File tree 3 files changed +22
-2
lines changed
compiler/src/dotty/tools/dotc/typer
3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -888,9 +888,12 @@ trait Checking {
888
888
// final vals can be marked inline even if they're not pure, see Typer#patchFinalVals
889
889
val purityLevel = if (sym.is(Final )) Idempotent else Pure
890
890
tpt.tpe.widenTermRefExpr match
891
- case tp : ConstantType if exprPurity(tree) >= purityLevel => // ok
891
+ case tp : ConstantType =>
892
+ if ! (exprPurity(tree) >= purityLevel) then
893
+ ctx.error(em " inline value must be pure " , tree.sourcePos)
892
894
case _ =>
893
- ctx.error(em " type of inline must be a known value " , tree.sourcePos)
895
+ val pos = if tpt.span.isZeroExtent then tree.sourcePos else tpt.sourcePos
896
+ ctx.error(em " inline value must have a literal constant type " , pos)
894
897
}
895
898
896
899
/** A hook to exclude selected symbols from double declaration check */
Original file line number Diff line number Diff line change
1
+ -- Error: tests/neg/i8841.scala:2:20 -----------------------------------------------------------------------------------
2
+ 2 | inline val log1 : Boolean = false // error
3
+ | ^^^^^^^
4
+ | inline value must have a literal constant type
5
+ -- Error: tests/neg/i8841.scala:3:20 -----------------------------------------------------------------------------------
6
+ 3 | inline val log2 = true: Boolean // error
7
+ | ^^^^^^^^^^^^^
8
+ | inline value must have a literal constant type
9
+ -- Error: tests/neg/i8841.scala:4:28 -----------------------------------------------------------------------------------
10
+ 4 | inline val log3: false = { println(); false } // error
11
+ | ^^^^^^^^^^^^^^^^^^^^
12
+ | inline value must be pure
Original file line number Diff line number Diff line change
1
+ object Foo {
2
+ inline val log1 : Boolean = false // error
3
+ inline val log2 = true : Boolean // error
4
+ inline val log3 : false = { println(); false } // error
5
+ }
You can’t perform that action at this time.
0 commit comments