Skip to content

Do not fold IsConst applied to dependent parameters #15759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeEval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -239,4 +244,4 @@ object TypeEval:

case _ => NoType
end tryCompiletimeConstantFold
end TypeEval
end TypeEval
5 changes: 5 additions & 0 deletions tests/neg/singleton-ops-any.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}