Missing arity check for BIFs #50

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

Comments

Projects
None yet
2 participants
@eriksoe
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@krestenkrab

krestenkrab Feb 14, 2011

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.

Member

krestenkrab commented Feb 14, 2011

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

This comment has been minimized.

Show comment
Hide comment
@krestenkrab

krestenkrab Feb 14, 2011

Member

Commit 2a0da3f improves this

Member

krestenkrab commented Feb 14, 2011

Commit 2a0da3f improves this

@eriksoe

This comment has been minimized.

Show comment
Hide comment
@eriksoe

eriksoe Feb 14, 2011

Contributor

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

Contributor

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