feat: replace new keyword with this constructor syntax and ClassName.new() calls across core library and docs
Replace all uses of the `new` reserved word with explicit `this new()` constructor definitions and `ClassName.new()` instantiation calls in builtin/core.wren. Update all documentation files (classes.markdown, fiber.markdown, fn.markdown, sequence.markdown, error-handling.markdown, expressions.markdown, fibers.markdown, functions.markdown) to reflect the new constructor syntax, removing `new` keyword examples and replacing them with `ClassName.new()` patterns and `this new()` definitions.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
new Fn {
|
||||
Fn.new {
|
||||
var a = "before"
|
||||
IO.print(a) // expect: before
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var f
|
||||
for (i in [1, 2, 3]) {
|
||||
var j = 4
|
||||
f = new Fn { IO.print(i + j) }
|
||||
f = Fn.new { IO.print(i + j) }
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var f
|
||||
while (true) {
|
||||
var i = "i"
|
||||
f = new Fn { IO.print(i) }
|
||||
f = Fn.new { IO.print(i) }
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var done = false
|
||||
while (!done) {
|
||||
new Fn {
|
||||
Fn.new {
|
||||
break // expect error
|
||||
}
|
||||
done = true
|
||||
|
||||
@@ -12,4 +12,4 @@ class foo {
|
||||
}
|
||||
|
||||
foo.callFoo // expect: static foo method
|
||||
(new foo).callFoo // expect: instance foo method
|
||||
foo.new().callFoo // expect: instance foo method
|
||||
|
||||
@@ -11,4 +11,4 @@ class Foo {
|
||||
}
|
||||
|
||||
Foo.sayName // expect: Foo!
|
||||
(new Foo).sayName // expect: Foo!
|
||||
Foo.new().sayName // expect: Foo!
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Foo {}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
IO.print(foo is Foo) // expect: true
|
||||
|
||||
// TODO: Test precedence and grammar of what follows "new".
|
||||
|
||||
@@ -3,13 +3,13 @@ var g = null
|
||||
|
||||
{
|
||||
var local = "local"
|
||||
f = new Fn {
|
||||
f = Fn.new {
|
||||
IO.print(local)
|
||||
local = "after f"
|
||||
IO.print(local)
|
||||
}
|
||||
|
||||
g = new Fn {
|
||||
g = Fn.new {
|
||||
IO.print(local)
|
||||
local = "after g"
|
||||
IO.print(local)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var f = null
|
||||
|
||||
new Fn {|param|
|
||||
f = new Fn {
|
||||
Fn.new {|param|
|
||||
f = Fn.new {
|
||||
IO.print(param)
|
||||
}
|
||||
}.call("param")
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
// would crash because it walked to the end of the upvalue list (correct), but
|
||||
// then didn't handle not finding the variable.
|
||||
|
||||
new Fn {
|
||||
Fn.new {
|
||||
var a = "a"
|
||||
var b = "b"
|
||||
new Fn {
|
||||
Fn.new {
|
||||
IO.print(b) // expect: b
|
||||
IO.print(a) // expect: a
|
||||
}.call()
|
||||
|
||||
@@ -2,11 +2,11 @@ var F = null
|
||||
|
||||
class Foo {
|
||||
method(param) {
|
||||
F = new Fn {
|
||||
F = Fn.new {
|
||||
IO.print(param)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(new Foo).method("param")
|
||||
Foo.new().method("param")
|
||||
F.call() // expect: param
|
||||
|
||||
@@ -2,7 +2,7 @@ var f = null
|
||||
|
||||
{
|
||||
var local = "local"
|
||||
f = new Fn {
|
||||
f = Fn.new {
|
||||
IO.print(local)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// TODO: Is this right? Shouldn't it resolve to this.local?
|
||||
var foo = null
|
||||
|
||||
{
|
||||
@@ -8,7 +9,7 @@ var foo = null
|
||||
}
|
||||
}
|
||||
|
||||
foo = new Foo
|
||||
foo = Foo.new()
|
||||
}
|
||||
|
||||
foo.method // expect: local
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
var f = null
|
||||
|
||||
new Fn {
|
||||
Fn.new {
|
||||
var a = "a"
|
||||
new Fn {
|
||||
Fn.new {
|
||||
var b = "b"
|
||||
new Fn {
|
||||
Fn.new {
|
||||
var c = "c"
|
||||
f = new Fn {
|
||||
f = Fn.new {
|
||||
IO.print(a)
|
||||
IO.print(b)
|
||||
IO.print(c)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
var local = "local"
|
||||
new Fn {
|
||||
Fn.new {
|
||||
IO.print(local) // expect: local
|
||||
}.call()
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// TODO: Is this right? Shouldn't it resolve to this.local?
|
||||
{
|
||||
var local = "local"
|
||||
class Foo {
|
||||
@@ -6,5 +7,5 @@
|
||||
}
|
||||
}
|
||||
|
||||
(new Foo).method // expect: local
|
||||
Foo.new().method // expect: local
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ var f = null
|
||||
|
||||
{
|
||||
var a = "a"
|
||||
f = new Fn {
|
||||
f = Fn.new {
|
||||
IO.print(a)
|
||||
IO.print(a)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
{
|
||||
var a = "a"
|
||||
f = new Fn { IO.print(a) }
|
||||
f = Fn.new { IO.print(a) }
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
var foo = "closure"
|
||||
new Fn {
|
||||
Fn.new {
|
||||
{
|
||||
IO.print(foo) // expect: closure
|
||||
var foo = "shadow"
|
||||
|
||||
@@ -15,7 +15,7 @@ IO.print(true || false ? 1 : 2) // expect: 1
|
||||
IO.print(!false ? 1 : 2) // expect: 1
|
||||
IO.print(~0 ? 1 : 2) // expect: 1
|
||||
IO.print(3 is Num ? 1 : 2) // expect: 1
|
||||
IO.print(new Foo ? 1 : 2) // expect: 1
|
||||
IO.print(Foo.new() ? 1 : 2) // expect: 1
|
||||
|
||||
var a = 0
|
||||
IO.print(a = 3 ? 1 : 2) // expect: 1
|
||||
@@ -32,7 +32,7 @@ IO.print(true ? 1 || false : 2) // expect: 1
|
||||
IO.print(true ? !true : 2) // expect: false
|
||||
IO.print(true ? ~0 : 2) // expect: 4294967295
|
||||
IO.print(true ? 3 is Bool : 2) // expect: false
|
||||
IO.print(true ? new Foo : 2) // expect: instance of Foo
|
||||
IO.print(true ? Foo.new() : 2) // expect: instance of Foo
|
||||
|
||||
IO.print(true ? a = 5 : 2) // expect: 5
|
||||
IO.print(a) // expect: 5
|
||||
@@ -48,7 +48,7 @@ IO.print(false ? 1 : 2 || false) // expect: 2
|
||||
IO.print(false ? 1 : !false) // expect: true
|
||||
IO.print(false ? 1 : ~0) // expect: 4294967295
|
||||
IO.print(false ? 1 : 3 is Num) // expect: true
|
||||
IO.print(false ? 1 : new Foo) // expect: instance of Foo
|
||||
IO.print(false ? 1 : Foo.new()) // expect: instance of Foo
|
||||
|
||||
// Associativity.
|
||||
IO.print(true ? 2 : true ? 4 : 5) // expect: 2
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
this +(value) { // expect error
|
||||
IO.print("ok")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
this -(value) { // expect error
|
||||
IO.print("ok")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
this name=(value) { // expect error
|
||||
IO.print("ok")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
static this new() {} // expect error
|
||||
this static new() {} // expect error
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
this [value] { // expect error
|
||||
IO.print("ok")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
this ! { // expect error
|
||||
IO.print("ok")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class Foo {
|
||||
this new() {
|
||||
IO.print("ok")
|
||||
}
|
||||
}
|
||||
|
||||
var foo = Foo.new() // expect: ok
|
||||
foo.new() // expect runtime error: Foo does not implement 'new()'.
|
||||
@@ -2,7 +2,7 @@ class Foo {
|
||||
toString { "Foo" }
|
||||
}
|
||||
|
||||
// Classes inherit the argument-less "new" one by default.
|
||||
var foo = new Foo
|
||||
// Classes get an argument-less "new()" by default.
|
||||
var foo = Foo.new()
|
||||
IO.print(foo is Foo) // expect: true
|
||||
IO.print(foo.toString) // expect: Foo
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
this new() {
|
||||
IO.print("Foo.new()")
|
||||
}
|
||||
}
|
||||
|
||||
class Bar is Foo {}
|
||||
|
||||
Bar.new() // expect: Foo.new()
|
||||
@@ -2,6 +2,8 @@ class Foo {
|
||||
+(other) { "Foo " + other }
|
||||
}
|
||||
|
||||
IO.print(new Foo + "value") // expect: Foo value
|
||||
IO.print(Foo.new() + "value") // expect: Foo value
|
||||
|
||||
// TODO: Other expressions following a constructor, like new Foo.bar("arg").
|
||||
// TODO: Delete this test?
|
||||
// TODO: Other constructor tests, like named constructors, etc.
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// TODO: Change this.
|
||||
|
||||
class Foo {
|
||||
this named() { _field = "named" }
|
||||
this other() { _field = "other" }
|
||||
|
||||
toString { _field }
|
||||
}
|
||||
|
||||
IO.print(Foo.named()) // expect: named
|
||||
IO.print(Foo.other()) // expect: other
|
||||
|
||||
// Returns the new instance.
|
||||
var foo = Foo.named()
|
||||
IO.print(foo is Foo) // expect: true
|
||||
IO.print(foo.toString) // expect: named
|
||||
@@ -1,19 +0,0 @@
|
||||
class Foo {
|
||||
new { IO.print("none") }
|
||||
new() { IO.print("zero") }
|
||||
new(a) { IO.print(a) }
|
||||
new(a, b) { IO.print(a + b) }
|
||||
|
||||
toString { "Foo" }
|
||||
}
|
||||
|
||||
// Can overload by arity.
|
||||
new Foo // expect: none
|
||||
new Foo() // expect: zero
|
||||
new Foo("one") // expect: one
|
||||
new Foo("one", "two") // expect: onetwo
|
||||
|
||||
// Returns the new instance.
|
||||
var foo = new Foo // expect: none
|
||||
IO.print(foo is Foo) // expect: true
|
||||
IO.print(foo.toString) // expect: Foo
|
||||
@@ -0,0 +1,6 @@
|
||||
class Foo {
|
||||
this real() {}
|
||||
}
|
||||
|
||||
// Classes do not get an argument-less "new()" if they define a constructor.
|
||||
var foo = Foo.new() // expect runtime error: Foo metaclass does not implement 'new()'.
|
||||
@@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
this new { // expect error
|
||||
IO.print("ok")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo {
|
||||
this base() {}
|
||||
}
|
||||
|
||||
class Bar is Foo {}
|
||||
|
||||
Bar.base() // expect runtime error: Bar metaclass does not implement 'base()'.
|
||||
@@ -0,0 +1,13 @@
|
||||
// Tests that Object implements new(). The only way to call that is through a
|
||||
// super() call in a subclass, so this does that.
|
||||
|
||||
class Foo {
|
||||
this new() {
|
||||
super() // Should not cause a no method error.
|
||||
IO.print("ok")
|
||||
}
|
||||
}
|
||||
|
||||
Foo.new() // expect: ok
|
||||
|
||||
// TODO: Test that can't invoke initializer on existing instance.
|
||||
@@ -0,0 +1,7 @@
|
||||
class A {}
|
||||
|
||||
class B is A {
|
||||
this new() {
|
||||
super // expect error
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -3,7 +3,7 @@ var closure
|
||||
|
||||
{
|
||||
var a = "before"
|
||||
fiber = new Fiber {
|
||||
fiber = Fiber.new {
|
||||
IO.print(a)
|
||||
Fiber.yield()
|
||||
a = "after"
|
||||
@@ -12,7 +12,7 @@ var closure
|
||||
a = "final"
|
||||
}
|
||||
|
||||
closure = new Fn {
|
||||
closure = Fn.new {
|
||||
IO.print(a)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
class Foo {
|
||||
new { _field = "Foo field" }
|
||||
this new() { _field = "Foo field" }
|
||||
|
||||
closeOverGet {
|
||||
return new Fn { _field }
|
||||
return Fn.new { _field }
|
||||
}
|
||||
|
||||
closeOverSet {
|
||||
return new Fn { _field = "new value" }
|
||||
return Fn.new { _field = "new value" }
|
||||
}
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
IO.print(foo.closeOverGet.call()) // expect: Foo field
|
||||
foo.closeOverSet.call()
|
||||
IO.print(foo.closeOverGet.call()) // expect: new value
|
||||
|
||||
@@ -2,4 +2,4 @@ class Foo {
|
||||
write { IO.print(_field) }
|
||||
}
|
||||
|
||||
(new Foo).write // expect: null
|
||||
Foo.new().write // expect: null
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
static bar {
|
||||
new Fn { _field = "wat" } // expect error
|
||||
Fn.new { _field = "wat" } // expect error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
foo.set(1, 2, 3, 4, 5)
|
||||
foo.write
|
||||
// expect: 1
|
||||
|
||||
@@ -10,9 +10,9 @@ class Outer {
|
||||
}
|
||||
}
|
||||
|
||||
(new Inner).method
|
||||
Inner.new().method
|
||||
IO.print(_field) // expect: outer
|
||||
}
|
||||
}
|
||||
|
||||
(new Outer).method
|
||||
Outer.new().method
|
||||
|
||||
@@ -1,36 +1,32 @@
|
||||
// This test exists mainly to make sure the GC traces instance fields.
|
||||
class Node {
|
||||
set(left, value, right) {
|
||||
this new(left, value, right) {
|
||||
_left = left
|
||||
_value = value
|
||||
_right = right
|
||||
}
|
||||
|
||||
write {
|
||||
write() {
|
||||
if (_left is Node) {
|
||||
_left.write
|
||||
_left.write()
|
||||
}
|
||||
|
||||
IO.print(_value)
|
||||
|
||||
if (_right is Node) {
|
||||
_right.write
|
||||
_right.write()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var a = new Node
|
||||
a.set(null, "a", null)
|
||||
var b = new Node
|
||||
b.set(null, "b", null)
|
||||
var c = new Node
|
||||
c.set(a, "c", b)
|
||||
var a = Node.new(null, "a", null)
|
||||
var b = Node.new(null, "b", null)
|
||||
var c = Node.new(a, "c", b)
|
||||
a = null
|
||||
b = null
|
||||
var d = new Node
|
||||
d.set(c, "d", null)
|
||||
var d = Node.new(c, "d", null)
|
||||
c = null
|
||||
d.write
|
||||
d.write()
|
||||
// expect: a
|
||||
// expect: c
|
||||
// expect: b
|
||||
|
||||
@@ -3,7 +3,7 @@ class Foo {
|
||||
init { _field = "value" } // ...before an assignment to it.
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
// But invoke them in the right order.
|
||||
foo.init
|
||||
foo.write // expect: value
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var list = []
|
||||
|
||||
for (i in [1, 2, 3]) {
|
||||
list.add(new Fn { IO.print(i) })
|
||||
list.add(Fn.new { IO.print(i) })
|
||||
}
|
||||
|
||||
for (f in list) f.call()
|
||||
|
||||
@@ -2,7 +2,7 @@ var list = []
|
||||
|
||||
for (i in [1, 2, 3]) {
|
||||
var j = i + 1
|
||||
list.add(new Fn { IO.print(j) })
|
||||
list.add(Fn.new { IO.print(j) })
|
||||
}
|
||||
|
||||
for (f in list) f.call()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var f = new Fn {
|
||||
var f = Fn.new {
|
||||
IO.print("evaluate sequence")
|
||||
return [1, 2, 3]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var f = new Fn {
|
||||
var f = Fn.new {
|
||||
for (i in [1, 2, 3]) {
|
||||
return new Fn { IO.print(i) }
|
||||
return Fn.new { IO.print(i) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var f = new Fn {
|
||||
var f = Fn.new {
|
||||
for (i in [1, 2, 3]) {
|
||||
return i
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
class Iter {
|
||||
new(value) { _value = value }
|
||||
this new(value) { _value = value }
|
||||
iterate(iterator) { _value }
|
||||
iteratorValue(iterator) { "value" }
|
||||
}
|
||||
|
||||
// False and null are false.
|
||||
for (n in new Iter(false)) {
|
||||
for (n in Iter.new(false)) {
|
||||
IO.print("bad")
|
||||
break
|
||||
}
|
||||
|
||||
for (n in new Iter(null)) {
|
||||
for (n in Iter.new(null)) {
|
||||
IO.print("bad")
|
||||
break
|
||||
}
|
||||
|
||||
// Everything else is true.
|
||||
for (n in new Iter(true)) {
|
||||
for (n in Iter.new(true)) {
|
||||
IO.print("true") // expect: true
|
||||
break
|
||||
}
|
||||
|
||||
for (n in new Iter(0)) {
|
||||
for (n in Iter.new(0)) {
|
||||
IO.print(0) // expect: 0
|
||||
break
|
||||
}
|
||||
|
||||
for (n in new Iter("")) {
|
||||
for (n in Iter.new("")) {
|
||||
IO.print("string") // expect: string
|
||||
break
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
var f = new Fn {}
|
||||
var f = Fn.new {}
|
||||
IO.print(f.call()) // expect: null
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var f = new Fn {
|
||||
var f = Fn.new {
|
||||
// Hi.
|
||||
}
|
||||
IO.print(f.call()) // expect: null
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
new Fn {
|
||||
Fn.new {
|
||||
IO.print("ok") } // expect error
|
||||
@@ -1 +1 @@
|
||||
new Fn {|| null } // expect error
|
||||
Fn.new {|| null } // expect error
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
var f0 = new Fn { 0 }
|
||||
var f0 = Fn.new { 0 }
|
||||
IO.print(f0.call()) // expect: 0
|
||||
|
||||
var f1 = new Fn {|a| a }
|
||||
var f1 = Fn.new {|a| a }
|
||||
IO.print(f1.call(1)) // expect: 1
|
||||
|
||||
var f2 = new Fn {|a, b| a + b }
|
||||
var f2 = Fn.new {|a, b| a + b }
|
||||
IO.print(f2.call(1, 2)) // expect: 3
|
||||
|
||||
var f3 = new Fn {|a, b, c| a + b + c }
|
||||
var f3 = Fn.new {|a, b, c| a + b + c }
|
||||
IO.print(f3.call(1, 2, 3)) // expect: 6
|
||||
|
||||
var f4 = new Fn {|a, b, c, d| a + b + c + d }
|
||||
var f4 = Fn.new {|a, b, c, d| a + b + c + d }
|
||||
IO.print(f4.call(1, 2, 3, 4)) // expect: 10
|
||||
|
||||
var f5 = new Fn {|a, b, c, d, e| a + b + c + d + e }
|
||||
var f5 = Fn.new {|a, b, c, d, e| a + b + c + d + e }
|
||||
IO.print(f5.call(1, 2, 3, 4, 5)) // expect: 15
|
||||
|
||||
var f6 = new Fn {|a, b, c, d, e, f| a + b + c + d + e + f }
|
||||
var f6 = Fn.new {|a, b, c, d, e, f| a + b + c + d + e + f }
|
||||
IO.print(f6.call(1, 2, 3, 4, 5, 6)) // expect: 21
|
||||
|
||||
var f7 = new Fn {|a, b, c, d, e, f, g| a + b + c + d + e + f + g }
|
||||
var f7 = Fn.new {|a, b, c, d, e, f, g| a + b + c + d + e + f + g }
|
||||
IO.print(f7.call(1, 2, 3, 4, 5, 6, 7)) // expect: 28
|
||||
|
||||
var f8 = new Fn {|a, b, c, d, e, f, g, h| a + b + c + d + e + f + g + h }
|
||||
var f8 = Fn.new {|a, b, c, d, e, f, g, h| a + b + c + d + e + f + g + h }
|
||||
IO.print(f8.call(1, 2, 3, 4, 5, 6, 7, 8)) // expect: 36
|
||||
|
||||
var f9 = new Fn {|a, b, c, d, e, f, g, h, i| a + b + c + d + e + f + g + h + i }
|
||||
var f9 = Fn.new {|a, b, c, d, e, f, g, h, i| a + b + c + d + e + f + g + h + i }
|
||||
IO.print(f9.call(1, 2, 3, 4, 5, 6, 7, 8, 9)) // expect: 45
|
||||
|
||||
var f10 = new Fn {|a, b, c, d, e, f, g, h, i, j| a + b + c + d + e + f + g + h + i + j }
|
||||
var f10 = Fn.new {|a, b, c, d, e, f, g, h, i, j| a + b + c + d + e + f + g + h + i + j }
|
||||
IO.print(f10.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) // expect: 55
|
||||
|
||||
var f11 = new Fn {|a, b, c, d, e, f, g, h, i, j, k| a + b + c + d + e + f + g + h + i + j + k }
|
||||
var f11 = Fn.new {|a, b, c, d, e, f, g, h, i, j, k| a + b + c + d + e + f + g + h + i + j + k }
|
||||
IO.print(f11.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)) // expect: 66
|
||||
|
||||
var f12 = new Fn {|a, b, c, d, e, f, g, h, i, j, k, l| a + b + c + d + e + f + g + h + i + j + k + l }
|
||||
var f12 = Fn.new {|a, b, c, d, e, f, g, h, i, j, k, l| a + b + c + d + e + f + g + h + i + j + k + l }
|
||||
IO.print(f12.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)) // expect: 78
|
||||
|
||||
var f13 = new Fn {|a, b, c, d, e, f, g, h, i, j, k, l, m| a + b + c + d + e + f + g + h + i + j + k + l + m }
|
||||
var f13 = Fn.new {|a, b, c, d, e, f, g, h, i, j, k, l, m| a + b + c + d + e + f + g + h + i + j + k + l + m }
|
||||
IO.print(f13.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)) // expect: 91
|
||||
|
||||
var f14 = new Fn {|a, b, c, d, e, f, g, h, i, j, k, l, m, n| a + b + c + d + e + f + g + h + i + j + k + l + m + n }
|
||||
var f14 = Fn.new {|a, b, c, d, e, f, g, h, i, j, k, l, m, n| a + b + c + d + e + f + g + h + i + j + k + l + m + n }
|
||||
IO.print(f14.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)) // expect: 105
|
||||
|
||||
var f15 = new Fn {|a, b, c, d, e, f, g, h, i, j, k, l, m, n, o| a + b + c + d + e + f + g + h + i + j + k + l + m + n + o }
|
||||
var f15 = Fn.new {|a, b, c, d, e, f, g, h, i, j, k, l, m, n, o| a + b + c + d + e + f + g + h + i + j + k + l + m + n + o }
|
||||
IO.print(f15.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)) // expect: 120
|
||||
|
||||
var f16 = new Fn {|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 f16 = Fn.new {|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 }
|
||||
IO.print(f16.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)) // expect: 136
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
// Single expression body.
|
||||
new Fn { IO.print("ok") }.call() // expect: ok
|
||||
Fn.new { IO.print("ok") }.call() // expect: ok
|
||||
|
||||
// Curly body.
|
||||
new Fn {
|
||||
Fn.new {
|
||||
IO.print("ok") // expect: ok
|
||||
}.call()
|
||||
|
||||
// Multiple statements.
|
||||
new Fn {
|
||||
Fn.new {
|
||||
IO.print("1") // expect: 1
|
||||
IO.print("2") // expect: 2
|
||||
}.call()
|
||||
|
||||
// Extra newlines.
|
||||
new Fn {
|
||||
Fn.new {
|
||||
|
||||
|
||||
IO.print("1") // expect: 1
|
||||
|
||||
@@ -20,4 +20,4 @@ class Bar is Foo {
|
||||
}
|
||||
}
|
||||
|
||||
(new Bar).test
|
||||
Bar.new().test
|
||||
|
||||
@@ -18,6 +18,6 @@ class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
(new Foo).test
|
||||
Foo.new().test
|
||||
|
||||
// TODO: Need to decide how these interact with globals.
|
||||
|
||||
@@ -14,4 +14,4 @@ class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
(new Foo).test
|
||||
Foo.new().test
|
||||
|
||||
@@ -17,4 +17,4 @@ class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
(new Foo).test
|
||||
Foo.new().test
|
||||
|
||||
@@ -36,7 +36,7 @@ class Outer {
|
||||
}
|
||||
}
|
||||
|
||||
(new Inner).test
|
||||
Inner.new().test
|
||||
|
||||
getter // expect: outer getter
|
||||
setter = "value" // expect: outer setter
|
||||
@@ -44,4 +44,4 @@ class Outer {
|
||||
}
|
||||
}
|
||||
|
||||
(new Outer).test
|
||||
Outer.new().test
|
||||
|
||||
@@ -22,7 +22,7 @@ class Bar is Foo {
|
||||
}
|
||||
}
|
||||
|
||||
var bar = new Bar
|
||||
var bar = Bar.new()
|
||||
bar.foo("foo 1", "foo 2")
|
||||
bar.bar("bar 1", "bar 2")
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ var ClosureType
|
||||
|
||||
{
|
||||
var a = "a"
|
||||
ClosureType = new Fn { IO.print(a) }.type
|
||||
ClosureType = Fn.new { IO.print(a) }.type
|
||||
}
|
||||
|
||||
class Subclass is ClosureType {} // expect runtime error: Subclass cannot inherit from Fn.
|
||||
|
||||
@@ -12,7 +12,7 @@ class Bar is Foo {
|
||||
override { IO.print("bar") }
|
||||
}
|
||||
|
||||
var bar = new Bar
|
||||
var bar = Bar.new()
|
||||
bar.methodOnFoo // expect: foo
|
||||
bar.methodOnBar // expect: bar
|
||||
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
class Foo {
|
||||
new { _field = "Foo field" }
|
||||
this new() { _field = "Foo field" }
|
||||
|
||||
closeOverFooGet {
|
||||
return new Fn { new Fn { _field } }
|
||||
return Fn.new { Fn.new { _field } }
|
||||
}
|
||||
|
||||
closeOverFooSet {
|
||||
return new Fn { new Fn { _field = "new foo value" } }
|
||||
return Fn.new { Fn.new { _field = "new foo value" } }
|
||||
}
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
new {
|
||||
super
|
||||
this new() {
|
||||
super()
|
||||
_field = "Bar field"
|
||||
}
|
||||
|
||||
closeOverBarGet {
|
||||
return new Fn { new Fn { _field } }
|
||||
return Fn.new { Fn.new { _field } }
|
||||
}
|
||||
|
||||
closeOverBarSet {
|
||||
return new Fn { new Fn { _field = "new bar value" } }
|
||||
return Fn.new { Fn.new { _field = "new bar value" } }
|
||||
}
|
||||
}
|
||||
|
||||
var bar = new Bar
|
||||
var bar = Bar.new()
|
||||
IO.print(bar.closeOverFooGet.call().call()) // expect: Foo field
|
||||
IO.print(bar.closeOverBarGet.call().call()) // expect: Bar field
|
||||
bar.closeOverFooSet.call().call()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
class A {}
|
||||
class B is A {}
|
||||
class C is B {}
|
||||
var a = new A
|
||||
var b = new B
|
||||
var c = new C
|
||||
var a = A.new()
|
||||
var b = B.new()
|
||||
var c = C.new()
|
||||
|
||||
IO.print(a is A) // expect: true
|
||||
IO.print(a is B) // expect: false
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
IO.print(Num is Class) // expect: true
|
||||
IO.print(true is Bool) // expect: true
|
||||
IO.print(new Fn { 1 } is Fn) // expect: true
|
||||
IO.print(Fn.new { 1 } is Fn) // expect: true
|
||||
IO.print(123 is Num) // expect: true
|
||||
IO.print(null is Null) // expect: true
|
||||
IO.print("s" is String) // expect: true
|
||||
@@ -8,7 +8,7 @@ IO.print("s" is String) // expect: true
|
||||
IO.print(Num is Bool) // expect: false
|
||||
IO.print(null is Class) // expect: false
|
||||
IO.print(true is Fn) // expect: false
|
||||
IO.print(new Fn { 1 } is Num) // expect: false
|
||||
IO.print(Fn.new { 1 } is Num) // expect: false
|
||||
IO.print("s" is Null) // expect: false
|
||||
IO.print(123 is String) // expect: false
|
||||
|
||||
@@ -16,7 +16,7 @@ IO.print(123 is String) // expect: false
|
||||
IO.print(Num is Object) // expect: true
|
||||
IO.print(null is Object) // expect: true
|
||||
IO.print(true is Object) // expect: true
|
||||
IO.print(new Fn { 1 } is Object) // expect: true
|
||||
IO.print(Fn.new { 1 } is Object) // expect: true
|
||||
IO.print("s" is Object) // expect: true
|
||||
IO.print(123 is Object) // expect: true
|
||||
|
||||
@@ -24,7 +24,7 @@ IO.print(123 is Object) // expect: true
|
||||
IO.print(Num is Class) // expect: true
|
||||
IO.print(null is Class) // expect: false
|
||||
IO.print(true is Class) // expect: false
|
||||
IO.print(new Fn { 1 } is Class) // expect: false
|
||||
IO.print(Fn.new { 1 } is Class) // expect: false
|
||||
IO.print("s" is Class) // expect: false
|
||||
IO.print(123 is Class) // expect: false
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
var a = 123
|
||||
new a // expect runtime error: Must provide a class to 'new' to construct.
|
||||
@@ -1,2 +0,0 @@
|
||||
new // expect error
|
||||
Fn {}
|
||||
@@ -12,7 +12,7 @@ class Foo {
|
||||
Foo.method
|
||||
IO.print(Nonlocal) // expect: method
|
||||
|
||||
new Fn {
|
||||
Fn.new {
|
||||
Nonlocal = "fn"
|
||||
}.call()
|
||||
IO.print(Nonlocal) // expect: fn
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
class Foo {
|
||||
static bar { new Bar }
|
||||
static bar { Bar.new() }
|
||||
}
|
||||
|
||||
class Bar {
|
||||
static foo { new Foo }
|
||||
static foo { Foo.new() }
|
||||
}
|
||||
|
||||
IO.print(Foo.bar) // expect: instance of Bar
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
var fn = new Fn {
|
||||
var fn = Fn.new {
|
||||
IO.print(Foo)
|
||||
IO.print(Bar)
|
||||
}
|
||||
|
||||
// expect error line 7
|
||||
// expect error line 7
|
||||
// expect error line 6
|
||||
@@ -1,5 +1,5 @@
|
||||
var Global = "global"
|
||||
|
||||
new Fn {
|
||||
Fn.new {
|
||||
IO.print(Global) // expect: global
|
||||
}.call()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var f = new Fn {
|
||||
var f = Fn.new {
|
||||
IO.print(Global)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,5 +10,5 @@ class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
(new Foo).method // expect: global
|
||||
Foo.new().method // expect: global
|
||||
Foo.classMethod // expect: global
|
||||
|
||||
@@ -10,5 +10,5 @@ class Foo {
|
||||
|
||||
var Global = "global"
|
||||
|
||||
(new Foo).method // expect: global
|
||||
Foo.new().method // expect: global
|
||||
Foo.classMethod // expect: global
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
IO.print(new Fn {
|
||||
IO.print(Fn.new {
|
||||
if (false) "no" else return "ok"
|
||||
}.call()) // expect: ok
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
IO.print(new Fn {
|
||||
IO.print(Fn.new {
|
||||
if (true) return "ok"
|
||||
}.call()) // expect: ok
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
IO.print(new Fn {
|
||||
IO.print(Fn.new {
|
||||
while (true) return "ok"
|
||||
}.call()) // expect: ok
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var f = new Fn {
|
||||
var f = Fn.new {
|
||||
return "ok"
|
||||
IO.print("bad")
|
||||
}
|
||||
|
||||
@@ -5,4 +5,4 @@ class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
IO.print((new Foo).method) // expect: ok
|
||||
IO.print(Foo.new().method) // expect: ok
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var f = new Fn {
|
||||
var f = Fn.new {
|
||||
return
|
||||
IO.print("bad")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
new(value) { _value = value }
|
||||
this new(value) { _value = value }
|
||||
toString { _value }
|
||||
bar=(value) {
|
||||
_value = value
|
||||
@@ -7,9 +7,9 @@ class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
var a = new Foo("a")
|
||||
var b = new Foo("b")
|
||||
var c = new Foo("c")
|
||||
var a = Foo.new("a")
|
||||
var b = Foo.new("b")
|
||||
var c = Foo.new("c")
|
||||
|
||||
// Assignment is right-associative.
|
||||
a.bar = b.bar = c.bar = "d"
|
||||
|
||||
@@ -2,5 +2,5 @@ class Foo {
|
||||
bar=(value) { value }
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
(foo.bar) = "value" // expect error
|
||||
|
||||
@@ -2,5 +2,5 @@ class Foo {
|
||||
bar=(value) { value }
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
"a" + foo.bar = "value" // expect error
|
||||
|
||||
@@ -4,5 +4,5 @@ class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
foo.bar = "value" // expect: value
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user