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:
@ -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)
|
||||
|
||||
@ -11,7 +11,7 @@ class Derived is Base {
|
||||
}
|
||||
}
|
||||
|
||||
(new Derived).bar
|
||||
Derived.new().bar
|
||||
// expect: Derived.bar
|
||||
// expect: Base.foo
|
||||
|
||||
|
||||
@ -11,6 +11,6 @@ class Derived is Base {
|
||||
}
|
||||
}
|
||||
|
||||
(new Derived).foo
|
||||
Derived.new().foo
|
||||
// expect: Derived.foo
|
||||
// expect: Base.foo
|
||||
|
||||
@ -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
|
||||
|
||||
@ -11,6 +11,6 @@ class Derived is Base {
|
||||
}
|
||||
}
|
||||
|
||||
(new Derived).foo
|
||||
Derived.new().foo
|
||||
// expect: Derived.foo
|
||||
// expect: Base.foo
|
||||
|
||||
@ -13,6 +13,6 @@ class C is B {
|
||||
}
|
||||
}
|
||||
|
||||
(new C).foo
|
||||
C.new().foo
|
||||
// expect: C.foo
|
||||
// expect: A.foo
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
new Fn {
|
||||
Fn.new {
|
||||
super.foo // expect error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user