Skip to content

Commit

Permalink
Merge pull request #1459 from soutaro/when-annotation
Browse files Browse the repository at this point in the history
Let annotations in `when` clause without `cond` expression work
  • Loading branch information
soutaro authored Jan 7, 2025
2 parents 7ba1260 + 9e946eb commit 9d9c88e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2026,8 +2026,8 @@ def synthesize(node, hint: nil, condition: false)
branch_result =
if body
when_clause_constr
.for_branch(body)
.update_type_env {|env| env.join(*body_envs) }
.for_branch(body)
.tap {|constr| typing.cursor_context.set_node_context(body, constr.context) }
.synthesize(body, hint: hint)
else
Expand Down
2 changes: 2 additions & 0 deletions sig/test/type_check_test.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,6 @@ class TypeCheckTest < Minitest::Test
def test_undeclared_method2: () -> untyped

def test_when__assertion: () -> untyped

def test_when__type_annotation: () -> untyped
end
28 changes: 28 additions & 0 deletions test/type_check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2869,4 +2869,32 @@ def test_when__assertion
YAML
)
end

def test_when__type_annotation
run_type_check_test(
signatures: {
"a.rbs" => <<~RBS
RBS
},
code: {
"a.rb" => <<~RUBY
a = [1, ""].sample
case
when 1.even?
# @type var a: String
a + ""
when 2.even?
# @type var a: Integer
a + 1
end
RUBY
},
expectations: <<~YAML
---
- file: a.rb
diagnostics: []
YAML
)
end
end

0 comments on commit 9d9c88e

Please sign in to comment.