Commit 8d7b856
committed
Do not harmonize constant args if their type doesn't affect resType
Fixes the following sample from #9939:
```scala
scala> f"${3.14}%.2f rounds to ${3}%d"
1 |f"${3.14}%.2f rounds to ${3}%d"
| ^
| type mismatch;
| found : Double
| required: Int
| This location contains code that was inlined from rs$line$2:1
```
At the moment when StringInterpolation transformation was performed instead
of receiving `List(Constant(3.0), Constant(3))` arguments they
were: `List(Constant(3.0), Constant(3.0))` (the second one was converted to double because of harmonization).
That caused the reported type mismatch.
In Scala2 harmonization doesn't happen if the resulting type is fully defined.
For f-interp it shouldn't happen too as it's resulting type is a `String`:
```scala
def f[A >: Any](args: A*): String = macro ???
```1 parent 68044a6 commit 8d7b856
File tree
5 files changed
+14
-1
lines changed- compiler/src/dotty/tools/dotc/typer
- tests
- run-macros
- run
5 files changed
+14
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
744 | 744 | | |
745 | 745 | | |
746 | 746 | | |
747 | | - | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
748 | 751 | | |
749 | 752 | | |
750 | 753 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
0 commit comments