feat: replace 'this' keyword with 'construct' for constructor definitions across core lib, compiler, docs, and tests
Add TOKEN_CONSTRUCT as a new reserved word in the Wren compiler lexer and parser, and update the grammar rule table so that 'construct' triggers a constructor signature instead of 'this'. Modify all built-in class definitions in core.wren, wren_core.c, benchmark files, and test fixtures to use 'construct new(...)' and 'construct named(...)' syntax. Update documentation in classes.markdown and syntax.markdown to reflect the new keyword, and remove the deprecated test files for 'new' and infix class expressions.
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
class Foo {}
|
||||
|
||||
var foo = Foo.new()
|
||||
IO.print(foo is Foo) // expect: true
|
||||
|
||||
// TODO: Test precedence and grammar of what follows "new".
|
||||
@@ -1,4 +1,4 @@
|
||||
class Foo {
|
||||
static this new() {} // expect error
|
||||
this static new() {} // expect error
|
||||
static construct new() {} // expect error
|
||||
construct static new() {} // expect error
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
this new() {
|
||||
construct new() {
|
||||
IO.print("ok")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
this new() {
|
||||
construct new() {
|
||||
IO.print("Foo.new()")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
class Foo {
|
||||
+(other) { "Foo " + other }
|
||||
}
|
||||
|
||||
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.
|
||||
@@ -1,8 +1,6 @@
|
||||
// TODO: Change this.
|
||||
|
||||
class Foo {
|
||||
this named() { _field = "named" }
|
||||
this other() { _field = "other" }
|
||||
construct named() { _field = "named" }
|
||||
construct other() { _field = "other" }
|
||||
|
||||
toString { _field }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
this real() {}
|
||||
construct real() {}
|
||||
}
|
||||
|
||||
// Classes do not get an argument-less "new()" if they define a constructor.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
this base() {}
|
||||
construct base() {}
|
||||
}
|
||||
|
||||
class Bar is Foo {}
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
// super() call in a subclass, so this does that.
|
||||
|
||||
class Foo {
|
||||
this new() {
|
||||
construct 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.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class A {}
|
||||
|
||||
class B is A {
|
||||
this new() {
|
||||
construct new() {
|
||||
super // expect error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class A {
|
||||
this new(arg) {
|
||||
construct new(arg) {
|
||||
IO.print("new A ", arg)
|
||||
_field = arg
|
||||
}
|
||||
@@ -8,7 +8,7 @@ class A {
|
||||
}
|
||||
|
||||
class B is A {
|
||||
this new(arg1, arg2) {
|
||||
construct new(arg1, arg2) {
|
||||
super(arg2)
|
||||
IO.print("new B ", arg1)
|
||||
_field = arg1
|
||||
@@ -18,7 +18,7 @@ class B is A {
|
||||
}
|
||||
|
||||
class C is B {
|
||||
this new() {
|
||||
construct new() {
|
||||
super("one", "two")
|
||||
IO.print("new C")
|
||||
_field = "c"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
this new() { _field = "Foo field" }
|
||||
construct new() { _field = "Foo field" }
|
||||
|
||||
closeOverGet {
|
||||
return Fn.new { _field }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// This test exists mainly to make sure the GC traces instance fields.
|
||||
class Node {
|
||||
this new(left, value, right) {
|
||||
construct new(left, value, right) {
|
||||
_left = left
|
||||
_value = value
|
||||
_right = right
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Iter {
|
||||
this new(value) { _value = value }
|
||||
construct new(value) { _value = value }
|
||||
iterate(iterator) { _value }
|
||||
iteratorValue(iterator) { "value" }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
this new() { _field = "Foo field" }
|
||||
construct new() { _field = "Foo field" }
|
||||
|
||||
closeOverFooGet {
|
||||
return Fn.new { Fn.new { _field } }
|
||||
@@ -11,7 +11,7 @@ class Foo {
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
this new() {
|
||||
construct new() {
|
||||
super()
|
||||
_field = "Bar field"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
this new(value) { _value = value }
|
||||
construct new(value) { _value = value }
|
||||
toString { _value }
|
||||
bar=(value) {
|
||||
_value = value
|
||||
|
||||
Reference in New Issue
Block a user