Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit warning when variable is being expanded to function call #3517

Merged
merged 1 commit into from
Jun 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/eex/lib/eex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ defmodule EEx do

"""
defmacro function_from_string(kind, name, source, args \\ [], options \\ []) do
quote bind_quoted: binding do
quote bind_quoted: binding() do
info = Keyword.merge [file: __ENV__.file, line: __ENV__.line], options
args = Enum.map args, fn arg -> {arg, [line: info[:line]], nil} end
compiled = EEx.compile_string(source, info)
Expand Down Expand Up @@ -148,7 +148,7 @@ defmodule EEx do

"""
defmacro function_from_file(kind, name, file, args \\ [], options \\ []) do
quote bind_quoted: binding do
quote bind_quoted: binding() do
info = Keyword.merge options, [file: file, line: 1]
args = Enum.map args, fn arg -> {arg, [line: 1], nil} end
compiled = EEx.compile_file(file, info)
Expand Down
6 changes: 3 additions & 3 deletions lib/eex/test/eex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require EEx

defmodule EExTest.Compiled do
def before_compile do
fill_in_stacktrace
fill_in_stacktrace()
{__ENV__.line, hd(tl(System.stacktrace))}
end

Expand All @@ -19,13 +19,13 @@ defmodule EExTest.Compiled do
def file_sample(arg), do: private_file_sample(arg)

def after_compile do
fill_in_stacktrace
fill_in_stacktrace()
{__ENV__.line, hd(tl(System.stacktrace))}
end

@file "unknown"
def unknown do
fill_in_stacktrace
fill_in_stacktrace()
{__ENV__.line, hd(tl(System.stacktrace))}
end

Expand Down
4 changes: 2 additions & 2 deletions lib/elixir/lib/dict.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule Dict do
end

def take(dict, keys) do
Enum.reduce(keys, new, fn key, acc ->
Enum.reduce(keys, new(), fn key, acc ->
case fetch(dict, key) do
{:ok, value} -> put(acc, key, value)
:error -> acc
Expand Down Expand Up @@ -166,7 +166,7 @@ defmodule Dict do
end

def split(dict, keys) do
Enum.reduce(keys, {new, dict}, fn key, {inc, exc} = acc ->
Enum.reduce(keys, {new(), dict}, fn key, {inc, exc} = acc ->
case fetch(exc, key) do
{:ok, value} ->
{put(inc, key, value), delete(exc, key)}
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/exception.ex
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ defmodule Exception do
is retrieved from `Process.info/2`.
"""
def format_stacktrace(trace \\ nil) do
trace = trace || case Process.info(self, :current_stacktrace) do
trace = trace || case Process.info(self(), :current_stacktrace) do
{:current_stacktrace, t} -> Enum.drop(t, 3)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ defmodule File do
"""
@spec cd!(Path.t, (() -> res)) :: res | no_return when res: var
def cd!(path, function) do
old = cwd!
old = cwd!()
cd!(path)
try do
function.()
Expand Down
4 changes: 2 additions & 2 deletions lib/elixir/lib/inspect/algebra.ex
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ defmodule Inspect.Algebra do
Inserts a break between two docs. See `break/1` for more info.
"""
@spec glue(t, t) :: doc_cons
def glue(x, y), do: concat(x, concat(break, y))
def glue(x, y), do: concat(x, concat(break(), y))

@doc """
Inserts a break, passed as the second argument, between two docs,
Expand Down Expand Up @@ -420,7 +420,7 @@ defmodule Inspect.Algebra do
"""
@spec fold_doc([t], ((t, t) -> t)) :: t
def fold_doc(list, fun)
def fold_doc([], _), do: empty
def fold_doc([], _), do: empty()
def fold_doc([doc], _), do: doc
def fold_doc([d | ds], fun), do: fun.(d, fold_doc(ds, fun))

Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/io.ex
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ defmodule IO do
def getn(prompt, count \\ 1)

def getn(prompt, count) when is_integer(count) and count > 0 do
getn(group_leader, prompt, count)
getn(group_leader(), prompt, count)
end

def getn(device, prompt) when not is_integer(prompt) do
Expand Down
4 changes: 2 additions & 2 deletions lib/elixir/lib/io/ansi.ex
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ defmodule IO.ANSI do
[[[[[[], "Hello, "] | "\e[31m"] | "\e[1m"], "world!"] | "\e[0m"]

"""
def format(chardata, emit? \\ enabled?) when is_boolean(emit?) do
def format(chardata, emit? \\ enabled?()) when is_boolean(emit?) do
do_format(chardata, [], [], emit?, :maybe)
end

Expand All @@ -206,7 +206,7 @@ defmodule IO.ANSI do
[[[[[[] | "\e[1m"], 87], 111], 114], 100]

"""
def format_fragment(chardata, emit? \\ enabled?) when is_boolean(emit?) do
def format_fragment(chardata, emit? \\ enabled?()) when is_boolean(emit?) do
do_format(chardata, [], [], emit?, false)
end

Expand Down
14 changes: 7 additions & 7 deletions lib/elixir/lib/io/ansi/docs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ defmodule IO.ANSI.Docs do
"""
def print_heading(heading, options \\ []) do
IO.puts IO.ANSI.reset
options = Keyword.merge(default_options, options)
options = Keyword.merge(default_options(), options)
width = options[:width]
padding = div(width + String.length(heading), 2)
heading = heading |> String.pad_leading(padding) |> String.pad_trailing(width)
write(:doc_title, heading, options)
newline_after_block
newline_after_block()
end

@doc """
Expand All @@ -55,7 +55,7 @@ defmodule IO.ANSI.Docs do
defined in `default_options/1`.
"""
def print(doc, options \\ []) do
options = Keyword.merge(default_options, options)
options = Keyword.merge(default_options(), options)
doc
|> String.split(["\r\n", "\n"], trim: false)
|> Enum.map(&String.trim_trailing/1)
Expand Down Expand Up @@ -124,13 +124,13 @@ defmodule IO.ANSI.Docs do

defp write_h2(heading, options) do
write(:doc_headings, heading, options)
newline_after_block
newline_after_block()
end

defp write_h3(heading, indent, options) do
IO.write(indent)
write(:doc_headings, heading, options)
newline_after_block
newline_after_block()
end

## Lists
Expand Down Expand Up @@ -256,15 +256,15 @@ defmodule IO.ANSI.Docs do

defp write_code(code, indent, options) do
write(:doc_code, "#{indent}┃ #{Enum.join(Enum.reverse(code), "\n#{indent}┃ ")}", options)
newline_after_block
newline_after_block()
end

## Tables

defp process_table(lines, indent, options) do
{table, rest} = Enum.split_while(lines, &table_line?/1)
table_lines(table, options)
newline_after_block
newline_after_block()
process(rest, [], indent, options)
end

Expand Down
8 changes: 4 additions & 4 deletions lib/elixir/lib/kernel/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,22 @@ defmodule Kernel.CLI do
fun.(elem(res, 1))
catch
:exit, {:shutdown, int} when is_integer(int) ->
send parent, {self, {:shutdown, int}}
send parent, {self(), {:shutdown, int}}
exit({:shutdown, int})
:exit, reason
when reason == :normal
when reason == :shutdown
when tuple_size(reason) == 2 and elem(reason, 0) == :shutdown ->
send parent, {self, {:shutdown, 0}}
send parent, {self(), {:shutdown, 0}}
exit(reason)
kind, reason ->
stack = System.stacktrace
print_error(kind, reason, stack)
send parent, {self, {:shutdown, 1}}
send parent, {self(), {:shutdown, 1}}
exit(to_exit(kind, reason, stack))
else
_ ->
send parent, {self, res}
send parent, {self(), res}
end
end)

Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/kernel/error_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule Kernel.ErrorHandler do
parent = :erlang.get(:elixir_compiler_pid)
ref = :erlang.make_ref
send parent, {:waiting, kind, self(), ref, module, :elixir_module.compiler_modules()}
:erlang.garbage_collect(self)
:erlang.garbage_collect(self())
receive do
{^ref, :found} -> true
{^ref, :not_found} -> false
Expand Down
4 changes: 2 additions & 2 deletions lib/elixir/lib/path.ex
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ defmodule Path do
"""
@spec type(t) :: :absolute | :relative | :volumerelative
def type(name) when is_list(name) or is_binary(name) do
pathtype(name, major_os_type) |> elem(0)
pathtype(name, major_os_type()) |> elem(0)
end

@doc """
Expand Down Expand Up @@ -625,7 +625,7 @@ defmodule Path do
defp resolve_home(""), do: System.user_home!

defp resolve_home(rest) do
case {rest, major_os_type} do
case {rest, major_os_type()} do
{"\\" <> _, :win32} ->
System.user_home! <> rest
{"/" <> _, _} ->
Expand Down
10 changes: 5 additions & 5 deletions lib/elixir/lib/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ defmodule Protocol do
_ = unquote(block)

# Finalize expansion
unquote(after_defprotocol)
unquote(after_defprotocol())
end
end
end
Expand All @@ -446,7 +446,7 @@ defmodule Protocol do
Kernel.def impl_for(data) when :erlang.unquote(guard)(data) do
case impl_for?(unquote(target)) do
true -> unquote(target).__impl__(:target)
false -> any_impl_for
false -> any_impl_for()
end
end
end, builtin)
Expand All @@ -459,17 +459,17 @@ defmodule Protocol do

# Internal handler for Any
if @fallback_to_any do
Kernel.defp any_impl_for, do: __MODULE__.Any.__impl__(:target)
Kernel.defp any_impl_for(), do: __MODULE__.Any.__impl__(:target)
else
Kernel.defp any_impl_for, do: nil
Kernel.defp any_impl_for(), do: nil
end

# Internal handler for Structs
Kernel.defp struct_impl_for(struct) do
target = Module.concat(__MODULE__, struct)
case impl_for?(target) do
true -> target.__impl__(:target)
false -> any_impl_for
false -> any_impl_for()
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ defmodule Stream do

## Examples

iex> stream = Stream.each([1, 2, 3], fn(x) -> send self, x end)
iex> stream = Stream.each([1, 2, 3], fn(x) -> send self(), x end)
iex> Enum.to_list(stream)
iex> receive do: (x when is_integer(x) -> x)
1
Expand Down
26 changes: 13 additions & 13 deletions lib/elixir/lib/system.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ defmodule System do
|> strip
end

defp revision, do: get_revision
defp revision, do: get_revision()

# Get the date at compilation time.
defmacrop get_date do
Expand Down Expand Up @@ -145,7 +145,7 @@ defmodule System do
Returns Elixir's version as binary.
"""
@spec version() :: String.t
def version, do: get_version
def version, do: get_version()

@doc """
Elixir build information.
Expand All @@ -154,22 +154,22 @@ defmodule System do
"""
@spec build_info() :: map
def build_info do
%{build: build,
date: get_date,
revision: revision,
version: version,
%{build: build(),
date: get_date(),
revision: revision(),
version: version(),
}
end

# Returns a string of the build info
defp build do
{:ok, v} = Version.parse(version)
{:ok, v} = Version.parse(version())

cond do
([] == v.pre) or ("" == revision) ->
version
([] == v.pre) or ("" == revision()) ->
version()
true ->
"#{version} (#{revision})"
"#{version()} (#{revision()})"
end
end

Expand Down Expand Up @@ -222,7 +222,7 @@ defmodule System do
Returns the current working directory or raises `RuntimeError`.
"""
def cwd! do
cwd ||
cwd() ||
raise RuntimeError, message: "could not get a current working directory, the current location is not accessible"
end

Expand All @@ -242,7 +242,7 @@ defmodule System do
instead of returning `nil` if no user home is set.
"""
def user_home! do
user_home ||
user_home() ||
raise RuntimeError, message: "could not find the user home, please set the HOME environment variable"
end

Expand Down Expand Up @@ -275,7 +275,7 @@ defmodule System do
instead of returning `nil` if no temp dir is set.
"""
def tmp_dir! do
tmp_dir ||
tmp_dir() ||
raise RuntimeError, message: "could not get a writable temporary directory, " <>
"please set the TMPDIR environment variable"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/elixir/lib/task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ defmodule Task do
"""
@spec start_link(module, atom, [term]) :: {:ok, pid}
def start_link(mod, fun, args) do
Task.Supervised.start_link(get_info(self), {mod, fun, args})
Task.Supervised.start_link(get_info(self()), {mod, fun, args})
end

@doc """
Expand All @@ -189,7 +189,7 @@ defmodule Task do
"""
@spec start(module, atom, [term]) :: {:ok, pid}
def start(mod, fun, args) do
Task.Supervised.start(get_info(self), {mod, fun, args})
Task.Supervised.start(get_info(self()), {mod, fun, args})
end

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/task/supervised.ex
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ defmodule Task.Supervised do
'** When function == ~p~n' ++
'** arguments == ~p~n' ++
'** Reason for termination == ~n' ++
'** ~p~n', [self, get_from(info), fun, args, get_reason(log_reason)])
'** ~p~n', [self(), get_from(info), fun, args, get_reason(log_reason)])

exit(reason)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/task/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ defmodule Task.Supervisor do
"""
@spec start_child(Supervisor.supervisor, module, atom, [term]) :: {:ok, pid}
def start_child(supervisor, module, fun, args) do
Supervisor.start_child(supervisor, [get_info(self), {module, fun, args}])
Supervisor.start_child(supervisor, [get_info(self()), {module, fun, args}])
end

defp get_info(self) do
Expand Down
Loading