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

Fix pp_type({var, ..., _}) #401

Merged
merged 2 commits into from
Mar 25, 2022
Merged

Fix pp_type({var, ..., _}) #401

merged 2 commits into from
Mar 25, 2022

Conversation

erszcz
Copy link
Collaborator

@erszcz erszcz commented Mar 23, 2022

This adds a unit test and supersedes #393. Thanks @berbiche!

berbiche and others added 2 commits March 18, 2022 16:14
A 'var' type variable's name is not always a string as opposed to what the comment indicate.

This commit fixes the logic to handle both cases in `pp_type`.

This commit also removes the final period in one error message because error messages don't have a
final period.

Example test that fails before this commit:

``` erlang
-module(error).

-compile([nowarn_export_all, export_all]).

-record(some_record, { id :: integer() }).

-spec error([#some_record{}]) -> [integer()].
error(List) ->
    lists:map(fun(#some_record{id = Id}) -> Id end, List).
```

``` console
$ ./gradualizer error.erl
error.erl: escript: exception error: bad argument
  in function  io_lib:format/2
     called as io_lib:format("~sThe record pattern for record #~p~s is expected to have type ~s.~n",
                             [[],some_record,
                              [32,111,110,32,108,105,110,101,32,"9",32,97,116,
                               32,99,111,108,117,109,110,32,"19"],
                              ["\e[35m",'A',"\e[0m"]])
  in call from gradualizer_fmt:handle_type_error/2 (src/gradualizer_fmt.erl, line 534)
  in call from gradualizer_fmt:'-print_errors/2-lc$^0/1-0-'/2 (src/gradualizer_fmt.erl, line 520)
  in call from gradualizer_fmt:print_errors/2 (src/gradualizer_fmt.erl, line 520)
  in call from gradualizer:type_check_forms/3 (src/gradualizer.erl, line 209)
  in call from gradualizer:'-type_check_files/2-fun-1-'/4 (src/gradualizer.erl, line 159)
  in call from lists:foldl/3 (lists.erl, line 1267)
  in call from gradualizer_cli:main/1 (src/gradualizer_cli.erl, line 14)
```

Co-authored-by: Viktor Söderqvist <viktor@zuiderkwast.se>
Co-authored-by: Radek Szymczyszyn <radoslaw.szymczyszyn@erlang-solutions.com>
@erszcz erszcz requested a review from zuiderkwast March 23, 2022 15:59
@erszcz
Copy link
Collaborator Author

erszcz commented Mar 23, 2022

Hmm, GH actions don't kick in...

@erszcz erszcz closed this Mar 23, 2022
@zuiderkwast zuiderkwast reopened this Mar 25, 2022
@erszcz erszcz merged commit d6032d0 into josefs:master Mar 25, 2022
@erszcz erszcz deleted the fix/pp_type_var branch March 25, 2022 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants