Skip to content

Commit

Permalink
Merge pull request #237 from soutaro/type-case-interface
Browse files Browse the repository at this point in the history
Let type-case work for interface types
  • Loading branch information
soutaro authored Oct 9, 2020
2 parents 46529d8 + 323c40d commit d7a6a76
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/steep/type_inference/logic_type_interpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ def type_case_select0(type, klass)
[type]
]

when AST::Types::Name::Interface
[
[instance_type],
[type]
]

else
[
[],
Expand Down
32 changes: 32 additions & 0 deletions test/type_construction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5821,4 +5821,36 @@ class Module
end
end
end

def test_type_case_interface
with_checker(<<-RBS) do |checker|
interface _Fooable
end
class WithName
attr_reader name: String
end
class WithEmail
attr_reader email: String
end
RBS
source = parse_ruby(<<-RUBY)
# @type var x: _Fooable
x = _ = nil
case x
when WithName
x.name
when WithEmail
x.email
end
RUBY

with_standard_construction(checker, source) do |construction, typing|
construction.synthesize(source.node)
assert_no_error typing
end
end
end
end

0 comments on commit d7a6a76

Please sign in to comment.