Skip to content

Polymorphic functions variance not working as expected #6918

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

Closed
guyde2011 opened this issue Jul 23, 2019 · 1 comment
Closed

Polymorphic functions variance not working as expected #6918

guyde2011 opened this issue Jul 23, 2019 · 1 comment

Comments

@guyde2011
Copy link

minimized code

val aiPoly: [T] => Any => Int = [T] => (a: Any) => 5
val iiPoly: [T] => Int => Int = aiPoly // <-- this part fails

Does not compile, producing the error:
Found: PolyFunction{apply: [T](x$1: Any): Int}(aiPoly)
Required: PolyFunction{apply: [T](x$1: Int): Int}

expectation

Expected the polymorhpic case to behave the same way as normal functions do:

val ai: Any => Int = (a: Any) => 5
val ii: Int => Int = ai // <-- compiles and works with no errors
@smarter
Copy link
Member

smarter commented Jul 23, 2019

Same root cause as #6357 since dependent and polymorphic function types share a similar encoding, closing this one as a duplicate since I'll either manage to fix both at the same time or none (details of my current plan here: http://guillaume.martres.me/talks/dotty-funs-scala19/)

@smarter smarter closed this as completed Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants