Log In  

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

input:
offending code on line 37:

foreach(collection, missing_function)

output:

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

vs.

input:
offending code on line 37:

missing_function(collection)

output:

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 2024-03-28 11:17:35 | 0.006s | Q:12