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

Add free variables to "no overload matches" errors #10692

Merged

Conversation

HertzDevil
Copy link
Contributor

Adds the forall part to the list of overloads when a call doesn't match any overloads of a def.

This is done because methods with free variables have different overload sets than methods that don't. Additionally, it avoids some confusion when the free variable names are also valid without the forall part. Consider:

class Foo(T)
  def foo(x : T, y : Int32)
  end

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

# okay
Foo(Char).new.foo('x', 'x')
Foo(Char).new.foo('x', 1)
Foo(Char).new.foo(1, 'x')

# Error: no overload matches 'Foo(Char)#foo' with types Int32, Int32
#
# Overloads are:
#  - Foo(T)#foo(x : T, y : Int32)
#  - Foo(T)#foo(x : T, y : Char)
Foo(Char).new.foo(1, 1)

This PR changes the overload list to:

# Overloads are:
#  - Foo(T)#foo(x : T, y : Int32)
#  - Foo(T)#foo(x : T, y : Char) forall T

This makes it clear that the T in the Char overload's type restriction shadows the generic type parameter. A similar case can be made when T shadows a normal type name instead.

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels May 8, 2021
@asterite asterite merged commit e3ba8c6 into crystal-lang:master May 9, 2021
@asterite asterite added this to the 1.1.0 milestone May 9, 2021
@HertzDevil HertzDevil deleted the bug/error-overload-free-vars branch May 11, 2021 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants