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
4 changes: 2 additions & 2 deletions lib/rbs/test/type_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def value(val, type)
when Types::Bases::Any
true
when Types::Bases::Bool
val.is_a?(TrueClass) || val.is_a?(FalseClass)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative may be Module#===: TrueClass === val

Test.call(val, IS_AP, TrueClass) || Test.call(val, IS_AP, FalseClass)
when Types::Bases::Top
true
when Types::Bases::Bottom
Expand Down Expand Up @@ -323,7 +323,7 @@ def value(val, type)
rescue TypeError
return false
end
val.is_a?(singleton_class)
Test.call(val, IS_AP, singleton_class)
when Types::Interface
if (definition = builder.build_interface(type.name.absolute!))
definition.methods.each.all? do |method_name, method|
Expand Down
2 changes: 2 additions & 0 deletions test/rbs/test/type_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def to_int: () -> Integer
assert typecheck.value(String, parse_type("singleton(::String)"))
assert typecheck.value(String, parse_type("singleton(::Object)"))
refute typecheck.value(String, parse_type("singleton(::Integer)"))
refute typecheck.value(BasicObject.new, parse_type("singleton(::BasicObject)"))

assert typecheck.value(3, parse_type("::M::t"))
assert typecheck.value(3, parse_type("::M::s"))
Expand All @@ -65,6 +66,7 @@ def to_int: () -> Integer
assert typecheck.value(false, parse_type("bool"))
refute typecheck.value(nil, parse_type("bool"))
refute typecheck.value("", parse_type("bool"))
refute typecheck.value(BasicObject.new, parse_type("bool"))
end
end
end
Expand Down