Open m8nmueller opened 4 months ago
This also happens with paths instead of match types
//> using scala 3.6.0-RC1-bin-SNAPSHOT
trait P:
type Q
trait PString extends P:
type Q = String
trait User[X <: P]:
def get(x: X): x.Q
def use(f: (x: X) => x.Q => String): String
class StringUser extends User[PString]:
def get(x: PString): x.Q = ???
def use(f: (x: PString) => x.Q => String): String = ???
I suspect it's something to do with variance...
//> using scala 3.6.0-RC1-bin-SNAPSHOT
trait P:
type Q
trait PString extends P:
type Q = String
type F[X <: P] = (x: X) => x.Q => String
val u = summon[F[PString] <:< ((x: PString) => x.Q => String)]
The compiler cannot prove this
Being invariant is enough:
type Inv[X]
type F[X <: P] = (x: X) => Inv[x.Q]
val v0: F[PString] = ???
val v2: (x: PString) => Inv[x.Q] = v0 // error
Compiler version
3.4.2
Minimized code
Output
Expectation
The compiler should realize that the two function types are exactly the result of replacing the type parameter X with the type
PString
, as it does for the non-function type inget
.