From b806a743354e5dd1d1ffb7a6e8bd4b6e9ddbe11b Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 1 Nov 2024 13:35:11 +0000 Subject: [PATCH 1/2] Fix provablyDisjoint handling enum constants with mixins --- .../dotty/tools/dotc/core/TypeComparer.scala | 2 +- tests/warn/i21860.scala | 16 ++++++++++++++++ tests/warn/i21860.unenum.scala | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/warn/i21860.scala create mode 100644 tests/warn/i21860.unenum.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 1c62c4a3d029..402e1f773b7e 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -3110,7 +3110,7 @@ object TypeComparer { def explaining[T](op: ExplainingTypeComparer => T, short: Boolean = false)(using Context): T = comparing(_.explaining(op, short)) - + def tracked[T](op: TrackingTypeComparer => T)(using Context): T = comparing(_.tracked(op)) } diff --git a/tests/warn/i21860.scala b/tests/warn/i21860.scala new file mode 100644 index 000000000000..377d4761e80f --- /dev/null +++ b/tests/warn/i21860.scala @@ -0,0 +1,16 @@ +trait Figure +sealed trait Corners { self: Figure => } + +enum Shape extends Figure: + case Triangle extends Shape with Corners + case Square extends Shape with Corners + case Circle extends Shape + case Ellipsis extends Shape + +def hasCorners(s: Shape): Boolean = s match + case hasCorners: Corners => true // <--- reported as `Unreachable case` + case _ => false + +class Test: + def test(): Unit = + println(hasCorners(Shape.Circle)) diff --git a/tests/warn/i21860.unenum.scala b/tests/warn/i21860.unenum.scala new file mode 100644 index 000000000000..7335e1b6851d --- /dev/null +++ b/tests/warn/i21860.unenum.scala @@ -0,0 +1,17 @@ +trait Figure +sealed trait Corners { self: Figure => } + +sealed abstract class Shape extends Figure +object Shape: + case object Triange extends Shape with Corners + case object Square extends Shape with Corners + case object Circle extends Shape + case object Ellipsis extends Shape + +def hasCorners(s: Shape): Boolean = s match + case hasCorners: Corners => true // <--- reported as `Unreachable case` + case _ => false + +class Test: + def test(): Unit = + println(hasCorners(Shape.Circle)) From 4895a183a2522edab241611ea899fd2be9b36cab Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Fri, 14 Feb 2025 17:50:38 +0100 Subject: [PATCH 2/2] Fix provablyDisjoint handling enum constants with mixins [Cherry-picked 19c945b9d938ed62073d8373c18e7acfef8ab2d7][modified]