Skip to content

Commit 22233f4

Browse files
committed
Merge pull request scala#4038 from adriaanm/t8894
SI-8894 dealias when looking at tuple components
2 parents 19d1c81 + ff051e2 commit 22233f4

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/compiler/scala/tools/nsc/transform/patmat/MatchAnalysis.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ trait TreeAndTypeAnalysis extends Debugging {
172172
// a type is "uncheckable" (for exhaustivity) if we don't statically know its subtypes (i.e., it's unsealed)
173173
// we consider tuple types with at least one component of a checkable type as a checkable type
174174
def uncheckableType(tp: Type): Boolean = {
175-
def tupleComponents(tp: Type) = tp.normalize.typeArgs
176175
val checkable = (
177176
(isTupleType(tp) && tupleComponents(tp).exists(tp => !uncheckableType(tp)))
178177
|| enumerateSubtypes(tp).nonEmpty)

src/reflect/scala/reflect/internal/Definitions.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ trait Definitions extends api.StandardDefinitions {
653653
// tends to change the course of events by forcing types.
654654
def isFunctionType(tp: Type) = isFunctionTypeDirect(tp.dealiasWiden)
655655
def isTupleType(tp: Type) = isTupleTypeDirect(tp.dealiasWiden)
656+
def tupleComponents(tp: Type) = tp.dealiasWiden.typeArgs
656657

657658
lazy val ProductRootClass: ClassSymbol = requiredClass[scala.Product]
658659
def Product_productArity = getMemberMethod(ProductRootClass, nme.productArity)
@@ -837,7 +838,7 @@ trait Definitions extends api.StandardDefinitions {
837838
def typeOfMemberNamedApply(tp: Type) = typeArgOfBaseTypeOr(tp, SeqClass)(resultOfMatchingMethod(tp, nme.apply)(IntTpe))
838839
def typeOfMemberNamedDrop(tp: Type) = typeArgOfBaseTypeOr(tp, SeqClass)(resultOfMatchingMethod(tp, nme.drop)(IntTpe))
839840
def typesOfSelectors(tp: Type) =
840-
if (isTupleType(tp)) tp.typeArgs
841+
if (isTupleType(tp)) tupleComponents(tp)
841842
else getterMemberTypes(tp, productSelectors(tp))
842843

843844
// SI-8128 Still using the type argument of the base type at Seq/Option if this is an old-style (2.10 compatible)

test/files/pos/t8894.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class CC(val i: Int, val s: String)
2+
object CC extends {
3+
type P = (Int, String)
4+
5+
//def unapply(c: CC): Option[(Int, String)] = Some((c.i, c.s)) // OK
6+
def unapply(c: CC): Option[P] = Some((c.i, c.s)) // fails (because of the type alias)
7+
}
8+
9+
class Test {
10+
val cc = new CC(23, "foo")
11+
val CC(i, s) = cc
12+
}

0 commit comments

Comments
 (0)