crystal icon indicating copy to clipboard operation
crystal copied to clipboard

Fix `Class#nilable?` for recursive unions and root types

Open HertzDevil opened this issue 1 year ago • 1 comments

Fixes #6447. Does not affect the macro method TypeNode#nilable?. Also does not affect the compiler's notion of a nilable type (which uses instead Type#includes_type?(NilType)).

HertzDevil avatar Aug 03 '22 10:08 HertzDevil

For illustration, this is what we're talking about:

def foo(v : Value)
  v.nil? # => true
end
def bar(o : Object)
  o.nil? # => true
end
foo nil
bar nil

Any parent type of Nil or Union is nilable because it can hold a value of type Nil.

straight-shoota avatar Aug 03 '22 21:08 straight-shoota