File tree 5 files changed +20
-5
lines changed
compiler/src/dotty/tools/dotc/typer 5 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -933,7 +933,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
933
933
* - If a type proxy P is not a reference to a class, P's supertype is in G
934
934
*/
935
935
def isSubTypeOfParent (subtp : Type , tp : Type )(implicit ctx : Context ): Boolean =
936
- if (subtp <:< tp ) true
936
+ if (constrainPatternType( subtp, tp) ) true
937
937
else tp match {
938
938
case tp : TypeRef if tp.symbol.isClass => isSubTypeOfParent(subtp, tp.firstParent)
939
939
case tp : TypeProxy => isSubTypeOfParent(subtp, tp.superType)
Original file line number Diff line number Diff line change @@ -186,7 +186,7 @@ object Inferencing {
186
186
* Invariant refinement can be assumed if `PatternType`'s class(es) are final or
187
187
* case classes (because of `RefChecks#checkCaseClassInheritanceInvariant`).
188
188
*/
189
- def constrainPatternType (tp : Type , pt : Type )(implicit ctx : Context ) = {
189
+ def constrainPatternType (tp : Type , pt : Type )(implicit ctx : Context ): Boolean = {
190
190
def refinementIsInvariant (tp : Type ): Boolean = tp match {
191
191
case tp : ClassInfo => tp.cls.is(Final ) || tp.cls.is(Case )
192
192
case tp : TypeProxy => refinementIsInvariant(tp.underlying)
@@ -207,7 +207,7 @@ object Inferencing {
207
207
}
208
208
209
209
val widePt = if (ctx.scala2Mode || refinementIsInvariant(tp)) pt else widenVariantParams(pt)
210
- ( tp <:< widePt)(ctx.addMode( Mode . GADTflexible ))
210
+ tp <:< widePt
211
211
}
212
212
213
213
/** The list of uninstantiated type variables bound by some prefix of type `T` which
Original file line number Diff line number Diff line change @@ -569,7 +569,7 @@ class Typer extends Namer
569
569
def typedTpt = checkSimpleKinded(typedType(tree.tpt))
570
570
def handlePattern : Tree = {
571
571
val tpt1 = typedTpt
572
- if (! ctx.isAfterTyper) constrainPatternType(tpt1.tpe, pt)
572
+ if (! ctx.isAfterTyper) constrainPatternType(tpt1.tpe, pt)(ctx.addMode( Mode . GADTflexible ))
573
573
// special case for an abstract type that comes with a class tag
574
574
tryWithClassTag(ascription(tpt1, isWildcard = true ), pt)
575
575
}
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ object Test extends App {
3
3
case class B [+ X ](val x : X ) extends A [X ]
4
4
class C [+ X ](x : Any ) extends B [Any ](x) with A [X ] // error
5
5
def f (a : A [Int ]): Int = a match {
6
- case a : B [_] => a.x
6
+ case B (i) => i
7
7
case _ => 0
8
8
}
9
9
f(new C [Int ](" foo" ))
Original file line number Diff line number Diff line change
1
+ import scala .Option
2
+ object Test extends App {
3
+ trait A [+ X ]
4
+ class B [+ X ](val x : X ) extends A [X ]
5
+ object B {
6
+ def unapply [X ](b : B [X ]): Option [X ] = Some (b.x)
7
+ }
8
+
9
+ class C [+ X ](x : Any ) extends B [Any ](x) with A [X ]
10
+ def f (a : A [Int ]): Int = a match {
11
+ case B (i) => i // error
12
+ case _ => 0
13
+ }
14
+ f(new C [Int ](" foo" ))
15
+ }
You can’t perform that action at this time.
0 commit comments