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
An InternalError occures with the given message:
"internal interpreter error; t.value.b is undefined"
This Error occures if a Class inherits from a Primitive Wrapper class, such as Integer.
If now 'this' is passed to the super constructor of that Primitive type, unexpected behaviour in the
following code might happen, as the error-message shows.
This probably happens, because with 'this' a reference is passed to super, even if an actual value is expected.
This mismatch then is not detected/checked leading to further unexpected errors.
To Reproduce
Example code:
class FakeInteger: Integer {
public: constructor(): super(this) {}
}
var x = FakeInteger();
print(x); // InternalError occures!
What should happen instead / What I expected to happen instead:
IMO it should not be possible to inherit from primitive Types such as Integer or String. For that I would reccomend to
introduce/implement the existing keyword 'const', which currently exist, but has no effect/throws syntax errors.
E.g.:
const class X {} // OK
class Y: X() // Syntax Error
const x = 3; // OK
x = 4; // Syntax Error
I also reccomend to not allow passing this to the super constructor, since the super-type-content must be initialized first
before using this. This also applies to static functions.
E.g.:
class FakeInteger: Integer {
public: constructor(): super(foo()) {} // This seems to work fine!
public: static function foo(){ return 1; }
}
The text was updated successfully, but these errors were encountered:
Thanks for bringing this up. The behavior is clearly a bug, although I wonder how you even managed to stumble across such a weird corner case.
I agree that inheriting from built-in types is rarely useful. However, I'd like to avoid a distinction between primitive and class types at the language level. Declaring built-in types final (or const) would do the job indeed. However, that would introduce a whole new concept only for fixing a very unlikely edge case.
Disallowing the use of this in super calls also seems too restrictive. After all, in TScript, all member variables are fully constructed (to null) and only need initialization. Therefore, using this should be safe in most cases. The situation is different for super classes of built-in types though, and that's what caused this issue.
Since the error can only occur in very few corner cases where an instance is (or a few instances are) in the process of being constructed, I feel that this issue should not be solved with overly restrictive measures affecting inheritance as a whole. Instead, I added minimal checks catching the error, and a corresponding error message.
Description
An InternalError occures with the given message:
"internal interpreter error; t.value.b is undefined"
This Error occures if a Class inherits from a Primitive Wrapper class, such as Integer.
If now 'this' is passed to the super constructor of that Primitive type, unexpected behaviour in the
following code might happen, as the error-message shows.
This probably happens, because with 'this' a reference is passed to super, even if an actual value is expected.
This mismatch then is not detected/checked leading to further unexpected errors.
To Reproduce
Example code:
What should happen instead / What I expected to happen instead:
IMO it should not be possible to inherit from primitive Types such as Integer or String. For that I would reccomend to
introduce/implement the existing keyword 'const', which currently exist, but has no effect/throws syntax errors.
E.g.:
const class X {} // OK
class Y: X() // Syntax Error
const x = 3; // OK
x = 4; // Syntax Error
I also reccomend to not allow passing this to the super constructor, since the super-type-content must be initialized first
before using this. This also applies to static functions.
E.g.:
The text was updated successfully, but these errors were encountered: