Skip to content

Missing arity check for BIFs #50

Closed
eriksoe opened this Issue Feb 13, 2011 · 3 comments

2 participants

@eriksoe
eriksoe commented Feb 13, 2011

To reproduce:

(fun erlang:integer_to_list/1)(1,0).

Expected behaviour:

** exception error: integer_to_list/1 called with two arguments

Observed behaviour:

Expression evaluates to "1".

@krestenkrab
Trifork member

If I compile

-module(foo).
-export([main/0]).
main() ->
  (fun erlang:integer_to_list/1)(1,0).

And try to run foo:main(), then I get badfun.

> catch(foo:main()).
{'EXIT',{badfun,[{foo,main,[#Fun<erlang:integer_to_list/1>]},
             {erlang,apply,4},
             {error_handler,undefined_function,3},
             {erlang,apply,4},
             {shell,apply_fun,3},
             {erl_eval,do_apply,5},
             {erl_eval,expr,5},
             {shell,exprs,7},
             {shell,eval_exprs,7},
             {shell,eval_loop,3},
             {erlang,apply,4}]}}

However, in BEAM I get

> catch(foo:main()).
{'EXIT',{{badarity,{#Fun<erlang.integer_to_list.1>,[1,0]}},
     [{foo,main,0},
      {erl_eval,do_apply,5},
      {erl_eval,expr,5},
      {shell,exprs,7},
      {shell,eval_exprs,7},
      {shell,eval_loop,3}]}}

So, it's close but no cigar ... we need to throw {badarity,{Fun,Args}} rather than badfun.

@krestenkrab
Trifork member

Commit 2a0da3f improves this

@eriksoe
eriksoe commented Feb 14, 2011

The behaviour I described was in the shell... so probably an apply() issue.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.