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:
Bob Nystrom
2015-09-01 15:16:04 +00:00
parent 4665ec1913
commit ef93496fd4
86 changed files with 248 additions and 133 deletions
@@ -1,4 +1,6 @@
class Foo {
construct new() {}
getter {
IO.print("getter")
}
@@ -13,6 +15,8 @@ class Foo {
}
class Bar is Foo {
construct new() {}
test {
getter // expect: getter
setter = "value" // expect: setter
@@ -1,4 +1,6 @@
class Foo {
construct new() {}
getter {
IO.print("getter")
}
@@ -1,4 +1,6 @@
class Foo {
construct new() {}
bar { "getter" }
test {
@@ -1,4 +1,6 @@
class Foo {
construct new() {}
bar=(value) {
IO.print("setter")
return value
@@ -1,4 +1,6 @@
class Outer {
construct new() {}
getter {
IO.print("outer getter")
}
@@ -17,6 +19,8 @@ class Outer {
method("arg") // expect: outer method
class Inner {
construct new() {}
getter {
IO.print("inner getter")
}