Regression for pattern match over dependant sealed traits #21845
Closed
Description
Based on compilation failure found in OpenCB for sbt/sbt
for version 2.0.0-M2
Compiler version
Introduced in 3.4.0
Backported to 3.3.4
Last good release: 3.4.0-RC1-bin-20231020-89a8fce-NIGHTLY
First bad release: 3.4.0-RC1-bin-20231023-44a537b-NIGHTLY
Bisect points to 2be1b41 however these changes were not backported to LTS.
Bisect on LTS commits only failed to build compiler, but issue could have been introduced in any of: c1dfcef
f87a634
Minimized code
//> using options -Werror
trait Init[ScopeType]:
sealed trait Initialize[A1]
final class Bind[S, A1](val f: S => Initialize[A1], val in: Initialize[S])
extends Initialize[A1]
final class Value[A1](val value: () => A1) extends Initialize[A1]
final class ValidationCapture[A1](val key: ScopedKey[A1], val selfRefOk: Boolean)
extends Initialize[ScopedKey[A1]]
final class TransformCapture(val f: [x] => Initialize[x] => Initialize[x])
extends Initialize[[x] => Initialize[x] => Initialize[x]]
final class Optional[S, A1](val a: Option[Initialize[S]], val f: Option[S] => A1)
extends Initialize[A1]
object StaticScopes extends Initialize[Set[ScopeType]]
sealed trait Keyed[S, A1] extends Initialize[A1]
trait KeyedInitialize[A1] extends Keyed[A1, A1]
sealed case class ScopedKey[A](scope: ScopeType, key: AttributeKey[A]) extends KeyedInitialize[A]
sealed trait AttributeKey[A]
abstract class EvaluateSettings[ScopeType]:
protected val init: Init[ScopeType]
import init._
val transform: [A] => Initialize[A] => Unit = [A] =>
(fa: Initialize[A]) =>
fa match
case k: Keyed[s, A] => ???
case b: Bind[s, A] => ???
case v: Value[A] => ???
case v: ValidationCapture[a] => ??? // unrearchable warning
case t: TransformCapture => ??? // unrearchable warning
case o: Optional[s, A] => ??? // unrearchable warning
case StaticScopes => ??? // unrearchable warning
Output
-- [E029] Pattern Match Exhaustivity Warning: /Users/wmazur/projects/sandbox/test.scala:26:10 --------------------------------------------------------------------------------------------------------------
26 | fa match
| ^^
| match may not be exhaustive.
|
| It would fail on pattern case: _: (Init[<?>] & (EvaluateSettings#init : Init[EvaluateSettings#ScopeType]))#TransformCapture
|
| longer explanation available when compiling with `-explain`
-- [E030] Match case Unreachable Warning: /Users/wmazur/projects/sandbox/test.scala:30:17 ------------------------------------------------------------------------------------------------------------------
30 | case v: ValidationCapture[a] => ??? // warn
| ^^^^^^^^^^^^^^^^^^^^^^^
| Unreachable case
-- [E030] Match case Unreachable Warning: /Users/wmazur/projects/sandbox/test.scala:31:17 ------------------------------------------------------------------------------------------------------------------
31 | case t: TransformCapture => ??? // warn
| ^^^^^^^^^^^^^^^^^^^
| Unreachable case
-- [E030] Match case Unreachable Warning: /Users/wmazur/projects/sandbox/test.scala:32:17 ------------------------------------------------------------------------------------------------------------------
32 | case o: Optional[s, A] => ??? // warn
| ^^^^^^^^^^^^^^^^^
| Unreachable case
-- [E030] Match case Unreachable Warning: /Users/wmazur/projects/sandbox/test.scala:33:17 ------------------------------------------------------------------------------------------------------------------
33 | case StaticScopes => ??? // warn
| ^^^^^^^^^^^^
| Unreachable case
No warnings can be incurred under -Werror (or -Xfatal-warnings)
Expectation
Should not warn about unreachable cases or being non-exhaustive