@@ -814,11 +814,9 @@ class Typer extends Namer
814
814
val underlyingTreeTpe =
815
815
if (isRepeatedParamType(tpt)) TypeTree (defn.SeqType .appliedTo(pt :: Nil ))
816
816
else tpt
817
-
818
817
val expr1 =
819
- if (isRepeatedParamType(tpt)) tree.expr.withType(defn.SeqType .appliedTo(pt :: Nil ))
820
- else if (isWildcard) tree.expr.withType(tpt.tpe)
821
- else typed(tree.expr, tpt.tpe.widenSkolem)
818
+ if isWildcard then tree.expr.withType(underlyingTreeTpe.tpe)
819
+ else typed(tree.expr, underlyingTreeTpe.tpe.widenSkolem)
822
820
assignType(cpy.Typed (tree)(expr1, tpt), underlyingTreeTpe)
823
821
.withNotNullInfo(expr1.notNullInfo)
824
822
}
@@ -844,8 +842,10 @@ class Typer extends Namer
844
842
// We need to make sure its type is no longer nullable
845
843
expr0.castToNonNullable
846
844
else expr0
847
- val fromCls = if expr1.tpe.derivesFrom(defn.ArrayClass )
848
- then defn.ArrayClass else defn.SeqClass
845
+ val fromCls =
846
+ if expr1.tpe.derivesFrom(defn.ArrayClass )
847
+ then defn.ArrayClass
848
+ else defn.SeqClass
849
849
val tpt1 = TypeTree (expr1.tpe.widen.translateToRepeated(fromCls)).withSpan(tree.tpt.span)
850
850
assignType(cpy.Typed (tree)(expr1, tpt1), tpt1)
851
851
}
@@ -1055,7 +1055,14 @@ class Typer extends Namer
1055
1055
val expr1 = ascribeType(expr, pt)
1056
1056
cpy.Block (block)(stats, expr1) withType expr1.tpe // no assignType here because avoid is redundant
1057
1057
case _ =>
1058
- Typed (tree, TypeTree (pt.simplified))
1058
+ val target = pt.simplified
1059
+ if tree.tpe <:< target then Typed (tree, TypeTree (pt.simplified))
1060
+ else
1061
+ // This case should not normally arise. It currently does arise in test cases
1062
+ // pos/t4080b.scala and pos/i7067.scala. In that case, a type ascription is wrong
1063
+ // and would not pass Ycheck. We have to use a cast instead. TODO: follow-up why
1064
+ // the cases arise and eliminate them, if possible.
1065
+ tree.cast(target)
1059
1066
}
1060
1067
def noLeaks (t : Tree ): Boolean = escapingRefs(t, localSyms).isEmpty
1061
1068
if (noLeaks(tree)) tree
@@ -3693,7 +3700,7 @@ class Typer extends Namer
3693
3700
gadts.println(i " GADT-approximated $wtp ~~ $gadtApprox" )
3694
3701
if pt.isMatchedBy(gadtApprox) then
3695
3702
gadts.println(i " Member selection healed by GADT approximation " )
3696
- tpd. Typed (tree, TypeTree ( gadtApprox) )
3703
+ tree.cast( gadtApprox)
3697
3704
else tree
3698
3705
else tree // other adaptations for selections are handled in typedSelect
3699
3706
case _ if ctx.mode.is(Mode .ImplicitsEnabled ) && tree.tpe.isValueType =>
0 commit comments