In Chapter 12.7.1 we try to prevent "re-initialization" of the constructor.
By calling this piece of code
class Foo {
init(value) {
print "init value: " + value;
}
}
var foo = Foo("bar");
print foo.init("bug");
we expect this output
init value: bar
Foo instance
Foo instance
but what we actually get is
init value: bar
init value: bug
Foo instance
I'm no expert, but i would consider this behaviour unintended and thus being a bug.
I would suggest we disallow calling the constructor directly and make it a syntax error instead.
This is quite easy to implement, we update the method visitGetExpr in Resolver.java by checking for a get-expression with the name init and than we check if the call comes from inside a class or not.
In Chapter 12.7.1 we try to prevent "re-initialization" of the constructor.
By calling this piece of code
we expect this output
but what we actually get is
I'm no expert, but i would consider this behaviour unintended and thus being a bug.
I would suggest we disallow calling the constructor directly and make it a syntax error instead.
This is quite easy to implement, we update the method
visitGetExpr
inResolver.java
by checking for a get-expression with the nameinit
and than we check if the call comes from inside a class or not.So the resolver will throw a syntax error and we don't get any headaches.