Skip to content

Commit d8fb35e

Browse files
authored
Merge pull request #162 from scala/backport-lts-3.3-22256
Backport "Documentation only: update Example code linked to obsolete content in macros-spec.md " to 3.3 LTS
2 parents ff5f18f + acddcbc commit d8fb35e

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

docs/_docs/reference/metaprogramming/staging.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ scala -with-compiler -classpath out Test
9898
## Example
9999

100100
Now take exactly the same example as in [Macros](./macros.md). Assume that we
101-
do not want to pass an array statically but generate code at run-time and pass
101+
do not want to pass a base double value statically but generate code at run-time and pass
102102
the value, also at run-time. Note, how we make a future-stage function of type
103-
`Expr[Array[Int] => Int]` in line 6 below. Using `staging.run { ... }` we can evaluate an
103+
`Expr[Double => Double]` in line 6 below. Using `staging.run { ... }` we can evaluate an
104104
expression at runtime. Within the scope of `staging.run` we can also invoke `show` on an expression
105105
to get a source-like representation of the expression.
106106

@@ -110,12 +110,12 @@ import scala.quoted.*
110110
// make available the necessary compiler for runtime code generation
111111
given staging.Compiler = staging.Compiler.make(getClass.getClassLoader)
112112

113-
val f: Array[Int] => Int = staging.run {
114-
val stagedSum: Expr[Array[Int] => Int] =
115-
'{ (arr: Array[Int]) => ${sum('arr)}}
116-
println(stagedSum.show) // Prints "(arr: Array[Int]) => { var sum = 0; ... }"
117-
stagedSum
113+
val power3: Double => Double = staging.run {
114+
val stagedPower3: Expr[Double => Double] =
115+
'{ (x: Double) => ${ unrolledPowerCode('x, 3) } }
116+
println(stagedPower3.show) // Prints "((x: scala.Double) => x.*(x.*(x)))"
117+
stagedPower3
118118
}
119119

120-
f.apply(Array(1, 2, 3)) // Returns 6
120+
power3.apply(2.0) // Returns 8.0
121121
```

tests/neg/21538.check

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
| ^^^^^^^^^^
44
| (value : V) is not a valid singleton type, since it is not an immutable path
55
| Inline parameters are not considered immutable paths and cannot be used as
6-
| singleton types.
7-
|
6+
| singleton types.
7+
|
88
| Hint: Removing the `inline` qualifier from the `value` parameter
99
| may help resolve this issue.
1010
|

tests/neg/i21696.check

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
|---------------------------------------------------------------------------------------------------------------------
66
| Explanation (enabled by `-explain`)
77
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8-
| Referencing `T` inside a quoted expression requires a `scala.quoted.Type[T]` to be in scope.
8+
| Referencing `T` inside a quoted expression requires a `scala.quoted.Type[T]` to be in scope.
99
| Since Scala is subject to erasure at runtime, the type information will be missing during the execution of the code.
10-
| `scala.quoted.Type[T]` is therefore needed to carry `T`'s type information into the quoted code.
11-
| Without an implicit `scala.quoted.Type[T]`, the type `T` cannot be properly referenced within the expression.
10+
| `scala.quoted.Type[T]` is therefore needed to carry `T`'s type information into the quoted code.
11+
| Without an implicit `scala.quoted.Type[T]`, the type `T` cannot be properly referenced within the expression.
1212
| To resolve this, ensure that a `scala.quoted.Type[T]` is available, either through a context-bound or explicitly.
1313
---------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)