[erlang-bugs] Compiler bug in sys_core_fold.erl

Bjorn Gustavsson <>
Fri Oct 10 15:29:49 CEST 2008

2008/10/8 Robert Virding <>

> I am running R12B-4 and have generated code with Lisp Flavoured Erlang.
> There is a bug in eval_element/3 which is called from fold_call/4 which
> tries to safely evaluate calls at compile time. Eval_element tries to
> evaluate calls to element/2. It also tries to check if the call is
> guaranteed to fail in which case it replaces the original call with a call
> to erlang:error(badarg). It is this check which is causing the bug as it is
> so tuned to code generated by the vanilla erlang compiler that it does not
> accept a nested call in the element. This is the bug.
> I would also argue that such a substitution has very little noticeable
> effect as any evaluation of the arguments to element/2 have been broken out
> and will already be evaluated before the code ever reaches the erlang:error
> call. It, in fact, saves very little.

The optimization in itself may not be worthwhile (because the code being
optimized is probably wrong), but there will also be a warning about a call
to element/2 that will always fail. The warning could be useful.

I have updated eval_element/2 to be more careful.

Björn Gustavsson, Erlang/OTP, Ericsson AB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20081010/954c0e0f/attachment.html>

More information about the erlang-bugs mailing list