Commit bd86363
authored
Warn on inline given aliases with functions as RHS (#16499)
```scala
inline given a: Conversion[String, Item] = Item(_)
```
will now produce this warning:
```
5 | inline given a: Conversion[String, Item] = Item(_)
| ^^^^^^^
|An inline given alias with a function value as right-hand side can significantly increase
|generated code size. You should either drop the `inline` or rewrite the given with an
|explicit `apply` method.
|----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| A function value on the right-hand side of an inline given alias expands to
| an anonymous class. Each application of the inline given will then create a
| fresh copy of that class, which can increase code size in surprising ways.
| For that reason, functions are discouraged as right hand sides of inline given aliases.
| You should either drop `inline` or rewrite to an explicit `apply` method. E.g.
|
| inline given Conversion[A, B] = x => x.toB
|
| should be re-formulated as
|
| inline given Conversion[A, B] with
| def apply(x: A) = x.toB
|
```
Fixes #16497
Alternative to #16498File tree
4 files changed
+40
-0
lines changed- compiler/src/dotty/tools/dotc
- reporting
- typer
- tests/neg-custom-args/fatal-warnings
4 files changed
+40
-0
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| 190 | + | |
190 | 191 | | |
191 | 192 | | |
192 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2769 | 2769 | | |
2770 | 2770 | | |
2771 | 2771 | | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
2772 | 2792 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2374 | 2374 | | |
2375 | 2375 | | |
2376 | 2376 | | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
2377 | 2381 | | |
2378 | 2382 | | |
2379 | 2383 | | |
| |||
| 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 | + | |
0 commit comments