Skip to content

Commit e28841f

Browse files
committed
Change flags for Any_typeCast
- it should not be Erased since that will remove the complete call, including the expression that is casted. It should be StableRealizable, so that a pure expression followed by a synthesized cast is still recognized as pure. - to make up for the loss of Erased, we take the method into account specifically when deciding whether a tree is erased.
1 parent 4d198ec commit e28841f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class Definitions {
277277
lazy val Any_isInstanceOf: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.isInstanceOf_, _ => BooleanType, Final)
278278
lazy val Any_asInstanceOf: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOf_, _.paramRefs(0), Final)
279279
lazy val Any_typeTest: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.isInstanceOfPM, _ => BooleanType, Final | Synthetic | Artifact)
280-
lazy val Any_typeCast: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOfPM, _.paramRefs(0), Final | Synthetic | Artifact | Erased)
280+
lazy val Any_typeCast: TermSymbol = enterT1ParameterlessMethod(AnyClass, nme.asInstanceOfPM, _.paramRefs(0), Final | Synthetic | Artifact | StableRealizable)
281281
// generated by pattern matcher, eliminated by erasure
282282

283283
def AnyMethods: List[TermSymbol] = List(Any_==, Any_!=, Any_equals, Any_hashCode,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,14 @@ object Erasure {
319319
class Typer(erasurePhase: DenotTransformer) extends typer.ReTyper with NoChecking {
320320
import Boxing._
321321

322+
def isErased(tree: Tree)(implicit ctx: Context): Boolean = tree match {
323+
case TypeApply(Select(qual, _), _) if tree.symbol == defn.Any_typeCast =>
324+
isErased(qual)
325+
case _ => tree.symbol.isEffectivelyErased
326+
}
327+
322328
private def checkNotErased(tree: Tree)(implicit ctx: Context): tree.type = {
323-
if (tree.symbol.isEffectivelyErased && !ctx.mode.is(Mode.Type))
329+
if (isErased(tree) && !ctx.mode.is(Mode.Type))
324330
ctx.error(em"${tree.symbol} is declared as erased, but is in fact used", tree.sourcePos)
325331
tree
326332
}

0 commit comments

Comments
 (0)