Skip to content

Commit aefb2b3

Browse files
authored
Merge pull request #14766 from dotty-staging/fix-14693
Drop special treatment for Scala-2 code in unapply
2 parents a9e0e2e + 50c6464 commit aefb2b3

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ object TypeOps:
827827
}
828828

829829
def instantiate(): Type = {
830-
maximizeType(protoTp1, NoSpan, fromScala2x = false)
830+
maximizeType(protoTp1, NoSpan)
831831
wildApprox(protoTp1)
832832
}
833833

compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ object TypeTestsCasts {
109109
// which conform to the skeleton pre.F[_] and X. Then we have to make
110110
// sure all of them are actually of the type P, which implies that the
111111
// type arguments in P are trivial (no runtime check needed).
112-
maximizeType(P1, span, fromScala2x = false)
112+
maximizeType(P1, span)
113113

114114
debug.println("after " + ctx.typerState.constraint.show)
115115

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,8 +1326,6 @@ trait Applications extends Compatibility {
13261326
unapp
13271327
}
13281328

1329-
def fromScala2x = unapplyFn.symbol.exists && (unapplyFn.symbol.owner is Scala2x)
1330-
13311329
unapplyFn.tpe.widen match {
13321330
case mt: MethodType if mt.paramInfos.length == 1 =>
13331331
val unapplyArgType = mt.paramInfos.head
@@ -1343,7 +1341,7 @@ trait Applications extends Compatibility {
13431341
// Constraining only fails if the pattern cannot possibly match,
13441342
// but useless pattern checks detect more such cases, so we simply rely on them instead.
13451343
withMode(Mode.GadtConstraintInference)(TypeComparer.constrainPatternType(unapplyArgType, selType))
1346-
val patternBound = maximizeType(unapplyArgType, tree.span, fromScala2x)
1344+
val patternBound = maximizeType(unapplyArgType, tree.span)
13471345
if (patternBound.nonEmpty) unapplyFn = addBinders(unapplyFn, patternBound)
13481346
unapp.println(i"case 2 $unapplyArgType ${ctx.typerState.constraint}")
13491347
unapplyArgType

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ object Inferencing {
399399
* @return The list of type symbols that were created
400400
* to instantiate undetermined type variables that occur non-variantly
401401
*/
402-
def maximizeType(tp: Type, span: Span, fromScala2x: Boolean)(using Context): List[Symbol] = {
402+
def maximizeType(tp: Type, span: Span)(using Context): List[Symbol] = {
403403
Stats.record("maximizeType")
404404
val vs = variances(tp)
405405
val patternBindings = new mutable.ListBuffer[(Symbol, TypeParamRef)]
@@ -409,7 +409,7 @@ object Inferencing {
409409
else if (v == -1) tvar.instantiate(fromBelow = true)
410410
else {
411411
val bounds = TypeComparer.fullBounds(tvar.origin)
412-
if (bounds.hi <:< bounds.lo || bounds.hi.classSymbol.is(Final) || fromScala2x)
412+
if bounds.hi <:< bounds.lo || bounds.hi.classSymbol.is(Final) then
413413
tvar.instantiate(fromBelow = false)
414414
else {
415415
// We do not add the created symbols to GADT constraint immediately, since they may have inter-dependencies.

tests/run/i14693.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Success!

tests/run/i14693.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
val a: Array[Long] = Array(1L)
3+
4+
def test(x: Any) = x match {
5+
case Array(i: Long) => println("Success!")
6+
case _ => println("Failure!") }
7+
8+
def main(args: Array[String]): Unit = test(a)
9+
}

0 commit comments

Comments
 (0)