Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inheriting from nil fails too late #246

Open
fendrin opened this issue Mar 3, 2016 · 4 comments
Open

Inheriting from nil fails too late #246

fendrin opened this issue Mar 3, 2016 · 4 comments

Comments

@fendrin
Copy link

fendrin commented Mar 3, 2016

Parent = nil 

class Some extends Parent
...

This fails when the constructor of "Some" is called.
The error message

attempt to index local '_parent_0' (a nil value)

isn't that helpful before you look into the implementation details of class.

I suggest to let the code that defines the class check for nil parent and write a more useful error message.

@Idyllei
Copy link

Idyllei commented Mar 6, 2016

👍 After delving into some of Perl 6 code, I very strongly agree with @fendrin that this fails too late. I suggest that the translator fail as soon as possible once it encounters a case of inheriting from nil. (Perhaps, if the 'compiler' failing is not desirable, the Lua code that creates the constructor might error if it detects that it will inherit from nil before it can be called.)

@RyanSquared
Copy link
Contributor

With the rest of MoonScript, the only required external dependency when compiling .moon files is MoonScript. Inherited classes must be checked runtime, if at all.

@leafo
Copy link
Owner

leafo commented Sep 26, 2016

There are currently no runtime checks that throw errors in any moonscript generated code. Should I add dependency on assert or error built in functions? Another option, maybe instead of naming the variable _parent_0 it could be called Some_parent (Some being the name of the class). You would most likely be able to immediately tell what the problem is from the attempt to index nil error at that point

@TangentFoxy
Copy link

I vote for naming the variable after the class name, since you don't currently depend on assert/error anywhere else, and it would make generated code easier to read in addition to making the error easier to find.

(Is there anywhere else the generic _something_# naming of variables can come up with a hard-to-find error? I can't think of any off the top of my head, but if there is, it might be worth looking into as well.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants