As requested at #1843 by @R4PaSs, a new annotation `optional` is now available on attributes.
~~~nit
class A
var x: Int = 99 is optional
# Because of `optional`, the automatic signature of the A constructor is `init(x: nullable Int)`
end
var a = new A
print a.x # outputs 99
var b = new A(4)
print b.x # output 4
~~~
In the model, the `optional` annotation only affects the signature and the behavior of the setter.
It transforms the argument to a `nullable` one and use the provided value if `null` is given as a parameter.
The `nullable` parameter is then propagated to the automatic constructors in the usual way.
Basically, the previous example is equivalent to having written:
~~~
class A
var x: Int is noautoinit
fun x=(x: nullable Int) is autoinit do if x != null then self.x = x else self.x = 99
end
~~~
Pull-Request: #1965
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>