Log In  

If a nonexistent function is called in a foreach loop, the runtime error thrown returns nothing useful.

offending code on line 37:

foreach(collection, missing_function)


line 0: attempt to call local 'f' (a nil value)


offending code on line 37:



line 37: attempt to call global 'missing_function' (a nil value)
P#12291 2015-08-04 18:21 ( Edited 2015-08-05 03:10)

foreach is likely implemented in lua rather than C as something like

function foreach(c,f) for i in all(c) do f(i) end

so when that errors it doesn't know the name of your variable since it's just argument f to that function.

I don't think this is a bug, but it could be more helpful.
Showing a stacktrace on error would likely help or throwing an error in foreach if the function is nil or not a function.

P#12297 2015-08-04 23:10 ( Edited 2015-08-05 03:10)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2022-11-30 04:23:17 | 0.004s | Q:8