Skip to content

Commit 47963c3

Browse files
committed
Fix #8843: Normalize type when constant folding
1 parent d757454 commit 47963c3

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
510510
*/
511511
def constToLiteral(tree: Tree)(implicit ctx: Context): Tree = {
512512
val tree1 = ConstFold(tree)
513-
tree1.tpe.widenTermRefExpr.dealias match {
513+
tree1.tpe.widenTermRefExpr.dealias.normalized match {
514514
case ConstantType(value) =>
515515
if (isIdempotentExpr(tree1)) Literal(value).withSpan(tree.span)
516516
else tree1 match {

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,14 +1002,9 @@ object SymDenotations {
10021002
/** Is this a Scala 2 macro */
10031003
final def isScala2Macro(implicit ctx: Context): Boolean = is(Macro) && symbol.owner.is(Scala2x)
10041004

1005-
/** An erased value or an inline method.
1006-
*/
1005+
/** An erased value or an erased inline method or field */
10071006
def isEffectivelyErased(implicit ctx: Context): Boolean =
10081007
is(Erased) || is(Inline) && !isRetainedInline && !hasAnnotation(defn.ScalaStaticAnnot)
1009-
// Do not mark local inline vals as erased. Currently some inline val references do not get
1010-
// fully inlined and then would fail the erased check.
1011-
// TODO: remove this condition when #8842 and #8843 are fixed
1012-
&& (owner.isClass || is(Method))
10131008

10141009
/** ()T and => T types should be treated as equivalent for this symbol.
10151010
* Note: For the moment, we treat Scala-2 compiled symbols as loose matching,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform =>
4949
else tree
5050

5151
private def trivialErasedTree(tree: Tree)(using Context): Tree =
52-
tree.tpe.widenTermRefExpr.dealias match
52+
tree.tpe.widenTermRefExpr.dealias.normalized match
5353
case ConstantType(c) => Literal(c)
5454
case _ => ref(defn.Predef_undefined)
5555

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ trait Checking {
887887
if sym.is(Inline, butNot = DeferredOrTermParamOrAccessor) && !ctx.erasedTypes && !ctx.inInlineMethod then
888888
// final vals can be marked inline even if they're not pure, see Typer#patchFinalVals
889889
val purityLevel = if (sym.is(Final)) Idempotent else Pure
890-
tpt.tpe.widenTermRefExpr.dealias match
890+
tpt.tpe.widenTermRefExpr.dealias.normalized match
891891
case tp: ConstantType =>
892892
if !(exprPurity(tree) >= purityLevel) then
893893
ctx.error(em"inline value must be pure", tree.sourcePos)

tests/pos/i8843.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class C:
2+
type X <: Tuple
3+
4+
inline def f(c: C): Unit = {
5+
inline val size = compiletime.constValue[Tuple.Size[c.X]]
6+
val n = size
7+
val m: Int = n
8+
???
9+
}
10+
11+
def test: Unit = f(??? : C { type X = Tuple1[Any] })

0 commit comments

Comments
 (0)