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:
@@ -1,4 +1,4 @@
|
||||
new Fn {
|
||||
Fn.new {
|
||||
IO.print(1) // expect: 1
|
||||
IO.print(2) // expect: 2
|
||||
IO.print(3) // expect: 3
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var f = new Fn {
|
||||
var f = Fn.new {
|
||||
1
|
||||
2
|
||||
3
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
new {
|
||||
this new() {
|
||||
_field1 = 1
|
||||
_field2 = 2
|
||||
_field3 = 3
|
||||
@@ -259,4 +259,4 @@ class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
var foo = new Foo // expect: 255
|
||||
var foo = Foo.new() // expect: 255
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
new {
|
||||
this new() {
|
||||
_field1 = 1
|
||||
_field2 = 2
|
||||
_field3 = 3
|
||||
@@ -137,8 +137,8 @@ class Foo {
|
||||
}
|
||||
|
||||
class Bar is Foo {
|
||||
new {
|
||||
super
|
||||
this new() {
|
||||
super()
|
||||
_field129 = 129
|
||||
_field130 = 130
|
||||
_field131 = 131
|
||||
@@ -274,7 +274,7 @@ class Bar is Foo {
|
||||
}
|
||||
}
|
||||
|
||||
var bar = new Bar
|
||||
var bar = Bar.new()
|
||||
bar.foo // expect: 1
|
||||
// expect: 128
|
||||
bar.bar // expect: 129
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var f = new Fn {
|
||||
var f = Fn.new {
|
||||
1
|
||||
2
|
||||
3
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
new {
|
||||
this new() {
|
||||
_field1 = 1
|
||||
_field2 = 2
|
||||
_field3 = 3
|
||||
@@ -259,4 +259,4 @@ class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
var foo = new Foo
|
||||
var foo = Foo.new()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Foo {
|
||||
new {
|
||||
this new() {
|
||||
_field1 = 1
|
||||
_field2 = 2
|
||||
_field3 = 3
|
||||
@@ -137,8 +137,8 @@ class Foo {
|
||||
}
|
||||
|
||||
class Bar is Foo { // expect runtime error: Class 'Bar' may not have more than 255 fields, including inherited ones.
|
||||
new {
|
||||
super
|
||||
this new() {
|
||||
super()
|
||||
_field129 = 129
|
||||
_field130 = 130
|
||||
_field131 = 131
|
||||
@@ -275,6 +275,6 @@ class Bar is Foo { // expect runtime error: Class 'Bar' may not have more than 2
|
||||
}
|
||||
}
|
||||
|
||||
var bar = new Bar
|
||||
var bar = Bar.new()
|
||||
bar.foo
|
||||
bar.bar
|
||||
|
||||
Reference in New Issue
Block a user