Consider the following snippet:
object Test extends App {
class X {
class Y
}
class Z(val x: X) {
val y: x.Y = new x.Y
}
val x: X = new X
val z: Z = new Z(x)
val y: x.Y = z.y
println(y)
}
This code won't compile, complaing about incompatible path-dependent types:
[error] 12 | val y: x.Y = z.y
[error] | ^^^
[error] | Found: (Test.z.y : Test.z.x.Y)
[error] | Required: Test.x².Y
[error] |
[error] | where: x is a value in class Z
[error] | x² is a value in object Test
[error] |
Is there a way to gently remind the compiler that z.x
is assigned to x
just one line above?
Even if (z.x == x) { val y: x.Y = z.y }
does not solve the issue, even though path equivalence should be inferred from control flow.
Background: Scala 3 macro API heavily uses PDT's, and this creates huge amount of pain to deal with --- all this pain is coming from compiler's inability to infer anything, and lack of syntactic structures to explicitly control that inference.