Skip to content

Commit f916747

Browse files
committed
Allow inline vals with alias to constant type
1 parent c5a76f0 commit f916747

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

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 match
890+
tpt.tpe.widenTermRefExpr.dealias match
891891
case tp: ConstantType if exprPurity(tree) >= purityLevel => // ok
892892
case _ =>
893893
ctx.error(em"type of inline must be a known value", tree.sourcePos)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import compiletime._
2+
3+
class C:
4+
type X <: Tuple
5+
6+
def test: Unit =
7+
val a: C { type X = Tuple1[Any] } = ???
8+
f(a)
9+
10+
inline def f(c: C): Unit = {
11+
inline val size = constValue[Tuple.Size[c.X]]
12+
val n = size
13+
val m: Int = n
14+
???
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import compiletime._
2+
3+
class C:
4+
type N <: Int
5+
6+
def test: Unit =
7+
val a: C { type N = 3 } = ???
8+
f(a)
9+
10+
inline def f(c: C): Unit = {
11+
inline val size = constValue[c.N]
12+
val n = size
13+
val m: Int = n
14+
???
15+
}

0 commit comments

Comments
 (0)