-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
SAM types don't support type bounds #2732
Comments
@adriaanm Does scalac do something special in its handling of SAMs to deal with types like |
No, but see scala/scala-dev#184, scala/bug#9756 and https://yanniss.github.io/varj-ecoop12.pdf |
We may have accumulated some more special-casing for existentials and type inference over the years, but I can't think of us doing anything specific to SAMs. This type checks too: |
But interestingly, this doesn't typecheck in either scalac or dotty: scala> def foo: ({type T <: String})#T = "a"
<console>:11: error: type mismatch;
found : String("a")
required: AnyRef{type T <: String}#T
def foo: ({type T <: String})#T = "a"
^ |
Yeah, I think it's because the existential is extrapolated to its upper bound because it appears in a covariant position. |
The `isInstantiable` test as written is incorrect: Given tp = `java.util.function.Function[String, _ <: String]`, we will have: tref = skolem TermRef with underlying info `tp` selfType = java.util.function.Function[tref#T, tref#R]` (because of the `asSeenFrom`) `tref <:< selfType` is false, because `tref.underlying` is just `tp` and its parameters are bounded wildcards, not references with `tref` as a prefix. In any case, I cannot think of a case where this function should return false, and no test failed when I removed it. So I'm removing it until someone can come up with a counter-example.
The `isInstantiable` test as written is incorrect: Given tp = `java.util.function.Function[String, _ <: String]`, we will have: tref = skolem TermRef with underlying info `tp` selfType = `java.util.function.Function[tref#T, tref#R]` (because of the `asSeenFrom`) `tref <:< selfType` is false, because `tref.underlying` is just `tp` and its parameters are bounded wildcards, not references with `tref` as a prefix. In any case, I cannot think of a case where this function should return false, and no test failed when I removed it. So I'm removing it until someone can come up with a counter-example.
The `isInstantiable` test as written is incorrect: Given tp = `java.util.function.Function[String, _ <: String]`, we will have: tref = skolem TermRef with underlying info `tp` selfType = `java.util.function.Function[String, tref#R]` (because of the `asSeenFrom`) `tref <:< selfType` is false, because `tref.underlying` is just `tp` and its return type parameter is a bounded wildcard, not a reference with `tref` as a prefix. In any case, I cannot think of a case where this function should return false, and no test failed when I removed it. So I'm removing it until someone can come up with a counter-example.
Fix #2732: Allow wildcards in SAM types (take 2)
The following compiles in Scala but fails in Dotty (using Scastie)
trying
still results in the second error
The text was updated successfully, but these errors were encountered: