@@ -101,17 +101,24 @@ object Checkable {
101
101
102
102
P1 <:< X // may fail, ignore
103
103
104
- tvars.foreach { case tvar : TypeVar =>
105
- val bounds = ctx.typerState.constraint.entry(tvar.origin)
106
- if (bounds.loBound =:= bounds.hiBound)
107
- tvar.instantiateWith(bounds.loBound)
108
- else if (tycon.classSymbol.is(Final )) // 3324g.scala cannot happen because of final
109
- instantiateSelected(P1 , tvar :: Nil )
110
- else { // see 3324g.scala
111
- val wildCard = ctx.newSymbol(ctx.owner, WildcardParamName .fresh().toTypeName, Case , tvar.origin.underlying, coord = pos)
112
- tvar.instantiateWith(wildCard.typeRef)
104
+ // 3324g.scala cannot happen in such cases
105
+ def canInstantiate =
106
+ tycon.classSymbol.is(Final ) ||
107
+ ! X .classSymbol.is(Trait ) ||
108
+ X .classSymbol.typeParams.isEmpty
109
+
110
+ if (canInstantiate)
111
+ maximizeType(P1 , pos, fromScala2x = true ) // use `fromScala2x = true` to force instantiate invariant tvars
112
+ else
113
+ tvars.foreach { case tvar : TypeVar =>
114
+ val bounds = ctx.typerState.constraint.entry(tvar.origin)
115
+ if (bounds.loBound =:= bounds.hiBound)
116
+ tvar.instantiateWith(bounds.loBound)
117
+ else { // 3324g.scala
118
+ val wildCard = ctx.newSymbol(ctx.owner, WildcardParamName .fresh().toTypeName, Case , tvar.origin.underlying, coord = pos)
119
+ tvar.instantiateWith(wildCard.typeRef)
120
+ }
113
121
}
114
- }
115
122
116
123
val res = P1 <:< P
117
124
debug.println(" P1 : " + P1 )
0 commit comments