Nit does not have intersection nor union types, however, the intersection and the difference operations on types are needed for a better behavior of the adaptive typing system.
Currently, the only need of type intersection and type difference is with `isa`. The previous implementation did not really implement them and only did the following:
~~~nit
var x: X
...
if x isa Y then
# if X<:Y then x is still a X (and you get a warning) else x is now a Y
...
else
# nothing never change here. x is a X
...
end
~~~
Now, the `then` branch, handle the merge of nullable types and the `else` branch might also be adapted.
~~~nit
var x: nullable X # where Y <: X
...
if x isa Object then
# x is a X (instead of Object as before)
else
# x is null (instead of nullable X as before)
end
if x isa nullable Object then # warning, useless isa
# x is a nullable X (as before)
else
# x is dead (instead of nullable X as before)
end
if x isa Y then
# x is a Y (same as before)
else
# x is a nullable X (same as before)
end
if x isa nullable Y then
# x is a nullable Y (as before)
else
# x is a X without nullable (instead of nullable X as before)
end
~~~
I do not expect that these change improve that much the expressiveness of the language. However, it makes the type system a little more consistent and a little less hackish.
Pull-Request: #2385
Reviewed-by: Jean-Christophe Beaupré <jcbrinfo.public@gmail.com>