Skip to content

Commit

Permalink
Merge pull request #841 from soutaro/case-untyped-nil
Browse files Browse the repository at this point in the history
Make type of `case` node `untyped` rather than `nil`
  • Loading branch information
soutaro committed Jul 6, 2023
2 parents 20834c6 + a1842ec commit c1b1a1e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4477,6 +4477,9 @@ def union_type(*types)

def union_type_unify(*types)
types.inject do |type1, type2|
next type1 if type1.is_a?(AST::Types::Any)
next type2 if type2.is_a?(AST::Types::Any)

unless no_subtyping?(sub_type: type1, super_type: type2)
next type2
end
Expand Down
29 changes: 29 additions & 0 deletions test/type_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,33 @@ def test_branch_unreachable__logic_type
YAML
)
end

def test_type_case__returns_nil_untyped_union
run_type_check_test(
signatures: {
},
code: {
"a.rb" => <<~RUBY
x = _ = 1
y = _ = 2
z = _ = 3
a =
case x
when :foo
y
when :bar
z
end
a.is_untyped
RUBY
},
expectations: <<~YAML
---
- file: a.rb
diagnostics: []
YAML
)
end
end

0 comments on commit c1b1a1e

Please sign in to comment.