diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index d50a258fe1fc..48671301cfea 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -510,7 +510,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => */ def constToLiteral(tree: Tree)(implicit ctx: Context): Tree = { val tree1 = ConstFold(tree) - tree1.tpe.widenTermRefExpr.dealias match { + tree1.tpe.widenTermRefExpr.dealias.normalized match { case ConstantType(value) => if (isIdempotentExpr(tree1)) Literal(value).withSpan(tree.span) else tree1 match { diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index e4a7cbffeec1..3fedfe10ecf9 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1002,14 +1002,9 @@ object SymDenotations { /** Is this a Scala 2 macro */ final def isScala2Macro(implicit ctx: Context): Boolean = is(Macro) && symbol.owner.is(Scala2x) - /** An erased value or an inline method. - */ + /** An erased value or an erased inline method or field */ def isEffectivelyErased(implicit ctx: Context): Boolean = is(Erased) || is(Inline) && !isRetainedInline && !hasAnnotation(defn.ScalaStaticAnnot) - // Do not mark local inline vals as erased. Currently some inline val references do not get - // fully inlined and then would fail the erased check. - // TODO: remove this condition when #8842 and #8843 are fixed - && (owner.isClass || is(Method)) /** ()T and => T types should be treated as equivalent for this symbol. * Note: For the moment, we treat Scala-2 compiled symbols as loose matching, diff --git a/compiler/src/dotty/tools/dotc/transform/PruneErasedDefs.scala b/compiler/src/dotty/tools/dotc/transform/PruneErasedDefs.scala index 32a0a35f752c..e03d1a91ff7e 100644 --- a/compiler/src/dotty/tools/dotc/transform/PruneErasedDefs.scala +++ b/compiler/src/dotty/tools/dotc/transform/PruneErasedDefs.scala @@ -49,7 +49,7 @@ class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform => else tree private def trivialErasedTree(tree: Tree)(using Context): Tree = - tree.tpe.widenTermRefExpr.dealias match + tree.tpe.widenTermRefExpr.dealias.normalized match case ConstantType(c) => Literal(c) case _ => ref(defn.Predef_undefined) diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 14584820ee3e..32294f6c5fc4 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -887,7 +887,7 @@ trait Checking { if sym.is(Inline, butNot = DeferredOrTermParamOrAccessor) && !ctx.erasedTypes && !ctx.inInlineMethod then // final vals can be marked inline even if they're not pure, see Typer#patchFinalVals val purityLevel = if (sym.is(Final)) Idempotent else Pure - tpt.tpe.widenTermRefExpr.dealias match + tpt.tpe.widenTermRefExpr.dealias.normalized match case tp: ConstantType => if !(exprPurity(tree) >= purityLevel) then ctx.error(em"inline value must be pure", tree.sourcePos) diff --git a/tests/pos/i8843.scala b/tests/pos/i8843.scala new file mode 100644 index 000000000000..d6744d4096f5 --- /dev/null +++ b/tests/pos/i8843.scala @@ -0,0 +1,11 @@ +class C: + type X <: Tuple + +inline def f(c: C): Unit = { + inline val size = compiletime.constValue[Tuple.Size[c.X]] + val n = size + val m: Int = n + ??? +} + +def test: Unit = f(??? : C { type X = Tuple1[Any] })