Skip to content

Commit af2dfe0

Browse files
authored
Merge pull request #13659 from dotty-staging/fix-13435
Fix parents of tuple classes
2 parents eb8773e + eb81076 commit af2dfe0

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,11 +1620,11 @@ class Definitions {
16201620

16211621
/** If `cls` is Tuple1..Tuple22, add the corresponding *: type as last parent to `parents` */
16221622
def adjustForTuple(cls: ClassSymbol, tparams: List[TypeSymbol], parents: List[Type]): List[Type] = {
1623-
def syntheticParent(tparams: List[TypeSymbol]): Type =
1624-
if (tparams.isEmpty) TupleTypeRef
1625-
else TypeOps.nestedPairs(tparams.map(_.typeRef))
1626-
if (isTupleClass(cls)) parents :+ syntheticParent(tparams)
1627-
else parents
1623+
if !isTupleClass(cls) then parents
1624+
else if tparams.isEmpty then parents :+ TupleTypeRef
1625+
else
1626+
assert(parents.head.typeSymbol == ObjectClass)
1627+
TypeOps.nestedPairs(tparams.map(_.typeRef)) :: parents.tail
16281628
}
16291629

16301630
/** If it is BoxedUnit, remove `java.io.Serializable` from `parents`. */
@@ -1777,6 +1777,7 @@ class Definitions {
17771777
.updated(SingletonClass, ObjectClass)
17781778
.updated(TupleClass, ProductClass)
17791779
.updated(NonEmptyTupleClass, ProductClass)
1780+
.updated(PairClass, ObjectClass)
17801781

17811782
// ----- Initialization ---------------------------------------------------
17821783

tests/neg/i13435.check

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- [E029] Pattern Match Exhaustivity Warning: tests/neg/i13435.scala:7:2 -----------------------------------------------
2+
7 | s match
3+
| ^
4+
| match may not be exhaustive.
5+
|
6+
| It would fail on pattern case: (_), ((_, _), (_, _))
7+
8+
longer explanation available when compiling with `-explain`
9+
-- Error: tests/neg/i13435.scala:8:10 ----------------------------------------------------------------------------------
10+
8 | case (dim: Axis, size: Int) => dim // error
11+
| ^^^^^^^^^
12+
| trait Singleton cannot be used in runtime type tests

tests/neg/i13435.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type Axis = String&Singleton
2+
type ShapeTuple = Tuple1[(Axis, Int)]|Tuple2[(Axis, Int), (Axis, Int)]
3+
type Shape = (Axis, Int) |ShapeTuple
4+
5+
6+
def mkSchema(s: Shape) =
7+
s match
8+
case (dim: Axis, size: Int) => dim // error

0 commit comments

Comments
 (0)