aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2019-04-09 06:37:55 +0200
committerBjörn Gustavsson <[email protected]>2019-04-09 06:46:31 +0200
commit23a497af427493b94739761e4d4974e12bc67579 (patch)
treed722974761354703cb9bb023d643bad44e0c7225 /lib/stdlib
parent45bb3d43fdba5b085fdd2f944277784ec18e60a8 (diff)
downloadotp-23a497af427493b94739761e4d4974e12bc67579.tar.gz
otp-23a497af427493b94739761e4d4974e12bc67579.tar.bz2
otp-23a497af427493b94739761e4d4974e12bc67579.zip
Issue an error for improper use of record_info/2 in a fun
`record_info/2` is a pseudo-function that requires literal arguments known at compile time. Therefore, the following usage is illegal: f() -> fun record_info/2. However, `erl_lint` did not issue a compilation error for this usage, and the compiler would crash in a later pass. https://bugs.erlang.org/browse/ERL-907
Diffstat (limited to 'lib/stdlib')
-rw-r--r--lib/stdlib/src/erl_lint.erl3
-rw-r--r--lib/stdlib/test/erl_lint_SUITE.erl6
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/stdlib/src/erl_lint.erl b/lib/stdlib/src/erl_lint.erl
index 00fd731e1d..e0c37ca030 100644
--- a/lib/stdlib/src/erl_lint.erl
+++ b/lib/stdlib/src/erl_lint.erl
@@ -2276,6 +2276,9 @@ expr({'fun',Line,Body}, Vt, St) ->
case Body of
{clauses,Cs} ->
fun_clauses(Cs, Vt, St);
+ {function,record_info,2} ->
+ %% It is illegal to call record_info/2 with unknown arguments.
+ {[],add_error(Line, illegal_record_info, St)};
{function,F,A} ->
%% BifClash - Fun expression
%% N.B. Only allows BIFs here as well, NO IMPORTS!!
diff --git a/lib/stdlib/test/erl_lint_SUITE.erl b/lib/stdlib/test/erl_lint_SUITE.erl
index 939cc1024c..fe98a3796d 100644
--- a/lib/stdlib/test/erl_lint_SUITE.erl
+++ b/lib/stdlib/test/erl_lint_SUITE.erl
@@ -3576,10 +3576,12 @@ basic_errors(Config) ->
{illegal_record_info,
<<"f1() -> record_info(42, record).
- f2() -> record_info(shoe_size, record).">>,
+ f2() -> record_info(shoe_size, record).
+ f3() -> fun record_info/2.">>,
[],
{errors,[{1,erl_lint,illegal_record_info},
- {2,erl_lint,illegal_record_info}],[]}},
+ {2,erl_lint,illegal_record_info},
+ {3,erl_lint,illegal_record_info}],[]}},
{illegal_expr,
<<"f() -> a:b.">>,