Commit 71b1101
authored
Forbid
Fixes #23008. Started during the Scala 3 Compiler Spree of Monday, April
28th, 2025.
`Constant` is an object in Dotty core that has several `apply`
overloads, including `Constant(String)` and `Constant(Null)`, that
create `Constant` instances with the appropriate tags:
https://github.com/scala/scala3/blob/bbe2dde1ee10adc05ceece96ab82af8a66a21880/compiler/src/dotty/tools/dotc/core/Constants.scala#L229
https://github.com/scala/scala3/blob/bbe2dde1ee10adc05ceece96ab82af8a66a21880/compiler/src/dotty/tools/dotc/core/Constants.scala#L238
It is called from the quotes reflection API with an argument `x:
String`, which always dispatched to the former overload:
https://github.com/scala/scala3/blob/9e7aab7ab8b2798175abf71737ffe822e50f9c30/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala#L2532
When this API is called from code without explicit nulls, `null` can be
passed as argument `x`. That still dispatches to the `Constant(String)`
overload, yielding a `Constant` with the wrong tag.
This PR fixes the issue by forbidding `null` as an argument of
`StringConstant`.StringConstant(null) (#23064)File tree
5 files changed
+43
-2
lines changed- compiler/src/scala/quoted/runtime/impl
- library/src/scala/quoted
- tests/neg-macros
- i23008
5 files changed
+43
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2529 | 2529 | | |
2530 | 2530 | | |
2531 | 2531 | | |
2532 | | - | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
2533 | 2538 | | |
2534 | 2539 | | |
2535 | 2540 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3640 | 3640 | | |
3641 | 3641 | | |
3642 | 3642 | | |
3643 | | - | |
| 3643 | + | |
| 3644 | + | |
| 3645 | + | |
| 3646 | + | |
3644 | 3647 | | |
3645 | 3648 | | |
3646 | 3649 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments