@@ -216,7 +216,7 @@ type `1`.
216
216
``` scala
217
217
inline def zero () <: Int = 0
218
218
219
- final val one : 1 = zero() + 1
219
+ val one : 1 = zero() + 1
220
220
```
221
221
222
222
## Inline Conditionals
@@ -285,7 +285,7 @@ inline def toInt(n: Nat) <: Int = inline n match {
285
285
case Succ (n1) => toInt(n1) + 1
286
286
}
287
287
288
- final val natTwo = toInt(Succ (Succ (Zero )))
288
+ val natTwo = toInt(Succ (Succ (Zero )))
289
289
val intTwo : 2 = natTwo
290
290
```
291
291
@@ -309,7 +309,7 @@ inline def toIntC[N] <: Int =
309
309
case _ : S [n1] => 1 + toIntC[n1]
310
310
}
311
311
312
- final val ctwo = toIntC[2 ]
312
+ val ctwo = toIntC[2 ]
313
313
```
314
314
315
315
` constValueOpt ` is the same as ` constValue ` , however returning an ` Option[T] `
@@ -338,6 +338,8 @@ called. But the function can in fact never be called, since it is declared
338
338
Using ` erasedValue ` , we can then define ` defaultValue ` as follows:
339
339
340
340
``` scala
341
+ import scala .compiletime .erasedValue
342
+
341
343
inline def defaultValue [T ] = inline erasedValue[T ] match {
342
344
case _ : Byte => Some (0 : Byte )
343
345
case _ : Char => Some (0 : Char )
@@ -372,7 +374,7 @@ inline def toIntT[N <: Nat] <: Int = inline scala.compiletime.erasedValue[N] mat
372
374
case _ : Succ [n] => toIntT[n] + 1
373
375
}
374
376
375
- final val two = toIntT[Succ [Succ [Zero .type ]]]
377
+ val two = toIntT[Succ [Succ [Zero .type ]]]
376
378
```
377
379
378
380
` erasedValue ` is an ` erased ` method so it cannot be used and has no runtime
@@ -392,6 +394,8 @@ If an inline expansion results in a call `error(msgStr)` the compiler
392
394
produces an error message containing the given ` msgStr ` .
393
395
394
396
``` scala
397
+ import scala .compiletime .error
398
+
395
399
inline def fail () = {
396
400
error(" failed for a reason" )
397
401
}
404
408
inline def fail (p1 : => Any ) = {
405
409
error(code " failed on: $p1" )
406
410
}
407
- fail(indentity (" foo" )) // error: failed on: indentity ("foo")
411
+ fail(identity (" foo" )) // error: failed on: identity ("foo")
408
412
```
409
413
410
414
## Summoning Implicits Selectively
0 commit comments