Skip to content

Commit ea4e06a

Browse files
committed
Mark type ascriptions added in ensureNoLocalRefs as inferred
# Conflicts: # compiler/src/dotty/tools/dotc/typer/RefineTypes.scala
1 parent 85b331d commit ea4e06a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -981,11 +981,13 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
981981
}
982982

983983
/** 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]")
986989
tree.select(if (ctx.erasedTypes) defn.Any_asInstanceOf else defn.Any_typeCast)
987-
.appliedToType(tp)
988-
}
990+
.appliedToTypeTree(tpt)
989991

990992
/** cast `tree` to `tp` (or its box/unbox/cast equivalent when after
991993
* erasure and value and non-value types are mixed),

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,13 +1058,14 @@ class Typer extends Namer
10581058
cpy.Block(block)(stats, expr1) withType expr1.tpe // no assignType here because avoid is redundant
10591059
case _ =>
10601060
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)
10621063
else
10631064
// This case should not normally arise. It currently does arise in test cases
10641065
// pos/t4080b.scala and pos/i7067.scala. In that case, a type ascription is wrong
10651066
// and would not pass Ycheck. We have to use a cast instead. TODO: follow-up why
10661067
// the cases arise and eliminate them, if possible.
1067-
tree.cast(target)
1068+
tree.cast(targetTpt)
10681069
}
10691070
def noLeaks(t: Tree): Boolean = escapingRefs(t, localSyms).isEmpty
10701071
if (noLeaks(tree)) tree

0 commit comments

Comments
 (0)