In particular, we reserve SyntaxError for synatx errors (doh)
and for macros that expects a given format at compilation time.
For example, defmodule/2 expects a :do keyword in the second
argument, not providing one is a syntax error.
In other places we impose similar restrictions bue the values
are allowed to be any expression as long as the final result
at compilation time is a given expression, for example:
when foo in @value
The right side of in can be anything as long it is a list or
a range at compilation time. Those kind of errors are now
CompileError.
This commit changes the -> clauses representation from:
{ :->, meta, list({ list(expr), expr }) }
To:
{ :->, meta, list({ list(expr), meta, expr }) }
Now clauses can store metadata, which allows us to provide
accurate reporting information.
Closes#1215
This provides a more robust way of checking from where
the original expressions are coming from compared to the
lexical check_clauses field we had in elixir_scope.
A direct consequence of this commit is that, the following
code:
defrecord Sample, [:hello] do
import List
end
Now raises a warning if the List import is not used,
where it didn't previously.
We have redefined the warning to say:
"trying to override previously defined function NAME/ARITY"
We have also relaxed the rules that causes the warning to
emitted. For example, if any kind of meta-programming or
unquoting is detected in the function definition, we skip
the warning altogether.
Closes#934.
This makes meta-programming in Elixir much easier and more friendly.
For example, here is how to convert a keywords argument into a bunch
of functions:
Enum.each [foo: 1, bar: 2, baz: 3], fn { k, v } ->
def unquote(k)(), do: unquote(v)
end
This means the second item in the AST is no longer an integer
(representing the line), but a keywords list. Code that relies
on the line information from AST or that manually generate AST
nodes need to be properly updated.