Skip to content

Commit 5145154

Browse files
committed
Ignore ascriptions from ensureNoLocalRefs in ReTyper
1 parent 473246e commit 5145154

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class ReTyper(nestingLevel: Int = 0) extends Typer(nestingLevel) with ReChecking
5858
override def typedTyped(tree: untpd.Typed, pt: Type)(using Context): Tree = {
5959
assertTyped(tree)
6060

61+
if tree.hasAttachment(Typer.NoLocalRefsAscription) then
62+
return typedExpr(tree.expr, pt)
63+
6164
val tpt1 = checkSimpleKinded(typedType(tree.tpt))
6265
val expr1 = tree.expr match {
6366
case id: untpd.Ident if (ctx.mode is Mode.Pattern) && untpd.isVarPattern(id) && (id.name == nme.WILDCARD || id.name == nme.WILDCARD_STAR) =>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ object Typer {
8686
/** Indicates that an expression is explicitly ascribed to [[Unit]] type. */
8787
val AscribedToUnit = new Property.StickyKey[Unit]
8888

89+
/** Indicates that this ascription was inserted by `ensureNoLocalRefs`. */
90+
val NoLocalRefsAscription = new Property.StickyKey[Unit]
91+
8992
/** Tree adaptation lost fidelity; this attachment preserves the original tree. */
9093
val AdaptedTree = new Property.StickyKey[tpd.Tree]
9194

@@ -1580,7 +1583,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
15801583
case _ =>
15811584
val target = pt.simplified
15821585
val targetTpt = TypeTree(target, inferred = true)
1583-
if tree.tpe <:< target then Typed(tree, targetTpt)
1586+
if tree.tpe <:< target then Typed(tree, targetTpt).withAttachment(NoLocalRefsAscription, ())
15841587
else
15851588
// This case should not normally arise. It currently does arise in test cases
15861589
// pos/t4080b.scala and pos/i7067.scala. In that case, a type ascription is wrong
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
transparent inline def f(): Long =
2+
1L
3+
4+
transparent inline def g(): Long =
5+
inline val x = f()
6+
x
7+
8+
transparent inline def h(): Long =
9+
inline if g() > 0L then 1L else 0L
10+
11+
@main def Test: Unit =
12+
assert(h() == 1L)

0 commit comments

Comments
 (0)