From 80fdbb882a7dce7f5bf1c8f8924154dba3c58dab Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 31 Jan 2025 14:18:56 +0000 Subject: [PATCH 1/6] Avoid inf recursion in provablyDisjointClasses --- tests/pos/i22266.scala | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/pos/i22266.scala diff --git a/tests/pos/i22266.scala b/tests/pos/i22266.scala new file mode 100644 index 000000000000..2ecdf9492a93 --- /dev/null +++ b/tests/pos/i22266.scala @@ -0,0 +1,22 @@ +sealed trait NonPolygon +sealed trait Polygon + +sealed trait SymmetryAspect +sealed trait RotationalSymmetry extends SymmetryAspect +sealed trait MaybeRotationalSymmetry extends SymmetryAspect + +enum Shape: + case Circle extends Shape with NonPolygon with RotationalSymmetry + case Triangle extends Shape with Polygon with MaybeRotationalSymmetry + case Square extends Shape with Polygon with RotationalSymmetry + +object Shape: + + def hasPolygon( + rotationalSyms: Vector[Shape & RotationalSymmetry], + maybeSyms: Vector[Shape & MaybeRotationalSymmetry] + ): Boolean = + val all = rotationalSyms.concat(maybeSyms) + all.exists: + case _: Polygon => true + case _ => false From 0adb4871211b70a87e11022047c4d427a2b36ad8 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 21 Apr 2025 14:10:23 +0200 Subject: [PATCH 2/6] Avoid inf recursion in provablyDisjointClasses [Cherry-picked 3cd94b4049d84d32464d695c753e1b1770a34c89][modified] From 596c11fa7a1eb2f3d7fb61d81348ec7502a7dab6 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 31 Jan 2025 15:19:02 +0000 Subject: [PATCH 3/6] Avoid early widening enum val symbols in provablyDisjointClasses --- tests/pos/i22266.unenum.scala | 22 ++++++++++++++++++++++ tests/warn/ext-override.scala | 2 +- tests/warn/i21860.unenum.scala | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i22266.unenum.scala diff --git a/tests/pos/i22266.unenum.scala b/tests/pos/i22266.unenum.scala new file mode 100644 index 000000000000..e7529b7edabe --- /dev/null +++ b/tests/pos/i22266.unenum.scala @@ -0,0 +1,22 @@ +sealed trait NonPolygon +sealed trait Polygon + +sealed trait SymmetryAspect +sealed trait RotationalSymmetry extends SymmetryAspect +sealed trait MaybeRotationalSymmetry extends SymmetryAspect + +sealed abstract class Shape + +object Shape: + case object Circle extends Shape with NonPolygon with RotationalSymmetry + case object Triangle extends Shape with Polygon with MaybeRotationalSymmetry + case object Square extends Shape with Polygon with RotationalSymmetry + + def hasPolygon( + rotationalSyms: Vector[Shape & RotationalSymmetry], + maybeSyms: Vector[Shape & MaybeRotationalSymmetry] + ): Boolean = + val all = rotationalSyms.concat(maybeSyms) + all.exists: + case _: Polygon => true + case _ => false diff --git a/tests/warn/ext-override.scala b/tests/warn/ext-override.scala index 7c082695cbaa..d08439e13c9a 100644 --- a/tests/warn/ext-override.scala +++ b/tests/warn/ext-override.scala @@ -7,6 +7,6 @@ trait Foo[T]: class Bla: def hi: String = "hi" object Bla: - given Foo[Bla]: + given Foo[Bla] with extension (x: Bla) def hi: String = x.hi diff --git a/tests/warn/i21860.unenum.scala b/tests/warn/i21860.unenum.scala index 7335e1b6851d..e4b282e35e76 100644 --- a/tests/warn/i21860.unenum.scala +++ b/tests/warn/i21860.unenum.scala @@ -3,7 +3,7 @@ sealed trait Corners { self: Figure => } sealed abstract class Shape extends Figure object Shape: - case object Triange extends Shape with Corners + case object Triangle extends Shape with Corners case object Square extends Shape with Corners case object Circle extends Shape case object Ellipsis extends Shape From 6b2eca34c1978cc9fa53ead7c8f4f868148a5455 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 21 Apr 2025 14:14:44 +0200 Subject: [PATCH 4/6] Avoid early widening enum val symbols in provablyDisjointClasses [Cherry-picked 04f6fc3893404bfc8c87395d2daa5601b7672fe9][modified] From 04e9c0a4f1dfbcecec15570b91604d58560f8d98 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 3 Feb 2025 11:40:29 +0000 Subject: [PATCH 5/6] Document enum value changes in provablyDisjointClasses --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 6 +++--- docs/_spec/03-types.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 5e0d9a98aa74..48274e0561ef 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -2772,11 +2772,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling * * 1. Single inheritance of classes * 2. Final classes cannot be extended - * 3. ConstantTypes with distinct values are non intersecting - * 4. TermRefs with distinct values are non intersecting + * 3. ConstantTypes with distinct values are non-intersecting + * 4. TermRefs with distinct values are non-intersecting * 5. There is no value of type Nothing * - * Note on soundness: the correctness of match types relies on on the + * Note on soundness: the correctness of match types relies on the * property that in all possible contexts, the same match type expression * is either stuck or reduces to the same case. */ diff --git a/docs/_spec/03-types.md b/docs/_spec/03-types.md index 4b1293258495..5d4e205aace9 100644 --- a/docs/_spec/03-types.md +++ b/docs/_spec/03-types.md @@ -1071,7 +1071,7 @@ The following properties hold about ´⌈X⌉´ (we have paper proofs for those) The "lower-bound rule" states that ´S <: T´ if ´T = q.X´ and ´q.X´ is a non-class type designator and ´S <: L´ where ´L´ is the lower bound of the underlying type definition of ´q.X´". That rule is known to break transitivy of subtyping in Scala already. -Second, we define the relation ´⋔´ on *classes* (including traits and hidden classes of objects) as: +Second, we define the relation ´⋔´ on *classes* (including traits, hidden classes of objects, and enum terms) as: - ´C ⋔ D´ if `´C ∉´ baseClasses´(D)´` and ´D´ is `final` - ´C ⋔ D´ if `´D ∉´ baseClasses´(C)´` and ´C´ is `final` From c9fe273dc603e343133997ff5a67c5a0bc365955 Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Mon, 21 Apr 2025 14:15:07 +0200 Subject: [PATCH 6/6] Document enum value changes in provablyDisjointClasses [Cherry-picked 4cd2a97a1c74a1eb3408e128fa4166eb1d0899f7][modified]