Skip to content

Commit

Permalink
Merge pull request #7099 from dotty-staging/fix-#7041
Browse files Browse the repository at this point in the history
Fix #7041: Drop `Annotated` type trees at erasure
  • Loading branch information
liufengyun committed Aug 26, 2019
2 parents 0d0c006 + 22ed885 commit cd21681
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ object Erasure {
case Block(_, tpt) => tpt // erase type aliases (statements) from type block
case tpt => tpt
}
val tpt2 = promote(tpt1)
val tpt2 = typedType(tpt1)
val expr1 = typed(expr, tpt2.tpe)
assignType(untpd.cpy.Typed(tree)(expr1, tpt2), tpt2)
}
Expand Down Expand Up @@ -736,6 +736,9 @@ object Erasure {
override def typedTypeDef(tdef: untpd.TypeDef, sym: Symbol)(implicit ctx: Context): Tree =
EmptyTree

override def typedAnnotated(tree: untpd.Annotated, pt: Type)(implicit ctx: Context): Tree =
typed(tree.arg, pt)

override def typedStats(stats: List[untpd.Tree], exprOwner: Symbol)(implicit ctx: Context): List[Tree] = {
val stats1 =
if (takesBridges(ctx.owner)) new Bridges(ctx.owner.asClass, erasurePhase).add(stats)
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/i7041.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import scala.util.control.NonLocalReturns._

inline def (op: => T) rescue[T, E <: Throwable] (fallback: PartialFunction[E, T]) =
try op
catch {
case ex: ReturnThrowable[_] => throw ex
case ex: E =>
if (fallback.isDefinedAt(ex)) fallback(ex) else throw ex
}

def test: Unit = {
9 / 0 rescue { case _: ArithmeticException => 10 }
}

0 comments on commit cd21681

Please sign in to comment.