Commit Graph
78 Commits
Author SHA1 Message Date
Eric Meadows-Jönsson 1d7af251ad Only error for duplicate map keys in matches (#9748)
In matches we will error:

    %{a: :b, a: :c} = %{a: :b}

In normal expressions we will only warn:

    %{a: :b, a: :c}
2020-01-21 18:15:35 +01:00
Eksperimental 9d87fe434e Replace usage of "etc." (#9569) 2019-11-29 08:22:18 +01:00
José Valim 94b507841b Add struct keys to tracing on struct expansion 2019-09-01 09:52:18 -06:00
Eric Meadows-Jönsson 0f47a58bf8 Support struct patterns (#9306) 2019-08-22 13:28:05 -07:00
José Valim b08593b9d1 Add compiler tracing (#9247)
This feature allows IDEs and other tools wanting to
perform source code analysis to do so reliably without
a need to reimplement Elixir's compiler expansion and
without relying on Elixir's private APIs.

This commit also adds :parser_options to compiler
options, which allows developers to combine both options
to retrieve more accurate information, such as columns.
2019-08-02 13:35:12 +02:00
Eric Meadows-Jönsson 1956e95808 Remove dispatch tracking in LexicalTracker (#9228) 2019-07-18 13:48:02 +02:00
José Valim a369190f42 Improve undefined struct messages 2019-06-10 11:19:00 +02:00
José Valim 59fcce0b92 Unify error handling and compiler deadlock checking (#9009) 2019-05-02 16:27:13 +02:00
José Valim e809326d81 Allow Code.ensure_compiled/2 to not raise on deadlocks
This is important when you may want to check if a module
is available but if that module is running a similar check
on you, you don't want the compiler to fail.
2019-04-01 13:04:00 +02:00
Fernando Tapia Rico ae6666f0d6 Ensure the struct name matches the given module
This change fixes inconsistencies when building structs: if the
struct was built using the map syntax the `:__struct__` key
was overridden by the given module name; however, if the struct
was built using `struct/1,2` the `:__struct__` key was kept.

For example:

    defmodule X do
      defstruct [:x]
    end

    defmodule Y do
      defdelegate __struct__, to: X
      defdelegate __struct__(args), to: X
    end

    iex> %Y{}
    %Y{x: nil}

    iex> struct(Y)
    %X{x: nil}

Closes #8800
2019-03-31 09:52:58 +02:00
Fernando Tapia Rico a7019ac90a Use inspect/1 with values returned by __struct__/* (#8873)
__struct__/0,1 is not meant to return an AST. Using
Macro.to_string/1 might lead to incorrect error messages:

    defmodule MyStruct do
      def __struct__, do: {:ok, :one, :two}
      def __struct__(_), do: {:ok, :one, :two}
    end

    iex> %MyStruct{}
    ** (CompileError) iex:2: expected MyStruct.__struct__/1 to
       return a map with a :__struct__ key that holds the name
       of the struct (atom), got: ok
2019-03-08 23:24:45 +01:00
Fernando Tapia Rico 9cfd989f4b Use :elixir_aliases.inspect/1 with module aliases (#8869)
The `Module` variable in these cases is guaranteed to be a module
alias.
2019-03-08 22:49:55 +01:00
Fernando Tapia Rico b88cd49d8d Validate __struct__ key in map returned by __struct__/0,1 (#8864) 2019-03-07 12:12:30 +01:00
José Valim 774a9baa93 Resolve circular struct dependencies in typespecs (#8377)
Prior to this patch, if a module depends on the struct of
another module and that other module depends on the struct
of the first module inside typespecs, it would lead to a
compiler deadlock, which this deadlock would not happen
in "regular code".

This commit also adds a test to ensure @enforce_keys are
not enforced when expanding typespecs.

For now, we are using a compiler private API, but we should
provide a public version for it in a future commit.
2018-11-13 17:47:24 +01:00
Eksperimental 28522ccb89 Use "etc." and not "etc" (#8379)
Command used to detect these typos:
$ ag -s "\betc[^.]"
2018-11-10 14:04:49 +01:00
Fernando Tapia Rico d24ff660cd Avoid errors with more than one duplicated key (#8346)
Closes #8345
2018-10-26 17:44:09 +02:00
Glauber Campinho 3fcc9241db Optimizes multiple :maps put and merge operations (#8223)
Optimizes :maps.put/3 to a VM operation instead of a remote call, including nested calls to it.
It does the same for :maps.merge/2 with a simple map on the right side.

Closes #7353
2018-09-28 08:40:27 +02:00
Eksperimental cdd9dae8b4 "Fall back" the verb is 2 separate words (#8131) 2018-08-27 12:10:22 +02:00
Fernando Tapia Rico caf62d5355 Use ETS instead of ets in documentation (#8099) 2018-08-17 00:35:49 +02:00
Michał Muskała ffb931a5ac Fix all compiler warnings (#7992) 2018-07-27 16:42:24 +02:00
Michał Muskała 335cfdbcad Separate testing for unquotes from escaping 2018-07-25 00:10:02 +02:00
José Valim 34befaaa36 Allow to prune metadata while escaping (#7949)
We use this option in ExUnit as we are escaping
the code to eventually convert it to a string
representation and therefore the metadata is not
relevant.
2018-07-21 12:56:07 +02:00
José Valim 5fbc8676c2 Improve error messages for bad map key patterns 2018-06-25 16:56:57 +02:00
Derek Kraan 95acb1f751 Include caller information on struct expansion errors
Closes #7752
2018-06-21 18:48:55 +02:00
José Valim fc857d6ff1 Raise on invalid pin in maps, closes #7543 2018-04-10 20:49:53 +02:00
José Valim 179566d9f3 Simplify key check in map match 2018-02-10 21:13:52 +01:00
Michał Muskała c95a877d38 Separate tracking structs from compile-time dependencies
This is a first step to limiting recompilations in case a struct is used in a
module, the "parent module" of the struct changes, but struct definition itself
does not change.

Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2017-10-31 14:24:48 +01:00
Ivan Kozik 75150ec7eb Fix more typos and spelling errors (#6530) 2017-09-01 10:20:53 +02:00
José Valim 5fb5c5a4f4 Always use in_context definition for struct expansion, closes #6409 2017-07-31 06:39:26 +02:00
José Valim 1f87810f5b Do not remove structs syntax in Elixir pass 2017-05-20 20:50:54 +02:00
Michał Muskała 170019c869 Make sure System.stracktrace is first thing done in the handler (#6119)
If any of the functions catches an error, we'd get a wrong trace
2017-05-18 12:27:17 +02:00
Andrea Leopardi c6218a92d6 Warn when a :__struct__ key is used when building/updating structs (#6113)
Until now, "%x{__struct__: y}" would ignore the ":__struct__" part and only
use/match on "x", without warnings. With this commit, a warning is emitted in
this case and in the respective case when updating ("%SomeStruct{x | __struct__:
y}").
2017-05-15 20:56:02 +02:00
José Valim 5ab8c6e93a Remove warnings on OTP 20 2017-05-07 10:28:08 +02:00
José Valim 6d122fa352 Clarify docs 2017-03-15 16:04:36 +01:00
José Valim 3404a6fd13 Solve race conditions on struct dispatch 2017-03-15 15:46:52 +01:00
José Valim 2eb8490f9a Add prematch_vars 2017-02-23 10:43:09 +01:00
Andrea Leopardi c775ab6db2 Replace elixir_errors:compile_error/4 with form_error/4 in elixir_map 2017-02-20 13:24:24 +01:00
Aleksei Magusev 84b67b5b95 Rename elixir_exp module to elixir_expand 2017-02-19 21:57:50 +01:00
Aleksei Magusev a729847db6 Rename m/2 helper macro to key/2 in the main header file 2017-02-19 21:56:05 +01:00
José Valim 8e2ebf739b Split erl and ex passes in elixir_def 2017-02-19 13:01:13 +01:00
José Valim ff3fc7ef43 Unify local handling in elixir_def 2017-02-18 23:36:30 +01:00
José Valim ad7642b7d6 Perform map_key check on elixir_exp 2017-02-15 20:44:06 +01:00
José Valim ddffa75cfe Move maps/structs validation to elixir pass 2017-02-14 14:34:22 +01:00
Gal Tsubery a42990526e Fix translation of maps used as map keys (#5654)
Fixes [issue 5602](https://github.com/elixir-lang/elixir/issues/5602)
Erlang does not accept map_field_exact tag for map used as map keys
since it does not perform any matching on map keys.

For example this fails:
$ erl
Erlang/OTP 19 [erts-8.2] [source-a2c5a92] [64-bit] [smp:8:8]
[async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.2  (abort with ^G)
1> #{ #{1 => X} := 3 } = #{ #{1 => 2} => 3 }.
* 1: illegal map key in pattern
2017-01-15 01:56:28 +01:00
Michał Muskała e24b7c6659 Use Macro.to_string/1 when printing bad struct keys (#5403) 2016-11-03 12:25:18 +01:00
Michał Muskała 8277dcd776 Make sure bad remote call errors have file/line info (#5116)
Change how we mark the generated AST for suppressing dialyzer errors -
instead of [generated: true, location: 0], we provide proper line number.
This means, however, that on OTP 18, those nodes won't be recognized
as generated and warnings will be issued.
It was decided that proper error messages are more important than
avoiding bogus dialyzer warnings.
The old mark for generated code is left in places that made compiler
issue warnings on 18.

The bad remote call dialyzer warnings can be suppressed with the
@dialyzer :no_fail_call
module attribute.
2016-08-15 13:18:09 +01:00
Michał Muskała 270c983b13 Mark struct update syntax as generated (#5067)
With changes to OTP 19, dialyzer started emitting warnings for
the struct update syntax where variable could only be that struct.
For example:

    def foo(%Foo{} = struct), do: %Foo{struct | bar: :baz}
2016-07-27 11:26:45 +02:00
José Valim b98b4bd235 Ensure structs can be expanded in dynamic module names, closes #4894 2016-06-28 10:30:15 +01:00
Eric Entin 2d7017fcc7 Make sure struct expansion results in a remote dispatch (#4807) 2016-06-12 23:38:51 +02:00
José Valim c87a7dbf26 Add @enforce_keys to defstruct, defexception and friends 2016-05-26 13:26:58 +02:00