You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The generated code for a where clause doesn't include the required outer variable, causing it to evaluate to nil:
localrecordmodrecordFoowhereself.kind==Fookind: selfendendlocalinstance: mod.Foo= {kind=mod.Foo}
-- Does not work:ifinstanceismod.Foothenprint("[1] It is a Foo!")
end-- Works:localFoo=mod.FooifinstanceisFoothenprint("[2] It is a Foo!")
end
Generated Lua code:
localmod= { Foo= {} }
localinstance= { kind=mod.Foo }
ifinstance.kind==Foothenprint("[1] It is a Foo!")
endlocalFoo=mod.Fooifinstance.kind==Foothenprint("[2] It is a Foo!")
end
The text was updated successfully, but these errors were encountered:
--- bar.tllocalfoo=require"foo"localinstance: foo.Foo= {kind=foo.Foo}
ifinstanceisfoo.Foothenprint("It is a Foo!")
end
Running bar.tl will cause attempt to index a nil value (global 'mod').
This is not related to the nesting, this is the behavior of where clauses, e.g. this fails too (it generates a reference to sentinel which is not defined):
--- bar.tllocalFoo=require"foo"localinstance: Foo= {kind=table.concat}
ifinstanceisFoothenprint("It is a Foo!")
end
I have never tried using where clauses this way (with variables outside of self), I am not sure if it should be allowed. Currently they just behave like "macros" i.e. they are copied as is.
Yeah, where clauses are non-hygienic macros. I think we do need to support variables outside self (since functions are variables too). For now, this is just a quirk we'll have to live with for simplicity's sake.
The generated code for a
where
clause doesn't include the required outer variable, causing it to evaluate to nil:Generated Lua code:
The text was updated successfully, but these errors were encountered: