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

Poor error message when assigning to a property of self at the global scope #132

Open
JoeStrout opened this issue Feb 13, 2024 · 0 comments

Comments

@JoeStrout
Copy link
Owner

JoeStrout commented Feb 13, 2024

I find it's surprisingly easy, when coding along and concentrating on other things, to create a class and then try to add a method this way:

self.foo = function
    // do some stuff
end function

And when you do this, you get a poor error message: "Runtime Error: can't set indexed element of null". What's worse, if this occurs in the main file, the stackTrace is empty — and if it occurs in an import module, it will claim the error is on the import line!

Curiously, trying to assign to super.foo produces a better error ("Undefined Identifier: 'super' is unknown in this context").

So:

  1. Catch trying to use self. when self is undefined, and print a better error message. Ideal might be something like "self undefined; not in object context"
  2. Ensure that the line number is correctly reported, both in the main file and in an import module.
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

1 participant