[erlang-bugs] Escript and fun local_func/arity runtime error

Scott Lystig Fritchie <>
Fri Oct 19 22:57:44 CEST 2012

Hi, all.  A colleague noticed this less-than-helpful runtime error when

* escript
* "fun local_func/1" syntax

The error message:

% /usr/local/erlang/R15B02.64bit/bin/escript ~/foo
Starting main....
escript: exception error: undefined function erl_eval:bar/0

See the example script below.  If your script doesn't have any initial
output (as the example does), then the error message could lead the
unsuspecting soul to believe that there's a compile-time error.  Well,
except that escripts aren't really compiled by default, but ... believe
that there's a syntax error detected prior to executing main().  But
main() really is executing.

I don't see fun syntax difference documented in the
http://www.erlang.org/doc/man/escript.html reference.

Yes, the problem disappears if "-mode(compile)." is added to the script.


--- snip --- snip --- snip --- snip --- snip --- snip --- 

#!/usr/bin/env escript
%%! -args_file ./data/ssl_distribution.args_file
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
%% -------------------------------------------------------------------

main( _) ->
    io:format("Starting main....\n"),
    X = fun() -> foo() end,
    Y = fun bar/0,

foo() ->
    io:format("Hello, foo!\n").

bar() ->
    io:format("Hello, bar!\n").

More information about the erlang-bugs mailing list