Skip to content

Commit 8e17110

Browse files
authored
Merge pull request #15759 from dotty-staging/mb/isConst-lazy
Do not fold IsConst applied to dependent parameters
2 parents 4d1dbc7 + b1e723c commit 8e17110

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ object TypeEval:
6464
// currently not a concrete known type
6565
case _: TypeParamRef => None
6666
// constant if the term is constant
67-
case t: TermRef => isConst(t.underlying)
67+
case t: TermRef =>
68+
if t.denot.symbol.flagsUNSAFE.is(Flags.Param) then
69+
// might be substituted later
70+
None
71+
else
72+
isConst(t.underlying)
6873
// an operation type => recursively check all argument compositions
6974
case applied: AppliedType if defn.isCompiletimeAppliedType(applied.typeSymbol) =>
7075
val argsConst = applied.args.map(isConst)
@@ -239,4 +244,4 @@ object TypeEval:
239244

240245
case _ => NoType
241246
end tryCompiletimeConstantFold
242-
end TypeEval
247+
end TypeEval

tests/neg/singleton-ops-any.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ object Test {
3737
val t51 : true = isConst2[1, 1]
3838
val t52 : false = isConst2[1, one.type]
3939
val t53 : true = isConst2[1, two.type]
40+
41+
val t54: 2 = 2
42+
summon[IsConst[t54.type] =:= true]
43+
def isConst(arg: Int)(using IsConst[arg.type] =:= true): Unit = ???
44+
isConst(t54)
4045
}

0 commit comments

Comments
 (0)