Error Lab
Every diagnostic below is the real output of ptc, not a mock-up. Pick a mistake, read how the compiler teaches the canonical form, then flip to the fix.
Option covers both worlds
Handling Some without None is exactly how null bugs are born elsewhere. Here the incomplete match never compiles.
let opt: Option[Int] = Some(1)
match opt:
case Some(n):
print("{n}")The compiler answers
error: this match on Option[Int] is not exhaustive — cover both 'case Some(...):' and 'case None:' or finish with a 'case _:' arm (line 2, column 1)let opt: Option[Int] = Some(1)
match opt:
case Some(n):
print("{n}")
case None:
print("none")Fixed — and it runs
1