Skip to content

Commit cd71999

Browse files
committed
Fix #7814: Turn assertion into test
1 parent 8156612 commit cd71999

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ object Erasure {
348348
tree.symbol.getAnnotation(defn.CompileTimeOnlyAnnot) match {
349349
case Some(annot) =>
350350
def defaultMsg =
351-
s"""Reference to ${tree.symbol.showLocated} should not have survived,
351+
i"""Reference to ${tree.symbol.showLocated} should not have survived,
352352
|it should have been processed and eliminated during expansion of an enclosing macro or term erasure."""
353353
val message = annot.argumentConstant(0).fold(defaultMsg)(_.stringValue)
354354
ctx.error(message, tree.sourcePos)
@@ -750,8 +750,11 @@ object Erasure {
750750

751751
override def adapt(tree: Tree, pt: Type, locked: TypeVars)(implicit ctx: Context): Tree =
752752
trace(i"adapting ${tree.showSummary}: ${tree.tpe} to $pt", show = true) {
753-
assert(ctx.phase == ctx.erasurePhase || ctx.phase == ctx.erasurePhase.next, ctx.phase)
754-
if (tree.isEmpty) tree
753+
if ctx.phase != ctx.erasurePhase && ctx.phase != ctx.erasurePhase.next then
754+
// this can happen when reading annotations loaded during erasure,
755+
// since these are loaded at phase typer.
756+
adapt(tree, pt, locked)(given ctx.withPhase(ctx.erasurePhase.next))
757+
else if (tree.isEmpty) tree
755758
else if (ctx.mode is Mode.Pattern) tree // TODO: replace with assertion once pattern matcher is active
756759
else adaptToType(tree, pt)
757760
}

tests/pos/i7814.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def i0 = Unit // error

0 commit comments

Comments
 (0)