diff options
author | Björn Gustavsson <bjorn@erlang.org> | 2022-11-17 06:23:43 +0100 |
---|---|---|
committer | Björn Gustavsson <bjorn@erlang.org> | 2022-11-22 12:50:05 +0100 |
commit | 14d479d583872e62e96713b15021cb656ec488be (patch) | |
tree | 521d1ef38066c3892c09681b7110eaff8d1ecc10 /lib/stdlib/test | |
parent | 0863bd30aabd035c83158c78046c5ffda16127e1 (diff) | |
download | erlang-14d479d583872e62e96713b15021cb656ec488be.tar.gz |
Don't allow local calls from record init in guards
Calling functions in guards is forbidden, but the compiler would
fail to reject a function call from a default record initializer
used in a guard. For example:
-record(test, {a = mk_a()}).
mk_a() -> 1.
test_rec(Rec) when Rec =:= #test{} ->
true.
Before this commit, the compiler would fail to reject the illegal call
to `mk_a/0`, and crash in a later pass. The compiler will now give the
following error message:
t.erl:7:36: call to local/imported function mk_a/0 is illegal in guard
% 7| test_rec(Rec) when Rec =:= #test{} ->
% | ^
Closes #6465
Closes #6466
Diffstat (limited to 'lib/stdlib/test')
-rw-r--r-- | lib/stdlib/test/erl_lint_SUITE.erl | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/stdlib/test/erl_lint_SUITE.erl b/lib/stdlib/test/erl_lint_SUITE.erl index c54efc20c6..c8c07de212 100644 --- a/lib/stdlib/test/erl_lint_SUITE.erl +++ b/lib/stdlib/test/erl_lint_SUITE.erl @@ -1645,8 +1645,20 @@ guard(Config) when is_list(Config) -> [], {error, [{{2,26},erl_lint,{obsolete_guard_overridden,port}}], - [{{2,26},erl_lint,{obsolete_guard,{port,1}}}]}} - ], + [{{2,26},erl_lint,{obsolete_guard,{port,1}}}]}}, + {guard11, + <<"-record(bar, {a = mk_a()}). + mk_a() -> 1. + + test_rec(Rec) when Rec =:= #bar{} -> true. + map_pattern(#{#bar{} := _}) -> ok. + ">>, + [], + {errors, + [{{4,43},erl_lint,{illegal_guard_local_call,{mk_a,0}}}, + {{5,30},erl_lint,{illegal_guard_local_call,{mk_a,0}}}], + []}} + ], [] = run(Config, Ts1), ok. |