File tree Expand file tree Collapse file tree 4 files changed +38
-2
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 4 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -958,7 +958,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
958958
959959 /** Extractors for splices */
960960 object Spliced {
961- /** Extracts the content of a spliced expresion tree.
961+ /** Extracts the content of a spliced expression tree.
962962 * The result can be the contents of a term splice, which
963963 * will return a term tree.
964964 */
Original file line number Diff line number Diff line change @@ -39,9 +39,13 @@ class InlineVals extends MiniPhase:
3939 val details = if enclosingInlineds.isEmpty then " " else em " but was: $rhs"
4040 report.error(s " inline value must be pure $details" , rhs.srcPos)
4141 case tp =>
42- if tp.derivesFrom(defn.StringClass ) || defn.ScalaValueClasses ().exists(tp.derivesFrom(_)) then
42+ if tp.derivesFrom(defn.UnitClass ) then
43+ report.error(em " `inline val` of type `Unit` is not supported. \n\n To inline a `Unit` consider using `inline def` " , rhs)
44+ else if tp.derivesFrom(defn.StringClass ) || defn.ScalaValueClasses ().exists(tp.derivesFrom(_)) then
4345 val pos = if tpt.span.isZeroExtent then rhs.srcPos else tpt.srcPos
4446 report.error(em " inline value must have a literal constant type " , pos)
47+ else if tp.derivesFrom(defn.NullClass ) then
48+ report.error(em " `inline val` with `null` is not supported. \n\n To inline a `null` consider using `inline def` " , rhs)
4549 else
4650 report.error(em " inline value must contain a literal constant value. \n\n To inline more complex types consider using `inline def` " , rhs)
4751 }
Original file line number Diff line number Diff line change 1+ -- Error: tests/neg/i12177.scala:2:17 ----------------------------------------------------------------------------------
2+ 2 | inline val v = null // error
3+ | ^^^^
4+ | `inline val` with `null` is not supported.
5+ |
6+ | To inline a `null` consider using `inline def`
7+ -- Error: tests/neg/i12177.scala:4:17 ----------------------------------------------------------------------------------
8+ 4 | inline val u = () // error
9+ | ^^
10+ | `inline val` of type `Unit` is not supported.
11+ |
12+ | To inline a `Unit` consider using `inline def`
13+ -- Error: tests/neg/i12177.scala:6:18 ----------------------------------------------------------------------------------
14+ 6 | inline val u2 = { println(); () } // error
15+ | ^^^^^^^^^^^^^^^^^
16+ | `inline val` of type `Unit` is not supported.
17+ |
18+ | To inline a `Unit` consider using `inline def`
19+ -- Error: tests/neg/i12177.scala:7:18 ----------------------------------------------------------------------------------
20+ 7 | inline val u3 = { } // error
21+ | ^^^
22+ | `inline val` of type `Unit` is not supported.
23+ |
24+ | To inline a `Unit` consider using `inline def`
Original file line number Diff line number Diff line change 1+ object Test1 {
2+ inline val v = null // error
3+ inline def d = null
4+ inline val u = () // error
5+ inline def e = ()
6+ inline val u2 = { println(); () } // error
7+ inline val u3 = { } // error
8+ }
You can’t perform that action at this time.
0 commit comments