crystal icon indicating copy to clipboard operation
crystal copied to clipboard

Return type restriction on `NilableCast` (`as?`)

Open straight-shoota opened this issue 10 months ago • 0 comments

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 always T.
  • If typeof(x) has no intersection with Y, the result is always Nil.

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.

straight-shoota avatar Apr 16 '24 12:04 straight-shoota