File 2786-epp-Fix-error-return-for-an-incorrect-preprocessor-i.patch of Package erlang
From f932c79a121a54fbf47c69e282b0933d5a694d9c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Wed, 26 Aug 2020 06:01:38 +0200
Subject: [PATCH] epp: Fix error return for an incorrect preprocessor -if
directive
Referencing an undefined preprocessor symbol in an `-if` directive
would return an invalid error term not recognized by
`epp:format_error/1`.
https://bugs.erlang.org/browse/ERL-1310
---
lib/stdlib/src/epp.erl | 2 ++
lib/stdlib/test/epp_SUITE.erl | 17 +++++++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/lib/stdlib/src/epp.erl b/lib/stdlib/src/epp.erl
index 181a524db6..92b43a89ce 100644
--- a/lib/stdlib/src/epp.erl
+++ b/lib/stdlib/src/epp.erl
@@ -1106,6 +1106,8 @@ scan_if([{'(',_}|_]=Toks, If, From, St) ->
Error = case Error0 of
{_,erl_parse,_} ->
{error,Error0};
+ {error,ErrL,What} ->
+ {error,{ErrL,epp,What}};
_ ->
{error,{loc(If),epp,Error0}}
end,
diff --git a/lib/stdlib/test/epp_SUITE.erl b/lib/stdlib/test/epp_SUITE.erl
index a90beed4f3..cb1638670c 100644
--- a/lib/stdlib/test/epp_SUITE.erl
+++ b/lib/stdlib/test/epp_SUITE.erl
@@ -1154,7 +1154,12 @@ test_if(Config) ->
{if_7c,
<<"-if(begin true end).\n" %Not a guard expression.
"-endif.\n">>,
- {errors,[{1,epp,{bad,'if'}}],[]}}
+ {errors,[{1,epp,{bad,'if'}}],[]}},
+
+ {if_8c,
+ <<"-if(?foo).\n" %Undefined symbol.
+ "-endif.\n">>,
+ {errors,[{1,epp,{undefined,foo,none}}],[]}}
],
[] = compile(Config, Cs),
@@ -1730,6 +1735,12 @@ eval_tests(Config, Fun, Tests) ->
Return = Fun(Config, P),
case message_compare(E, Return) of
true ->
+ case E of
+ {errors, Errors} ->
+ call_format_error(Errors);
+ _ ->
+ ok
+ end,
BadL;
false ->
io:format("~nTest ~p failed. Expected~n ~p~n"
@@ -1739,7 +1750,6 @@ eval_tests(Config, Fun, Tests) ->
end,
lists:foldl(F, [], Tests).
-
check_test(Config, Test) ->
Filename = "epp_test.erl",
PrivDir = proplists:get_value(priv_dir, Config),
@@ -1763,6 +1773,9 @@ compile_test(Config, Test0) ->
Opts = [export_all,nowarn_export_all,return,nowarn_unused_record,{outdir,PrivDir}],
case compile_file(File, Opts) of
{ok, Ws} -> warnings(File, Ws);
+ {errors, Errors}=Else ->
+ call_format_error(Errors),
+ Else;
Else -> Else
end.
--
2.26.2