crystal
crystal copied to clipboard
Return type restriction on `NilableCast` (`as?`)
I noticed that the return type of x.as?(T)
is always T | Nil
.
In some cases however, could be further reduced. This could allow removal of some code paths that would never be reached anyway.
- If
typeof(x) <= T
, the result is alwaysT
. - If
typeof(x)
has no intersection withY
, the result is alwaysNil
.
I don't see any particular reason why the return type should not be restricted as much as possible, but maybe I'm missing something.