File tree 4 files changed +38
-2
lines changed
compiler/src/dotty/tools/dotc
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] =>
958
958
959
959
/** Extractors for splices */
960
960
object Spliced {
961
- /** Extracts the content of a spliced expresion tree.
961
+ /** Extracts the content of a spliced expression tree.
962
962
* The result can be the contents of a term splice, which
963
963
* will return a term tree.
964
964
*/
Original file line number Diff line number Diff line change @@ -39,9 +39,13 @@ class InlineVals extends MiniPhase:
39
39
val details = if enclosingInlineds.isEmpty then " " else em " but was: $rhs"
40
40
report.error(s " inline value must be pure $details" , rhs.srcPos)
41
41
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
43
45
val pos = if tpt.span.isZeroExtent then rhs.srcPos else tpt.srcPos
44
46
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)
45
49
else
46
50
report.error(em " inline value must contain a literal constant value. \n\n To inline more complex types consider using `inline def` " , rhs)
47
51
}
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