Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/typeprof/core/graph/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def resolve_overload(changes, genv, method_type, node, param_map, a_args, ret, f
end
return false
end

if rbs_blk && a_args.block
# rbs_blk_func.optional_keywords, ...
blk_a_args = rbs_blk.req_positionals.map do |blk_a_arg|
Expand Down Expand Up @@ -251,6 +252,20 @@ def resolve_overloads(changes, genv, node, param_map, a_args, ret, &blk)
return
end

# If any positional argument has no type information, we cannot
# determine which overload to select. Return silently (untyped)
# rather than attempting to match. This prevents oscillation in
# cyclic cases like @x = Foo.transform(@x), and avoids false
# "failed to resolve overloads" diagnostics for untyped arguments.
# We still set up dependency edges so the box re-runs when the
# empty arguments later receive types.
if a_args.positionals.any? {|vtx| vtx.types.empty? }
a_args.positionals.each do |vtx|
changes.add_edge(genv, vtx, changes.target)
end
return
end

match_any_overload = false
@method_types.each do |method_type|
if resolve_overload(changes, genv, method_type, node, param_map, a_args, ret, false, &blk)
Expand Down
2 changes: 1 addition & 1 deletion scenario/rbs/untyped-for-overload-record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ def check(unknown)

## assert
class Object
def check: (untyped) -> (:record | :str)
def check: (untyped) -> untyped
end
2 changes: 1 addition & 1 deletion scenario/rbs/untyped-for-overload-singleton.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ def check(unknown)

## assert
class Object
def check: (untyped) -> (:int | :str)
def check: (untyped) -> untyped
end
2 changes: 1 addition & 1 deletion scenario/rbs/untyped-for-overload-tuple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ def check(unknown)

## assert
class Object
def check: (untyped) -> (:str | :tuple)
def check: (untyped) -> untyped
end
2 changes: 1 addition & 1 deletion scenario/rbs/untyped-for-overload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ def check

## assert
class Object
def check: -> (:A | :B)
def check: -> untyped
end
18 changes: 18 additions & 0 deletions scenario/regressions/avoid-infinite-loop-overload-chain.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## update: test.rbs
class Foo
def self.transform: (Integer) -> String
| (String) -> Float
| (Float) -> Symbol
end

## update: test.rb
def check
@x = Foo.transform(@x)
end

## diagnostics: test.rb

## assert
class Object
def check: -> untyped
end
17 changes: 17 additions & 0 deletions scenario/regressions/avoid-infinite-loop-overload-disjoint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## update: test.rbs
class Foo
def self.transform: (Integer) -> Float
| (String) -> Symbol
end

## update: test.rb
def check
@x = Foo.transform(@x)
end

## diagnostics: test.rb

## assert
class Object
def check: -> untyped
end
17 changes: 17 additions & 0 deletions scenario/regressions/avoid-infinite-loop-overload-partial.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## update: test.rbs
class Foo
def self.transform: (Integer) -> String
| (String) -> Float
end

## update: test.rb
def check
@x = Foo.transform(@x)
end

## diagnostics: test.rb

## assert
class Object
def check: -> untyped
end