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:
@@ -19,7 +19,7 @@ class Foo {
|
||||
method(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) { a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p}
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
IO.print(foo.method) // expect: getter
|
||||
IO.print(foo.method()) // expect: no args
|
||||
IO.print(foo.method(1)) // expect: 1
|
||||
|
||||
@@ -2,4 +2,4 @@ class Foo {
|
||||
bar {}
|
||||
}
|
||||
|
||||
IO.print((new Foo).bar) // expect: null
|
||||
IO.print(Foo.new().bar) // expect: null
|
||||
|
||||
@@ -4,4 +4,4 @@ class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
IO.print((new Foo).thisHasAMethodNameThatIsExactly64CharactersLongWhichIsTheMaximum) // expect: result
|
||||
IO.print(Foo.new().thisHasAMethodNameThatIsExactly64CharactersLongWhichIsTheMaximum) // expect: result
|
||||
|
||||
@@ -1010,7 +1010,7 @@ class Foo {
|
||||
method999 { 1 }
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
var result = 0
|
||||
result = result + foo.method000
|
||||
result = result + foo.method001
|
||||
|
||||
@@ -3,7 +3,7 @@ class Foo {
|
||||
[a, b] { "subscript " + a + " " + b }
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
|
||||
// Allow newlines after commas and before ")".
|
||||
IO.print(foo.method("a",
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
class Foo {}
|
||||
|
||||
(new Foo).someUnknownMethod // expect runtime error: Foo does not implement 'someUnknownMethod'.
|
||||
Foo.new().someUnknownMethod // expect runtime error: Foo does not implement 'someUnknownMethod'.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
class Foo {}
|
||||
|
||||
(new Foo).someUnknownMethod(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) // expect runtime error: Foo does not implement 'someUnknownMethod(_,_,_,_,_,_,_,_,_,_,_)'.
|
||||
Foo.new().someUnknownMethod(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) // expect runtime error: Foo does not implement 'someUnknownMethod(_,_,_,_,_,_,_,_,_,_,_)'.
|
||||
@@ -1,3 +1,3 @@
|
||||
class Foo {}
|
||||
|
||||
(new Foo).someUnknownMethod(1, 2) // expect runtime error: Foo does not implement 'someUnknownMethod(_,_)'.
|
||||
Foo.new().someUnknownMethod(1, 2) // expect runtime error: Foo does not implement 'someUnknownMethod(_,_)'.
|
||||
@@ -1,3 +1,3 @@
|
||||
class Foo {}
|
||||
|
||||
(new Foo).someUnknownMethod(1) // expect runtime error: Foo does not implement 'someUnknownMethod(_)'.
|
||||
Foo.new().someUnknownMethod(1) // expect runtime error: Foo does not implement 'someUnknownMethod(_)'.
|
||||
@@ -18,7 +18,7 @@ class Foo {
|
||||
- { "prefix -" }
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
IO.print(foo + "a") // expect: infix + a
|
||||
IO.print(foo - "a") // expect: infix - a
|
||||
IO.print(foo * "a") // expect: infix * a
|
||||
|
||||
@@ -6,7 +6,7 @@ class Foo {
|
||||
static bar(arg) { "on metaclass " + arg }
|
||||
}
|
||||
|
||||
IO.print((new Foo).bar) // expect: on instance
|
||||
IO.print(Foo.new().bar) // expect: on instance
|
||||
IO.print(Foo.bar) // expect: on metaclass
|
||||
IO.print((new Foo).bar("arg")) // expect: on instance arg
|
||||
IO.print(Foo.new().bar("arg")) // expect: on instance arg
|
||||
IO.print(Foo.bar("arg")) // expect: on metaclass arg
|
||||
|
||||
@@ -7,7 +7,7 @@ class Foo {
|
||||
[a, b, c]=(value) { "3-subscript setter " + a + " " + b + " " + c + " = " + value }
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
IO.print(foo["a"]) // expect: 1-subscript a
|
||||
IO.print(foo["a", "b"]) // expect: 2-subscript a b
|
||||
IO.print(foo["a", "b", "c"]) // expect: 3-subscript a b c
|
||||
|
||||
Reference in New Issue
Block a user