Commit Graph
139 Commits
Author SHA1 Message Date
José Valim d634355ace Fix code comment 2022-11-29 08:18:13 +01:00
José Valim b24869687b Introduce mechanism to collect several errors in a module (#12275) 2022-11-28 15:40:30 +01:00
José Valim 386113af86 Include snippets in more syntax errors 2022-10-25 12:52:20 +02:00
felipe stival 85d86fd120 Change approach: never show error if line is empty (#11466) 2021-12-10 09:27:25 +01:00
Michał Łępicki 1eccae1232 Settle elixir_errors:parse_error/6 InputString as charlist (#11345) 2021-10-25 23:09:32 +02:00
José Valim 3b2f5057df Only consider StartColumn on first line 2021-10-25 16:33:16 +02:00
felipe stival ac80ddc123 Show code snippet on syntax and token missing errors (#11332)
Closes #11280.
2021-10-25 16:18:29 +02:00
José Valim 65ab34224f Include column in warnings emitted by compiler (#11339)
We also extend Mix.Tasks.Compiler.Diagnostic
to include {line, column} as possible position.
We also explicitly document the behaviour of
line=0, which is equivalent to unknown line.
Elixir was already setting the line to zero in
multiple occasions prior to this patch, so this
patch makes it official and we stop returning `nil`
for said cases.
2021-10-24 16:28:36 +02:00
José Valim a355450af8 Ensure waiting is tracked across typespecs
The Elixir compiler spawns a separate process per file.
When a file has to wait on another module, Elixir tracks
in the compiler that the file is waiting.

However, every time a module is defined, the Elixir compiler
spawns a separate process to compile to .beam, and this
process may expand structs in the typespec. Since this
new process is no longer the original file process, Elixir
was not able to track its waiting time.

This PR address this issue by passing the original file_pid
to the .beam compiler process. Note though that, if we
change typespecs to be compiled in the original file process,
this change is no longer required, but at the moment there are
no plans to make such change.

Closes #11036.
2021-06-05 19:21:12 +02:00
José Valim 3c45984d2c Assume Elixir is not started when accessing configs 2021-05-21 12:02:15 +02:00
José Valim dcd0b6d4d1 Use persistent term for tokenizer and bootstrap 2021-04-01 10:45:15 +02:00
Eric Meadows-Jönsson 436a279d89 Improve map unification (#10310) 2020-09-10 12:37:43 +02:00
Eksperimental 6944a67965 Revise use of Note and Notice verbs (#10264) 2020-08-14 07:59:34 +02:00
José Valim 2bc8541cae Add column information to SyntaxError and TokenMissingError 2020-08-12 20:14:31 +02:00
José Valim bb808fe683 Add line numbers to deprecated imports 2020-06-11 15:59:07 +02:00
José Valim 80c37a8dc9 Use reserved word where appropriate instead of token/keyword 2020-06-11 10:34:50 +02:00
Michał Łępicki 32b767a10f Fix multiple dialyzer errors in the Elixir application (#9965)
* fix dialyzer issue in ParallelChecker.verify/2

* fix dialyzer specs for elixir_errors:form_error and elixir_errors:form_warn

* fix dialyzer error caused by erl_anno:anno type being opaque in exception.ex

* fix spec for File.stream!

* fix spec for IO.getn/2 - dialyzer doesn't support overloaded specs

* add explicit spec for System.halt/0 to fix dialyzer error

* fix spec for Regex.recompile/1
2020-04-26 09:40:40 +02:00
José Valim 4894f3b6e0 Pass application tracer warnings to the compiler, closes #9861 2020-02-29 10:38:51 +01:00
Wojtek Mach c3752ac4df Add :indentation to sigil heredoc meta (#9725) 2020-01-14 20:45:24 +01:00
Eksperimental e8378b83da Replace usage of "e.g." (#9571) 2019-11-22 11:26:23 +01:00
José Valim 37d0931fd1 Improve error messages on keywords, closes #9467 2019-11-04 14:51:39 +01:00
José Valim cf881389cf Remove unecessary Erlang macro 2019-11-01 19:19:54 +01:00
Eric Meadows-Jönsson 1f974f869e Move unreachable function check from xref to group pass (#9168) 2019-06-28 10:25:49 +02:00
José Valim e80b55b21c Unify error handling and compiler deadlock checking (#9009) 2019-05-02 16:27:13 +02:00
José Valim 64eb6af13a Rely on IO.warn whenever possible 2019-01-18 14:59:20 +01:00
Michał Muskała 25aede7984 Fix all compiler warnings (#7992) 2018-07-27 16:42:24 +02:00
José Valim 216d6d6edf Add hints on mismatched do/end and others pairs
When you are working on large files and you add new code,
you may forget to add a `do` or an `end`. In those cases,
the error message usually points to the first `do` or the
last `end` in the file, which are usually far away from
the source of the error.

This pull request adds a simple heuristic based on the
indentation of the tokens, to try to provide hints of
where the source may be. Those hints are not deterministic
but they may be able to point users to the source of the
problem.

For example, in this case:

    defmodule MyApp do
      def one do
      # end

      def two do
      end
    end

we know that we now that `def two do` is happening on the
same indentation as `def one do`, which may mean that
`def one do` was not closed properly. We store this as a
hint in case the terminators do not match later.

Similarly, in the case below:

    defmodule MyApp do
      def one
      end

      def two do
      end
    end

The `end` on line 3 will end-up closing the defmodule `do`,
on line 1. Because their indentation do not match, it may
be that there is a missing `do`, where the `end` was supposed
to align.

Some basic testing show those heuristics work on the majority
of the cases, but we will only be sure when we have enough
feedback from the community.
2018-06-10 13:55:49 +02:00
José Valim b37e8a3637 Start v1.7 2017-12-23 19:40:30 +01:00
José Valim 6a5f96b5ac Properly guard bare_warn to catch errors early 2017-11-03 19:53:30 +01:00
José Valim f15d47f8e2 Pass line and file to IO.warn whenever possible 2017-11-03 18:49:07 +01:00
José Valim 47ca7004b6 Avoid conflicts with erl_anno in meta
We avoid using :file publicly as well as :location privately.
We do still use :file privately but that's supposed to mirror
the `-file` annotation in Erlang before function definitions.
2017-10-25 00:33:05 +02:00
José Valim a33cbcd32a Format errors_test.exs 2017-10-12 09:35:58 +02:00
Jake Becker d2f1cccace Add option :return_errors to ParallelCompiler (#6446) 2017-09-21 08:14:52 +02:00
José Valim e938d8a1d4 Add literal annotation for aliases 2017-08-28 23:59:45 +02:00
José Valim 1addd60e12 Make terminator binaries 2017-08-27 12:39:40 +02:00
Andrea Leopardi 7b111ac593 Merge integer tokens into the "int" token (#6499) 2017-08-23 11:55:12 +02:00
Alex Jiao ee389fff82 Add terminator info to sigil AST node metadata (#6305) 2017-07-08 01:05:37 +02:00
Jake Becker a5efcb8d4d Add --all-warnings option to Elixir compiler (#6224)
* Track Elixir build warnings in the manifest

* Add --all-warnings option to Elixir compiler

* Document "each_warning" option in ParallelCompiler

* Handle old manifest version :v6 when parsing manifest

* Track warnings during compile using a map in the Agent's state
2017-06-18 21:40:29 +01:00
Michał Muskała e20d10e0d8 Clean-up use of get_stracktrace in elixir_errors.erl (#6092)
It's possible get_stacktrace won't work outside of catch clauses in the future.

Reference: https://github.com/erlang/otp/pull/1449
2017-05-11 09:44:43 +02:00
José Valim ac5a0cf9ec Add elixir_erl_compiler 2017-02-23 13:15:26 +01:00
José Valim 9ba49d2347 Start refactoring on elixir_compiler 2017-02-23 13:15:26 +01:00
José Valim f667aed420 Remove duplication in format_errors 2017-02-10 20:55:53 +01:00
José Valim 6bb8f59b42 Improve compiler message on unexpected end of line, closes #5137 2016-11-20 11:01:30 +01:00
José Valim 3b08987dfd Ensure we consistently wrap variables in quotes 2016-10-22 22:25:18 +02:00
Aleksei Magusev 054206b03b Improve warning output (#4631) 2016-05-16 00:10:51 +02:00
José Valim e018c773b0 Unify warning calls 2016-05-15 20:34:29 +02:00
eksperimental 685e87bdf0 Formmating: Add white space around vertical bar (#4507) 2016-04-25 00:55:49 +02:00
eksperimental ba111fb9b3 Formatting: add white space after comma (#4491)
Standardizes the use of comma leaving a white space after it whenever applicable.

Note: It does not enforce this in quantifiers in regular expressions such as in: `x{1,3}`
2016-04-19 01:23:50 +02:00
Andrea Leopardi a00fe5a017 Handle chars literals in the parser for better syntax errors
Before this commit, we handled char literals (like `?a`) in the
tokenizer, turning a literal like `?a` into the token `{:number, _,
97}` (thus indistinguishable from the literal `97` at the parsing
stage). This led to error messages with the integer for the character
instead of the character literal, e.g.:

    iex> :ok ?a
    ** (SyntaxError) iex:11: syntax error before: 97

With this commit, we now turn `?a` into the token `{:char, _,
97}` (which is the same token used by Erlang for Erlang char literals
like `$a`); since it's the same token as in Erlang, the parser will now
output the char literal as an Erlang char (`?a` would be printed as
`$a`). We hijack the error message in elixir_errors.erl to end up with
the correct message:

    iex> :ok ?a
    ** (SyntaxError) iex:11: syntax error before: ?a
2016-04-04 21:29:15 +02:00
José Valim c027854cd3 Format beam validator errors properly, closes #4263 2016-02-06 17:23:18 +01:00