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 @@ -927,7 +927,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
927
927
* - If a type proxy P is not a reference to a class, P's supertype is in G
928
928
*/
929
929
def isSubTypeOfParent (subtp : Type , tp : Type )(implicit ctx : Context ): Boolean =
930
- if (subtp <:< tp ) true
930
+ if (constrainPatternType( subtp, tp) ) true
931
931
else tp match {
932
932
case tp : TypeRef if tp.symbol.isClass => isSubTypeOfParent(subtp, tp.firstParent)
933
933
case tp : TypeProxy => isSubTypeOfParent(subtp, tp.superType)
Original file line number Diff line number Diff line change @@ -185,7 +185,7 @@ object Inferencing {
185
185
* Invariant refinement can be assumed if `PatternType`'s class(es) are final or
186
186
* case classes (because of `RefChecks#checkCaseClassInheritanceInvariant`).
187
187
*/
188
- def constrainPatternType (tp : Type , pt : Type )(implicit ctx : Context ) = {
188
+ def constrainPatternType (tp : Type , pt : Type )(implicit ctx : Context ): Boolean = {
189
189
def refinementIsInvariant (tp : Type ): Boolean = tp match {
190
190
case tp : ClassInfo => tp.cls.is(Final ) || tp.cls.is(Case )
191
191
case tp : TypeProxy => refinementIsInvariant(tp.underlying)
@@ -206,7 +206,7 @@ object Inferencing {
206
206
}
207
207
208
208
val widePt = if (ctx.scala2Mode || refinementIsInvariant(tp)) pt else widenVariantParams(pt)
209
- ( tp <:< widePt)(ctx.addMode( Mode . GADTflexible ))
209
+ tp <:< widePt
210
210
}
211
211
212
212
/** The list of uninstantiated type variables bound by some prefix of type `T` which
Original file line number Diff line number Diff line change @@ -568,7 +568,7 @@ class Typer extends Namer
568
568
def typedTpt = checkSimpleKinded(typedType(tree.tpt))
569
569
def handlePattern : Tree = {
570
570
val tpt1 = typedTpt
571
- if (! ctx.isAfterTyper) constrainPatternType(tpt1.tpe, pt)
571
+ if (! ctx.isAfterTyper) constrainPatternType(tpt1.tpe, pt)(ctx.addMode( Mode . GADTflexible ))
572
572
// special case for an abstract type that comes with a class tag
573
573
tryWithClassTag(ascription(tpt1, isWildcard = true ), pt)
574
574
}
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