Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset free vars before attempting each overload match #10271

Merged
merged 2 commits into from
Jan 19, 2021
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
28 changes: 28 additions & 0 deletions spec/compiler/semantic/def_overload_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -960,4 +960,32 @@ describe "Semantic: def overload" do
do_something value: 7.as(Int32 | Char)
)) { union_of float64, bool }
end

it "resets free vars after a partial match is rejected (#10270)" do
assert_type(%(
def foo(x : T, y : String) forall T
1
end

def foo(x : Char, y : T) forall T
true
end

foo('a', 1)
)) { bool }
end

it "resets free vars after a partial match is rejected (2) (#10185)" do
assert_type(%(
def foo(*x : *T) forall T
T
end

def foo(**x : **T) forall T
T
end

foo(**{a: 1, b: ""})
)) { named_tuple_of({a: int32, b: string}).metaclass }
end
end
2 changes: 2 additions & 0 deletions src/compiler/crystal/semantic/method_lookup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ module Crystal
macro_owner = item.def.macro_owner?
context.defining_type = macro_owner if macro_owner
context.def_free_vars = item.def.free_vars
context.free_vars.try &.clear

match = signature.match(item, context)

Expand All @@ -143,6 +144,7 @@ module Crystal
else
context.defining_type = path_lookup if macro_owner
context.def_free_vars = nil
context.free_vars.try &.clear
end
end

Expand Down