diff --git a/compiler/src/dotty/tools/dotc/core/TypeEval.scala b/compiler/src/dotty/tools/dotc/core/TypeEval.scala index 187b4e903065..7ec0f12db3b6 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeEval.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeEval.scala @@ -64,7 +64,12 @@ object TypeEval: // currently not a concrete known type case _: TypeParamRef => None // constant if the term is constant - case t: TermRef => isConst(t.underlying) + case t: TermRef => + if t.denot.symbol.flagsUNSAFE.is(Flags.Param) then + // might be substituted later + None + else + isConst(t.underlying) // an operation type => recursively check all argument compositions case applied: AppliedType if defn.isCompiletimeAppliedType(applied.typeSymbol) => val argsConst = applied.args.map(isConst) @@ -239,4 +244,4 @@ object TypeEval: case _ => NoType end tryCompiletimeConstantFold -end TypeEval \ No newline at end of file +end TypeEval diff --git a/tests/neg/singleton-ops-any.scala b/tests/neg/singleton-ops-any.scala index 45f63cf68ff1..86dad91d9556 100644 --- a/tests/neg/singleton-ops-any.scala +++ b/tests/neg/singleton-ops-any.scala @@ -37,4 +37,9 @@ object Test { val t51 : true = isConst2[1, 1] val t52 : false = isConst2[1, one.type] val t53 : true = isConst2[1, two.type] + + val t54: 2 = 2 + summon[IsConst[t54.type] =:= true] + def isConst(arg: Int)(using IsConst[arg.type] =:= true): Unit = ??? + isConst(t54) }