Commit 286b518
committed
Add underlining to safe-init stack traces
This underlines the source positions in the safe-init stack traces similarly to how the MessageRendering will underline its stack positions.
Before, a safe-init error might look like this:
```
[error] -- Error: /******/dotty/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala:1032:22
[error] 1032 | "inlineVars" -> inlineVars
[error] | ^^^^^^^^^^
[error] |Cannot prove that the value is fully initialized. Only initialized values may be used as arguments
[error] |
[error] |The unsafe promotion may cause the following problem:
[error] |Calling the external method method apply may cause initialization errors. Calling trace:
[error] | -> "inlineVars" -> inlineVars [ PatternMatcher.scala:1032 ]
[error] | -> Inliner(plan) [ PatternMatcher.scala:700 ]
[error] | -> case plan: TestPlan => apply(plan) [ PatternMatcher.scala:492 ]
[error] | -> plan.scrutinee = apply(plan.scrutinee) [ PatternMatcher.scala:472 ]
[error] | -> def apply(tree: Tree): Tree = treeMap.transform(tree) [ PatternMatcher.scala:470 ]
[error] | -> if (toDrop(sym)) transform(initializer(sym)) [ PatternMatcher.scala:675 ]
```
Now, the same error looks like this:
```
[error] -- Error: /******/dotty/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala:1032:22
[error] 1032 | "inlineVars" -> inlineVars
[error] | ^^^^^^^^^^
[error] |Cannot prove that the value is fully initialized. Only initialized values may be used as arguments
[error] |
[error] |The unsafe promotion may cause the following problem:
[error] |Calling the external method method apply may cause initialization errors. Calling trace:
[error] |-> "inlineVars" -> inlineVars [ PatternMatcher.scala:1032 ]
[error] | ^^^^^^^^^^
[error] |-> Inliner(plan) [ PatternMatcher.scala:700 ]
[error] | ^^^^^^^^^^^^^
[error] |-> case plan: TestPlan => apply(plan) [ PatternMatcher.scala:492 ]
[error] | ^^^^^^^^^^^
[error] |-> plan.scrutinee = apply(plan.scrutinee) [ PatternMatcher.scala:472 ]
[error] | ^^^^^^^^^^^^^^^^^^^^^
[error] |-> def apply(tree: Tree): Tree = treeMap.transform(tree) [ PatternMatcher.scala:470 ]
[error] | ^^^^^^^^^^^^^^^^^^^^^^^
[error] |-> if (toDrop(sym)) transform(initializer(sym)) [ PatternMatcher.scala:675 ]
```
This should improve the readability of the safe-init error messages.
Review by @liufengyun1 parent 5626f25 commit 286b518
File tree
12 files changed
+95
-43
lines changed- compiler/src/dotty/tools/dotc/transform/init
- tests/init/neg
12 files changed
+95
-43
lines changedLines changed: 21 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | | - | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | 33 | | |
35 | | - | |
| 34 | + | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
43 | 46 | | |
44 | | - | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
50 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
51 | 68 | | |
52 | 69 | | |
53 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
17 | | - | |
18 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | | - | |
| 13 | + | |
13 | 14 | | |
14 | | - | |
15 | | - | |
| 15 | + | |
| 16 | + | |
16 | 17 | | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
0 commit comments