Skip to content

Commit

Permalink
Logic type is a boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Sep 9, 2024
1 parent b132550 commit 8af2e27
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 1 addition & 4 deletions lib/steep/subtyping/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@ def check_type0(relation)
when relation.sub_type.is_a?(AST::Types::Bot)
success(relation)

when relation.sub_type.is_a?(AST::Types::Logic::Base) && (true_type?(relation.super_type) || false_type?(relation.super_type))
success(relation)

when relation.super_type.is_a?(AST::Types::Boolean)
Expand(relation) do
check_type(
Expand All @@ -278,7 +275,7 @@ def check_type0(relation)
)
end

when relation.sub_type.is_a?(AST::Types::Boolean)
when relation.sub_type.is_a?(AST::Types::Boolean) || relation.sub_type.is_a?(AST::Types::Logic::Base)
Expand(relation) do
check_type(
Relation.new(
Expand Down
18 changes: 14 additions & 4 deletions test/subtyping_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -934,10 +934,20 @@ def test_literal_alias_union
def test_logic_type
with_checker do |checker|
type = AST::Types::Logic::ReceiverIsNil.new()
assert_success_check checker, type, "true"
assert_success_check checker, type, "false"
assert_success_check checker, type, "::TrueClass"
assert_success_check checker, type, "::FalseClass"

assert_success_check checker, type, "bool"
assert_success_check checker, type, "Object"
assert_success_check checker, type, "Object?"

assert_fail_check checker, type, "true"
assert_fail_check checker, type, "false"
assert_fail_check checker, type, "::TrueClass"
assert_fail_check checker, type, "::FalseClass"

assert_fail_check checker, "true", type
assert_fail_check checker, "false", type
assert_fail_check checker, "::TrueClass", type
assert_fail_check checker, "::FalseClass", type
end
end

Expand Down

0 comments on commit 8af2e27

Please sign in to comment.