Two questions in one.
First when redefining an optional attribute:
class A
var foo: String = "foo" is optional
end
class B
super A
redef var foo = "bar" # is optional
end
Without the optional annotation on the redef, the compiler will return:
file.nit:8,12--14: Redef Error: expected `nullable String` type for parameter `foo'; got `String`.
redef var foo = "bar"
^
With the annotation, no problem.
I'm not sure about the spec here. Is the annotation really needed on the redef? If yes, shouldn't the error message be more explicative? Either the spec or the compiler is wrong here.
Then when setting the default value of optional (with the annotation obviously):
var b = new B("ba")
print b.foo
I expected the previous piece of code to display ba but it display bar.
So the attribute is allowed as optional in the constructor but the passed value is never assigned.
Here again, I'm not sure about the spec of this annotation.
Two questions in one.
First when redefining an
optionalattribute:Without the
optionalannotation on the redef, the compiler will return:With the annotation, no problem.
I'm not sure about the spec here. Is the annotation really needed on the redef? If yes, shouldn't the error message be more explicative? Either the spec or the compiler is wrong here.
Then when setting the default value of optional (with the annotation obviously):
I expected the previous piece of code to display
babut it displaybar.So the attribute is allowed as optional in the constructor but the passed value is never assigned.
Here again, I'm not sure about the spec of this annotation.