-
Notifications
You must be signed in to change notification settings - Fork 8
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
In-Game: Throw an exception when calling a constructor function without the "new" keyword #7690
Comments
Feature added in 2024.11 - an error will be thrown if a constructor is called normally - they MUST be called with |
new
… without the "new" keyword YoYoGames/GameMaker-Bugs#7690
For clarity, can we have some answer as to why constructor exists then? New and constructor seem to both perform the same task: indicate to the engine that this code produces structs. The JS we're seemingly emulating uses new but doesn't use constructor. Thus, while new never worked on non-constructor calls, constructors could be called without new. Weird, but a quirk of two keywords. As with my post on #3055, with this change, we can now say, without exception, one of them is superfluous. If we've decided new, arguably the less important of the two, is now vital then we shouldn't need to declare constructors anymore. If we admit that constructor is important, then new is completely unneccessary as the identity of the constructor is to BE a constructor. Enforcing the use of new only ensures this is true and adds a language keyword that actually does nothing but throw runtime errors when omitted. Thus one can easily argue that removing new also solves this problem as calling a constructor, which has been declared as a constructor, should be sufficient to indicate to the engine it's purpose and also close the aforementioned since constructors would be legal to call with method_call and return the expected results. In short, the fix here is patching a hole that only exists because the implementation uses two keywords and changing that both breaks prior functionality and makes one keyword pointless. |
You are absolutely wrong. The |
Perhaps, except the fix here requires the use of new with a function explicitly flagged as a constructor. We have drawn an explicit link from a new declaration to a constructor declaration, if the two must be used together and can not be used without one another, we have one keyword too many. In this condition the nature of the call can be inferred from constructor or new, there is no other legal pairing. After all, the runtime error being added proves the interpreter can recognize this. |
Fix verified in Beta IDE v2024.1100.0.626 Beta Runtime v2024.1100.0.652 |
Is your feature request related to a problem?
In YYC and GMRT, the following code will construct an instance of
Bee
instead ofCas
:Describe the solution you'd like
A runtime error when calling a constructor function without
new
.Bee()
should be a runtime error like "cannot call a constructor without the 'new' keyword".Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: