Make constructors just methods.

* Eliminate "new" reserved word.
* Allow "this" before a method definition to define a constructor.
* Only create a default constructor for classes that don't define one.
This commit is contained in:
Bob Nystrom
2015-07-10 09:18:22 -07:00
parent 0ddaa2517c
commit 5fb6186d7d
221 changed files with 864 additions and 654 deletions
+4 -4
View File
@@ -1,5 +1,5 @@
class A {
new(arg) {
this new(arg) {
IO.print("new A ", arg)
_field = arg
}
@@ -8,7 +8,7 @@ class A {
}
class B is A {
new(arg1, arg2) {
this new(arg1, arg2) {
super(arg2)
IO.print("new B ", arg1)
_field = arg1
@@ -18,7 +18,7 @@ class B is A {
}
class C is B {
new {
this new() {
super("one", "two")
IO.print("new C")
_field = "c"
@@ -27,7 +27,7 @@ class C is B {
cField { _field }
}
var c = new C
var c = C.new()
// expect: new A two
// expect: new B one
// expect: new C