Pattern matching value s
against a literal does not refine s.type
to that literal
#22887
Labels
s
against a literal does not refine s.type
to that literal
#22887
Compiler version
3.6.3
Minimized code
https://scastie.scala-lang.org/qUB4su3XSgumJBtwnyUgmQ
Output
Expectation
After matching value
s
against"x"
, the typeF[s.type]
offs
should be refined toF["x"]
.Workarounds
Using a GADT instead of union type works, but that's beside the point, as it's not applicable in all situations.
https://scastie.scala-lang.org/tyEprpkaS7mqkg6yj2XA0A
An unsatisfactory and bloated workaround
The following workaround compiles while retaining the original method signature. However, not only is it an overkill, but it also triggers a **false exhaustivity warning**.https://scastie.scala-lang.org/AhV6kSFtR4CVCNPYAgHKgg
The text was updated successfully, but these errors were encountered: