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

Scalac does not check type equality for existential types #9899

Closed
scabug opened this issue Aug 23, 2016 · 5 comments
Closed

Scalac does not check type equality for existential types #9899

scabug opened this issue Aug 23, 2016 · 5 comments

Comments

@scabug
Copy link

scabug commented Aug 23, 2016

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_77).
Type in expressions for evaluation. Or try :help.

scala> import language.existentials
import language.existentials

scala> val pair: (A => String, A) forSome { type A } = ( { a: Int => a.toString }, 19 )
pair: (A => String, A) forSome { type A } = (<function1>,19)

scala> pair._1(pair._2)
<console>:13: error: type mismatch;
 found   : pair._2.type (with underlying type A)
 required: A
       pair._1(pair._2)
                    ^
@scabug
Copy link
Author

scabug commented Aug 23, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9899?orig=1
Reporter: @Atry
Affected Versions: 2.11.8

@scabug
Copy link
Author

scabug commented Aug 23, 2016

@SethTisue said:
I think this is working as designed as per SLS 6.1: "The following skolemization rule is applied universally for every expression: If the type of an expression would be an existential type T, then the type of the expression is assumed instead to be a skolemization of T." pair._1 and pair._2 get two different skolems which then don't match.

You can pattern match instead; this compiles:

pair match { case (f, x) => f(x) }

You might also be interested in http://stackoverflow.com/a/39061519/86485 which is similar.

@scabug scabug closed this as completed Aug 23, 2016
@scabug
Copy link
Author

scabug commented Aug 23, 2016

@SethTisue said:
Closing as "Not a bug" rather than leaving it open as a feature request, because it's not clear exactly what the feature would be or how it would work.

@scabug
Copy link
Author

scabug commented Aug 23, 2016

@SethTisue said:
Note that this compiles as well:

def applyPair[A](p: (A => String, A)) = p._1(p._2)
applyPair(pair)

so pattern-matching isn't the only workaround.

@scabug
Copy link
Author

scabug commented Aug 23, 2016

@adriaanm said:
Seth & I pulled on this thread a bit, and it turns out it revealed a different bug in the type checker, tracked as #12208

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

1 participant