Commit 620d3f7
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 620d3f7
File tree
12 files changed
+51
-1
lines changed- compiler/src/dotty/tools/dotc/transform/init
- tests/init/neg
12 files changed
+51
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| 44 | + | |
43 | 45 | | |
44 | | - | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
51 | 66 | | |
52 | 67 | | |
53 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| 14 | + | |
12 | 15 | | |
| 16 | + | |
13 | 17 | | |
| 18 | + | |
14 | 19 | | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| 20 | + | |
18 | 21 | | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
| 9 | + | |
8 | 10 | | |
| 11 | + | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| 16 | + | |
13 | 17 | | |
| 18 | + | |
14 | 19 | | |
| 20 | + | |
15 | 21 | | |
| 22 | + | |
16 | 23 | | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
| 10 | + | |
8 | 11 | | |
| 12 | + | |
9 | 13 | | |
| 14 | + | |
10 | 15 | | |
| 16 | + | |
11 | 17 | | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
0 commit comments