From cf3b2c808e8b7eccd39bedbb9c62432f7da5ca59 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Tue, 19 Dec 2017 15:30:17 +0100 Subject: stdlib: Add check of stacktrace variable to erl_eval Some of the functions of the erl_eval module do not call the Erlang code linter, so they need to explicitly check that the newly introduced stacktrace variable is not bound. --- lib/stdlib/src/erl_eval.erl | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'lib/stdlib/src/erl_eval.erl') diff --git a/lib/stdlib/src/erl_eval.erl b/lib/stdlib/src/erl_eval.erl index 489f65290a..4ee11383da 100644 --- a/lib/stdlib/src/erl_eval.erl +++ b/lib/stdlib/src/erl_eval.erl @@ -904,9 +904,9 @@ if_clauses([], _Bs, _Lf, _Ef, _RBs) -> %% try_clauses(Body, CaseClauses, CatchClauses, AfterBody, Bindings, %% LocalFuncHandler, ExtFuncHandler, RBs) -%% When/if variable bindings between the different parts of a -%% try-catch expression are introduced this will have to be rewritten. + try_clauses(B, Cases, Catches, AB, Bs, Lf, Ef, RBs) -> + check_stacktrace_vars(Catches, Bs), try exprs(B, Bs, Lf, Ef, none) of {value,V,Bs1} when Cases =:= [] -> ret_expr(V, Bs1, RBs); @@ -919,7 +919,6 @@ try_clauses(B, Cases, Catches, AB, Bs, Lf, Ef, RBs) -> end catch Class:Reason:Stacktrace when Catches =:= [] -> - %% Rethrow erlang:raise(Class, Reason, Stacktrace); Class:Reason:Stacktrace -> V = {Class,Reason,Stacktrace}, @@ -937,6 +936,23 @@ try_clauses(B, Cases, Catches, AB, Bs, Lf, Ef, RBs) -> end end. +check_stacktrace_vars([{clause,_,[{tuple,_,[_,_,STV]}],_,_}|Cs], Bs) -> + case STV of + {var,_,V} -> + case binding(V, Bs) of + {value, _} -> + erlang:raise(error, stacktrace_bound, ?STACKTRACE); + unbound -> + check_stacktrace_vars(Cs, Bs) + end; + _ -> + erlang:raise(error, + {illegal_stacktrace_variable,STV}, + ?STACKTRACE) + end; +check_stacktrace_vars([], _Bs) -> + ok. + %% case_clauses(Value, Clauses, Bindings, LocalFuncHandler, ExtFuncHandler, %% RBs) -- cgit v1.2.3