Skip to content

Fix parents of tuple classes #13659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1620,11 +1620,11 @@ class Definitions {

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

/** If it is BoxedUnit, remove `java.io.Serializable` from `parents`. */
Expand Down Expand Up @@ -1777,6 +1777,7 @@ class Definitions {
.updated(SingletonClass, ObjectClass)
.updated(TupleClass, ProductClass)
.updated(NonEmptyTupleClass, ProductClass)
.updated(PairClass, ObjectClass)

// ----- Initialization ---------------------------------------------------

Expand Down
12 changes: 12 additions & 0 deletions tests/neg/i13435.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- [E029] Pattern Match Exhaustivity Warning: tests/neg/i13435.scala:7:2 -----------------------------------------------
7 | s match
| ^
| match may not be exhaustive.
|
| It would fail on pattern case: (_), ((_, _), (_, _))

longer explanation available when compiling with `-explain`
-- Error: tests/neg/i13435.scala:8:10 ----------------------------------------------------------------------------------
8 | case (dim: Axis, size: Int) => dim // error
| ^^^^^^^^^
| trait Singleton cannot be used in runtime type tests
8 changes: 8 additions & 0 deletions tests/neg/i13435.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type Axis = String&Singleton
type ShapeTuple = Tuple1[(Axis, Int)]|Tuple2[(Axis, Int), (Axis, Int)]
type Shape = (Axis, Int) |ShapeTuple


def mkSchema(s: Shape) =
s match
case (dim: Axis, size: Int) => dim // error