Skip to content

Commit 21ba78c

Browse files
authored
Merge pull request #232 from scala/backport-lts-3.3-22489
Backport "Avoid inf recursion in provablyDisjointClasses" to 3.3 LTS
2 parents 37c9379 + c9fe273 commit 21ba78c

File tree

6 files changed

+50
-6
lines changed

6 files changed

+50
-6
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,11 +2772,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
27722772
*
27732773
* 1. Single inheritance of classes
27742774
* 2. Final classes cannot be extended
2775-
* 3. ConstantTypes with distinct values are non intersecting
2776-
* 4. TermRefs with distinct values are non intersecting
2775+
* 3. ConstantTypes with distinct values are non-intersecting
2776+
* 4. TermRefs with distinct values are non-intersecting
27772777
* 5. There is no value of type Nothing
27782778
*
2779-
* Note on soundness: the correctness of match types relies on on the
2779+
* Note on soundness: the correctness of match types relies on the
27802780
* property that in all possible contexts, the same match type expression
27812781
* is either stuck or reduces to the same case.
27822782
*/

docs/_spec/03-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ The following properties hold about ´⌈X⌉´ (we have paper proofs for those)
10711071
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´".
10721072
That rule is known to break transitivy of subtyping in Scala already.
10731073

1074-
Second, we define the relation ´⋔´ on *classes* (including traits and hidden classes of objects) as:
1074+
Second, we define the relation ´⋔´ on *classes* (including traits, hidden classes of objects, and enum terms) as:
10751075

10761076
- ´C ⋔ D´ if `´C ∉´ baseClasses´(D)´` and ´D´ is `final`
10771077
- ´C ⋔ D´ if `´D ∉´ baseClasses´(C)´` and ´C´ is `final`

tests/pos/i22266.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
sealed trait NonPolygon
2+
sealed trait Polygon
3+
4+
sealed trait SymmetryAspect
5+
sealed trait RotationalSymmetry extends SymmetryAspect
6+
sealed trait MaybeRotationalSymmetry extends SymmetryAspect
7+
8+
enum Shape:
9+
case Circle extends Shape with NonPolygon with RotationalSymmetry
10+
case Triangle extends Shape with Polygon with MaybeRotationalSymmetry
11+
case Square extends Shape with Polygon with RotationalSymmetry
12+
13+
object Shape:
14+
15+
def hasPolygon(
16+
rotationalSyms: Vector[Shape & RotationalSymmetry],
17+
maybeSyms: Vector[Shape & MaybeRotationalSymmetry]
18+
): Boolean =
19+
val all = rotationalSyms.concat(maybeSyms)
20+
all.exists:
21+
case _: Polygon => true
22+
case _ => false

tests/pos/i22266.unenum.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
sealed trait NonPolygon
2+
sealed trait Polygon
3+
4+
sealed trait SymmetryAspect
5+
sealed trait RotationalSymmetry extends SymmetryAspect
6+
sealed trait MaybeRotationalSymmetry extends SymmetryAspect
7+
8+
sealed abstract class Shape
9+
10+
object Shape:
11+
case object Circle extends Shape with NonPolygon with RotationalSymmetry
12+
case object Triangle extends Shape with Polygon with MaybeRotationalSymmetry
13+
case object Square extends Shape with Polygon with RotationalSymmetry
14+
15+
def hasPolygon(
16+
rotationalSyms: Vector[Shape & RotationalSymmetry],
17+
maybeSyms: Vector[Shape & MaybeRotationalSymmetry]
18+
): Boolean =
19+
val all = rotationalSyms.concat(maybeSyms)
20+
all.exists:
21+
case _: Polygon => true
22+
case _ => false

tests/warn/ext-override.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ trait Foo[T]:
77
class Bla:
88
def hi: String = "hi"
99
object Bla:
10-
given Foo[Bla]:
10+
given Foo[Bla] with
1111
extension (x: Bla)
1212
def hi: String = x.hi

tests/warn/i21860.unenum.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sealed trait Corners { self: Figure => }
33

44
sealed abstract class Shape extends Figure
55
object Shape:
6-
case object Triange extends Shape with Corners
6+
case object Triangle extends Shape with Corners
77
case object Square extends Shape with Corners
88
case object Circle extends Shape
99
case object Ellipsis extends Shape

0 commit comments

Comments
 (0)