1
0
forked from Mirror/wren

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

View File

@ -13,7 +13,7 @@ class Derived is Base {
}
}
(new Derived).foo(1)
Derived.new().foo(1)
// expect: Derived.bar(a)
// expect: Base.foo
// expect: Base.foo(a)

View File

@ -11,7 +11,7 @@ class Derived is Base {
}
}
(new Derived).bar
Derived.new().bar
// expect: Derived.bar
// expect: Base.foo

View File

@ -11,6 +11,6 @@ class Derived is Base {
}
}
(new Derived).foo
Derived.new().foo
// expect: Derived.foo
// expect: Base.foo

View File

@ -3,9 +3,9 @@ class Base {
}
class Derived is Base {
getClosure { new Fn { super.toString } }
getClosure { Fn.new { super.toString } }
toString { "Derived" }
}
var closure = (new Derived).getClosure
var closure = Derived.new().getClosure
IO.print(closure.call()) // expect: Base

View File

@ -11,6 +11,6 @@ class Derived is Base {
}
}
(new Derived).foo
Derived.new().foo
// expect: Derived.foo
// expect: Base.foo

View File

@ -13,6 +13,6 @@ class C is B {
}
}
(new C).foo
C.new().foo
// expect: C.foo
// expect: A.foo

View File

@ -4,4 +4,4 @@ class Derived is Base {
foo { super.doesNotExist(1) } // expect runtime error: Base does not implement 'doesNotExist(_)'.
}
(new Derived).foo
Derived.new().foo

View File

@ -1,6 +1,6 @@
class A {
callSuperToString {
return new Fn { super.toString }.call()
return Fn.new { super.toString }.call()
}
toString { "A.toString" }
@ -8,4 +8,4 @@ class A {
class B is A {}
IO.print((new B).callSuperToString) // expect: instance of B
IO.print(B.new().callSuperToString) // expect: instance of B

View File

@ -6,4 +6,4 @@ class A {
class B is A {}
IO.print((new B).callSuperToString) // expect: instance of B
IO.print(B.new().callSuperToString) // expect: instance of B

View File

@ -1,3 +1,3 @@
new Fn {
Fn.new {
super.foo // expect error
}