Closed
Description
object BadInlineConstCheck {
final val MaxSize = Int.MaxValue + 0
}
crashes in checkInlineConformant
:
Exception in thread "main" class dotty.tools.dotc.reporting.diagnostic.messages$Error at try/BadInlineConstCheck.scala:2: right-hand side of inline value MaxSize must be a constant expression or a function
at dotty.tools.dotc.reporting.Reporting.error(Reporter.scala:88)
at dotty.tools.dotc.reporting.Reporting.error$(Reporter.scala:87)
at dotty.tools.dotc.core.Contexts$Context.error(Contexts.scala:70)
at dotty.tools.dotc.typer.Checking.checkInlineConformant(Checking.scala:607)
at dotty.tools.dotc.typer.Checking.checkInlineConformant$(Checking.scala:600)
at dotty.tools.dotc.typer.Typer.checkInlineConformant(Typer.scala:82)
at dotty.tools.dotc.typer.Typer.$anonfun$typedValDef$1(Typer.scala:1352)
(...)
The problem here lies in the isPureExpr
check returning false
, which seems to be specifically related to the select of Int.MaxValue
not being considered pure. Ultimately, refPurity
of a reference to the Int
module return Idempotent
, which makes the overall expression idempotent rather than pure.
The standard settings of -Ycheck
don't run into this crash, since they (I think) only check after some simplification on the trees has taken place, replacing the selection by a simple literal of the same constant value.
Metadata
Metadata
Assignees
Labels
No labels