fix: remove default constructors and require explicit construct new() for all user classes
The compiler no longer auto-generates a default `new()` constructor for classes. All classes must now explicitly define `construct new() {}` to be instantiable. This change removes the `createDefaultConstructor` function from the compiler, eliminates the `return_this` primitive used by Object's default initializer, and adds explicit constructors to all test and example classes. Core metaclasses (Bool, Class, Null, Num, Object, Range, Sequence) now correctly reject `new()` calls with runtime errors.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
class Foo {
|
||||
construct new() {}
|
||||
method { "getter" }
|
||||
method() { "no args" }
|
||||
method(a) { a }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Foo {
|
||||
construct new() {}
|
||||
bar {}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Foo {
|
||||
construct new() {}
|
||||
thisHasAMethodNameThatIsExactly64CharactersLongWhichIsTheMaximum {
|
||||
return "result"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Foo {
|
||||
construct new() {}
|
||||
method000 { 1 }
|
||||
method001 { 1 }
|
||||
method002 { 1 }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Foo {
|
||||
construct new() {}
|
||||
method(a, b) { "method " + a + " " + b }
|
||||
[a, b] { "subscript " + a + " " + b }
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
class Foo {}
|
||||
class Foo {
|
||||
construct new() {}
|
||||
}
|
||||
|
||||
Foo.new().someUnknownMethod // expect runtime error: Foo does not implement 'someUnknownMethod'.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
class Foo {}
|
||||
class Foo {
|
||||
construct new() {}
|
||||
}
|
||||
|
||||
Foo.new().someUnknownMethod(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) // expect runtime error: Foo does not implement 'someUnknownMethod(_,_,_,_,_,_,_,_,_,_,_)'.
|
||||
@@ -1,3 +1,5 @@
|
||||
class Foo {}
|
||||
class Foo {
|
||||
construct new() {}
|
||||
}
|
||||
|
||||
Foo.new().someUnknownMethod(1, 2) // expect runtime error: Foo does not implement 'someUnknownMethod(_,_)'.
|
||||
@@ -1,3 +1,5 @@
|
||||
class Foo {}
|
||||
class Foo {
|
||||
construct new() {}
|
||||
}
|
||||
|
||||
Foo.new().someUnknownMethod(1) // expect runtime error: Foo does not implement 'someUnknownMethod(_)'.
|
||||
@@ -1,4 +1,6 @@
|
||||
class Foo {
|
||||
construct new() {}
|
||||
|
||||
+(other) { "infix + " + other }
|
||||
-(other) { "infix - " + other }
|
||||
*(other) { "infix * " + other }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Foo {
|
||||
construct new() {}
|
||||
bar { "on instance" }
|
||||
static bar { "on metaclass" }
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Foo {
|
||||
construct new() {}
|
||||
[a] { "1-subscript " + a }
|
||||
[a, b] { "2-subscript " + a + " " + b }
|
||||
[a, b, c] { "3-subscript " + a + " " + b + " " + c }
|
||||
|
||||
Reference in New Issue
Block a user