File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
compiler/src/dotty/tools/dotc/core Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -308,6 +308,18 @@ trait ConstraintHandling[AbstractContext] {
308
308
widenOr(widenSingle(tp)).dropRepeatedAnnot
309
309
}
310
310
311
+ def widenInferred2 (inst : Type , param : TypeParamRef )(implicit actx : AbstractContext ): Type = {
312
+ def widenSingle (tp : Type ) = {
313
+ val tpw = tp.widen
314
+ if ((tpw ne tp) && tpw <:< param) tpw else tp
315
+ }
316
+ def widenOr (tp : Type ) = {
317
+ val tpw = tp.widenUnion
318
+ if ((tpw ne tp) && tpw <:< param) tpw else tp
319
+ }
320
+ widenOr(widenSingle(inst)).dropRepeatedAnnot
321
+ }
322
+
311
323
/** The instance type of `param` in the current constraint (which contains `param`).
312
324
* If `fromBelow` is true, the instance type is the lub of the parameter's
313
325
* lower bounds; otherwise it is the glb of its upper bounds. However,
@@ -316,7 +328,7 @@ trait ConstraintHandling[AbstractContext] {
316
328
*/
317
329
def instanceType (param : TypeParamRef , fromBelow : Boolean )(implicit actx : AbstractContext ): Type = {
318
330
val inst = approximation(param, fromBelow).simplified
319
- if (fromBelow) widenInferred (inst, constraint.fullUpperBound(param)) else inst
331
+ if (fromBelow) widenInferred2 (inst, /* constraint.fullUpperBound*/ (param)) else inst
320
332
}
321
333
322
334
/** Constraint `c1` subsumes constraint `c2`, if under `c2` as constraint we have
Original file line number Diff line number Diff line change @@ -1525,6 +1525,8 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
1525
1525
/** The greatest lower bound of a list types */
1526
1526
final def glb (tps : List [Type ]): Type = ((AnyType : Type ) /: tps)(glb)
1527
1527
1528
+ def widenInUnions (implicit ctx : Context ): Boolean = ctx.scala2Mode || ctx.erasedTypes || true
1529
+
1528
1530
/** The least upper bound of two types
1529
1531
* @param canConstrain If true, new constraints might be added to simplify the lub.
1530
1532
* @note We do not admit singleton types in or-types as lubs.
@@ -1536,7 +1538,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
1536
1538
if ((tp1 isRef AnyClass ) || (tp1 isRef AnyKindClass ) || (tp2 isRef NothingClass )) return tp1
1537
1539
if ((tp2 isRef AnyClass ) || (tp2 isRef AnyKindClass ) || (tp1 isRef NothingClass )) return tp2
1538
1540
val atoms1 = tp1.atoms
1539
- if (atoms1.nonEmpty && ! ctx.scala2Mode && ! ctx.erasedTypes ) {
1541
+ if (atoms1.nonEmpty && ! widenInUnions ) {
1540
1542
val atoms2 = tp2.atoms
1541
1543
if (atoms2.nonEmpty) {
1542
1544
if (atoms1.subsetOf(atoms2)) return tp2
@@ -1550,8 +1552,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] {
1550
1552
val t2 = mergeIfSuper(tp2, tp1, canConstrain)
1551
1553
if (t2.exists) return t2
1552
1554
1553
- def widen (tp : Type ) =
1554
- if (ctx.scala2Mode || ctx.erasedTypes) tp.widen else tp.widenIfUnstable
1555
+ def widen (tp : Type ) = if (widenInUnions) tp.widen else tp.widenIfUnstable
1555
1556
val tp1w = widen(tp1)
1556
1557
val tp2w = widen(tp2)
1557
1558
if ((tp1 ne tp1w) || (tp2 ne tp2w)) lub(tp1w, tp2w)
You can’t perform that action at this time.
0 commit comments