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,8 +0,0 @@
|
||||
class Foo {
|
||||
toString { "Foo" }
|
||||
}
|
||||
|
||||
// Classes get an argument-less "new()" by default.
|
||||
var foo = Foo.new()
|
||||
IO.print(foo is Foo) // expect: true
|
||||
IO.print(foo.toString) // expect: Foo
|
||||
@@ -1,9 +0,0 @@
|
||||
class Foo {
|
||||
construct new() {
|
||||
IO.print("Foo.new()")
|
||||
}
|
||||
}
|
||||
|
||||
class Bar is Foo {}
|
||||
|
||||
Bar.new() // expect: Foo.new()
|
||||
@@ -1,6 +1,4 @@
|
||||
class Foo {
|
||||
construct real() {}
|
||||
}
|
||||
class Foo {}
|
||||
|
||||
// Classes do not get an argument-less "new()" if they define a constructor.
|
||||
// Classes do not get a constructor by default.
|
||||
var foo = Foo.new() // expect runtime error: Foo metaclass does not implement 'new()'.
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
// Tests that Object implements new(). The only way to call that is through a
|
||||
// super() call in a subclass, so this does that.
|
||||
|
||||
class Foo {
|
||||
construct new() {
|
||||
super() // Should not cause a no method error.
|
||||
IO.print("ok")
|
||||
}
|
||||
}
|
||||
|
||||
Foo.new() // expect: ok
|
||||
Reference in New Issue
Block a user