bug icon indicating copy to clipboard operation
bug copied to clipboard

Error on type projection C[_]#K

Open lrytz opened this issue 4 years ago • 6 comments

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
            ^

lrytz avatar Sep 16 '21 14:09 lrytz

No diff with https://github.com/scala/scala/pull/9712

som-snytt avatar Sep 17 '21 00:09 som-snytt

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

lrytz avatar Sep 17 '21 08:09 lrytz

Isn't that related to #8039?

joroKr21 avatar Sep 17 '21 08:09 joroKr21

very much, thanks @joroKr21. It comes with one of @retronym's wip branches :-) https://github.com/retronym/scala/tree/ticket/8039

lrytz avatar Sep 17 '21 08:09 lrytz

@lrytz did you try that patch? I saw that you merged a workaround.

joroKr21 avatar Sep 25 '21 20:09 joroKr21

@joroKr21 no, I didn't try the patch...

lrytz avatar Sep 27 '21 08:09 lrytz