Skip to content

Commit c83ffe6

Browse files
committed
Fix #8846: Normalize type when constant folding
1 parent 7b2be84 commit c83ffe6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ 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+
val deepDealias = new TypeMap:
514+
def apply(tp: Type): Type = mapOver(tp.dealias)
515+
tree1.tpe.widenTermRefExpr.dealias.normalized match {
514516
case ConstantType(value) =>
515517
if (isIdempotentExpr(tree1)) Literal(value).withSpan(tree.span)
516518
else tree1 match {

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)