Skip to content

Commit

Permalink
Fix error when searching method on "include Enumerable"
Browse files Browse the repository at this point in the history
  • Loading branch information
mame committed Aug 9, 2024
1 parent 4d39783 commit d4268c5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/typeprof/core/graph/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,8 @@ def resolve_included_modules(genv, changes, base_ty_env, ty, mid, &blk)
if inc_decl.is_a?(AST::SigIncludeNode) && inc_mod.type_params
inc_ty = genv.get_instance_type(inc_mod, inc_decl.args, changes, base_ty_env, ty)
else
inc_ty = Type::Instance.new(genv, inc_mod, [])
type_params = inc_mod.type_params.map {|ty_param| Source.new() } # TODO: better support
inc_ty = Type::Instance.new(genv, inc_mod, type_params)
end

me = inc_ty.mod.get_method(false, mid)
Expand Down
3 changes: 2 additions & 1 deletion lib/typeprof/core/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def check_match_included_modules(genv, changes, ty, other_ty)
if inc_decl.is_a?(AST::SigIncludeNode) && inc_mod.type_params
inc_ty = genv.get_instance_type(inc_mod, inc_decl.args, changes, {}, ty)
else
inc_ty = Type::Instance.new(genv, inc_mod, [])
type_params = inc_mod.type_params.map {|ty_param| Source.new() } # TODO: better support
inc_ty = Type::Instance.new(genv, inc_mod, type_params)
end
if inc_ty.mod == other_ty.mod
args_all_match = true
Expand Down
20 changes: 20 additions & 0 deletions scenario/misc/include-enumerable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## update
class Foo
include Enumerable

def foo
ary = []
ary.each do |ary|
add ary
end
end
end

## assert
class Foo
include Enumerable
def foo: -> Array[untyped]
end

## diagnostics
(7,6)-(7,9): undefined method: Foo#add

0 comments on commit d4268c5

Please sign in to comment.