File tree 2 files changed +9
-6
lines changed
compiler/src/dotty/tools/dotc 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -981,11 +981,13 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
981
981
}
982
982
983
983
/** cast tree to `tp`, assuming no exception is raised, i.e the operation is pure */
984
- def cast (tp : Type )(using Context ): Tree = {
985
- assert(tp.isValueType, i " bad cast: $tree.asInstanceOf[ $tp] " )
984
+ def cast (tp : Type )(using Context ): Tree = cast(TypeTree (tp))
985
+
986
+ /** cast tree to `tp`, assuming no exception is raised, i.e the operation is pure */
987
+ def cast (tpt : TypeTree )(using Context ): Tree =
988
+ assert(tpt.tpe.isValueType, i " bad cast: $tree.asInstanceOf[ $tpt] " )
986
989
tree.select(if (ctx.erasedTypes) defn.Any_asInstanceOf else defn.Any_typeCast )
987
- .appliedToType(tp)
988
- }
990
+ .appliedToTypeTree(tpt)
989
991
990
992
/** cast `tree` to `tp` (or its box/unbox/cast equivalent when after
991
993
* erasure and value and non-value types are mixed),
Original file line number Diff line number Diff line change @@ -1058,13 +1058,14 @@ class Typer extends Namer
1058
1058
cpy.Block (block)(stats, expr1) withType expr1.tpe // no assignType here because avoid is redundant
1059
1059
case _ =>
1060
1060
val target = pt.simplified
1061
- if tree.tpe <:< target then Typed (tree, TypeTree (pt.simplified))
1061
+ val targetTpt = InferredTypeTree ().withType(target)
1062
+ if tree.tpe <:< target then Typed (tree, targetTpt)
1062
1063
else
1063
1064
// This case should not normally arise. It currently does arise in test cases
1064
1065
// pos/t4080b.scala and pos/i7067.scala. In that case, a type ascription is wrong
1065
1066
// and would not pass Ycheck. We have to use a cast instead. TODO: follow-up why
1066
1067
// the cases arise and eliminate them, if possible.
1067
- tree.cast(target )
1068
+ tree.cast(targetTpt )
1068
1069
}
1069
1070
def noLeaks (t : Tree ): Boolean = escapingRefs(t, localSyms).isEmpty
1070
1071
if (noLeaks(tree)) tree
You can’t perform that action at this time.
0 commit comments