Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/typeprof/core/ast/sig_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,16 @@ def contravariant_vertex0(genv, changes, vtx, subst)
end

def typecheck(genv, changes, vtx, subst)
# For optional type T?, check if all non-nil types match T.
# nil is always acceptable.
changes.add_edge(genv, vtx, changes.target)
has_non_nil = false
vtx.each_type do |ty|
next if ty.is_a?(Type::Bot)
next if ty == genv.nil_type
has_non_nil = true
end
return true unless has_non_nil
@type.typecheck(genv, changes, vtx, subst)
end

Expand Down
21 changes: 21 additions & 0 deletions scenario/rbs/optional_nil_typecheck.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## update: test.rbs
class Object
def bar: (Binding?) -> void
end

## update: test.rb
eval("hello", nil, "test")

def bar_nil
bar(nil)
end

def bar_binding
bar(binding)
end

## assert
class Object
def bar_nil: -> Object
def bar_binding: -> Object
end
Loading