scala3
scala3 copied to clipboard
Weird compile-error in Scastie worksheet mode
Compiler version
3.2.0
Minimized code
sealed trait Nat
case class Zero() extends Nat
case class Succ[N <: Nat](n: N) extends Nat
type PredOrZero[N <: Nat] = N match
case Zero => Zero
case Succ[predN] => predN
type PredOrZeroOption[N <: Nat] <: Option[Nat] = N match
case Zero => None.type
case Succ[predN] => Some[predN]
def predOrZeroOption[N <: Nat](n: N): PredOrZeroOption[N] = n match
case Zero(): Zero => None
case Succ(predN): Succ[_] =>Some(predN)
predOrZeroOption(Succ(Zero())) match
case Some(pred) => println("Hi")
Output
Recursive <nonsensical>value $t</nonsensical> needs type
Expectation
The code is expected to compile successfully, similarly to how, when not in worksheet mode, the code does compile (with the last two lines packaged in a main method).