Skip to content

Commit cd21681

Browse files
authored
Merge pull request #7099 from dotty-staging/fix-#7041
Fix #7041: Drop `Annotated` type trees at erasure
2 parents 0d0c006 + 22ed885 commit cd21681

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ object Erasure {
388388
case Block(_, tpt) => tpt // erase type aliases (statements) from type block
389389
case tpt => tpt
390390
}
391-
val tpt2 = promote(tpt1)
391+
val tpt2 = typedType(tpt1)
392392
val expr1 = typed(expr, tpt2.tpe)
393393
assignType(untpd.cpy.Typed(tree)(expr1, tpt2), tpt2)
394394
}
@@ -736,6 +736,9 @@ object Erasure {
736736
override def typedTypeDef(tdef: untpd.TypeDef, sym: Symbol)(implicit ctx: Context): Tree =
737737
EmptyTree
738738

739+
override def typedAnnotated(tree: untpd.Annotated, pt: Type)(implicit ctx: Context): Tree =
740+
typed(tree.arg, pt)
741+
739742
override def typedStats(stats: List[untpd.Tree], exprOwner: Symbol)(implicit ctx: Context): List[Tree] = {
740743
val stats1 =
741744
if (takesBridges(ctx.owner)) new Bridges(ctx.owner.asClass, erasurePhase).add(stats)

tests/pos/i7041.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import scala.util.control.NonLocalReturns._
2+
3+
inline def (op: => T) rescue[T, E <: Throwable] (fallback: PartialFunction[E, T]) =
4+
try op
5+
catch {
6+
case ex: ReturnThrowable[_] => throw ex
7+
case ex: E =>
8+
if (fallback.isDefinedAt(ex)) fallback(ex) else throw ex
9+
}
10+
11+
def test: Unit = {
12+
9 / 0 rescue { case _: ArithmeticException => 10 }
13+
}

0 commit comments

Comments
 (0)