Skip to content

Commit

Permalink
Merge pull request #206 from soutaro/module-typing
Browse files Browse the repository at this point in the history
Fix module typing
  • Loading branch information
soutaro committed Sep 15, 2020
2 parents 0c64bc7 + 64652a8 commit 63ed42e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/steep/type_construction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ def for_module(node)

instance_type = AST::Types::Intersection.build(
types: [
AST::Types::Name::Instance.new(name: module_name, args: module_args),
AST::Builtin::Object.instance_type,
*module_entry.self_types.map {|module_self|
type = case
Expand All @@ -305,7 +304,8 @@ def for_module(node)
)
end
checker.factory.type(type)
}
},
AST::Types::Name::Instance.new(name: module_name, args: module_args)
].compact
)

Expand Down
2 changes: 1 addition & 1 deletion smoke/module/a.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def count
# !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
s = n

# !expects NoMethodError: type=(::A & ::Object & ::_Each2[::Integer, ::A]), method=foo
# !expects NoMethodError: type=(::Object & ::_Each2[::Integer, ::A] & ::A), method=foo
foo()

n
Expand Down
32 changes: 31 additions & 1 deletion test/type_construction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ module Steep end
),
for_module.module_context.implement_name
)
assert_equal parse_type("::Steep & ::Object"), for_module.module_context.instance_type
assert_equal parse_type("::Object & ::Steep"), for_module.module_context.instance_type
assert_equal parse_type("singleton(::Steep)"), for_module.module_context.module_type
end
end
Expand Down Expand Up @@ -5404,4 +5404,34 @@ def foo(x)
end
end
end

def test_module_method_call
with_checker(<<-RBS) do |checker|
module Types
def foo: () -> String
def hash: () -> String
end
class Object
def hash: () -> Integer
end
RBS
source = parse_ruby(<<-RUBY)
module Types
def foo
hash + "a"
end
def hash
"foo"
end
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 63ed42e

Please sign in to comment.