Closed
Description
Minimized code
case class More(); case class Stop();
sealed abstract class DSL
case class Fun[F <: More|Stop => DSL](cont: F) extends DSL
case class Nop() extends DSL
type Match2[X <: More|Stop] <: DSL = X match {
case More => Fun[(y: More|Stop) => Match1[y.type]]
case Stop => Nop
}
type Match1[X] <: DSL = X match {
case More => Nop
case Stop => Nop
}
def fun2(x: More|Stop): Match2[x.type] = x match {
case _: More => Fun(fun1)
case _: Stop => Nop()
}
def fun1(y: More|Stop): Match1[y.type] = y match {
case _: More => Nop()
case _: Stop => Nop()
}
Output
[error] -- [E043] Type Error: MatchTypes.scala:19:1
[error] 19 |}
[error] | ^
[error] |unreducible application of higher-kinded type Match1 to wildcard arguments in subpart Match1[? <: More | Stop] of inferred type
[error] | (x : More | Stop) match {
[error] | case More => Fun[(y: More | Stop) => Match1[y.type]]
[error] | case Stop => Nop
[error] | } <: DSL
[error] |
[error] one error found
Expectation
Type-checking should succeed.
Notes
-
The error arises whenever I try to nest 2+ levels of dependent function types + match types
-
Indeed, if
fun2()
is commented out, then the type-checking offun1()
succeeds -
The whole code above appears to type-check correctly when using VS Code with the Dotty extension:
- the types reported by the IDE appear correct
- if one tries to replace
Fun(fun1)
withNop()
infun2()
, the resulting error message correctly reports the expected type - if the body of
fun1()
is inlined infun2()
, its type is correctly inferred and type-checking succeeds
-
The error is reported by the
PostTyper
compiler phase, which is not executed by the Dotty extension for VS Code