Error on type projection C[_]#K
import scala.language.higherKinds
trait B
class C[CC[_] <: B] {
class K
}
object O {
def t1(x: Any): Int = x match {
case _: C[_]#K => 0
}
def t2(x: Any) = x.isInstanceOf[C[_]#K]
}
t1 fails in type checking, only if CC is higher-kinded
A.scala:10: error: type arguments [_] do not conform to class C's type parameter bounds [CC[_] <: B]
case _: C[_]#K => 0
^
t2 fails in parsing
A.scala:12: error: unbound wildcard type
def t2(x: Any) = x.isInstanceOf[C[_]#K]
^
Both work in Scala 3.
Interestingly, t1 compiles with Scala 2.12.14/15, but fails in the same way as 2.13.6 when adding the semanticdb-scalac compiler plugin (🤷♂️).
$> sc12 -Xplugin:/Users/luc/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scalameta/semanticdb-scalac_2.12.15/4.4.28/semanticdb-scalac_2.12.15-4.4.28.jar A.scala
A.scala:10: error: type arguments [_] do not conform to class C's type parameter bounds [CC[_] <: B]
case _: C[_]#K => 0
^
No diff with https://github.com/scala/scala/pull/9712
Also in the same ballpark, works in Scala 3:
scala> class C[CC[_]]
scala> def f: C[_] = null
^
error: _$1 takes no type parameters, expected: 1
Isn't that related to #8039?
very much, thanks @joroKr21. It comes with one of @retronym's wip branches :-) https://github.com/retronym/scala/tree/ticket/8039
@lrytz did you try that patch? I saw that you merged a workaround.
@joroKr21 no, I didn't try the patch...