Skip to content

Commit 42ed82f

Browse files
fix: only add synthetic primary span if there are no others (#5874)
Purely affects the human error format. Only add the “synthetic” span covering the original specified range when there are no other primary spans specified.
1 parent 48763dc commit 42ed82f

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

src/lang_utils/diag.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,13 @@ let fancy_of_message msg =
121121
if msg.spans = [] then
122122
[G.Diagnostic.Label.primaryf ~range:(range msg.at) ""]
123123
else
124-
List.map mk_span msg.spans in
124+
let spans = List.map mk_span msg.spans in
125+
let primary_spans = List.filter (fun span -> span.prio = Primary) msg.spans in
126+
if primary_spans = [] then
127+
G.Diagnostic.Label.primaryf ~range:(range msg.at) "" :: spans
128+
else
129+
spans
130+
in
125131
let severity = match msg.sev with
126132
| Error -> G.Diagnostic.Severity.Error
127133
| Warning -> G.Diagnostic.Severity.Warning

test/fail/ok/bad-type-comp.tc-human.ok

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ because the type
2222
error[M0018]: duplicate type field name T in object type
2323
┌─ bad-type-comp.mo:7:73
2424
7 │ ignore ((module { public type T = Null}) : module { type T = Null; type T = Null });
25-
│ - - used more than once
26-
│ │
25+
│ - ^
26+
│ │ │
27+
│ │
28+
│ │ used more than once
2729
│ first use of T
2830
error[M0029]: unbound type T
2931
Did you mean type Text?

test/fail/ok/duplicate-field.tc-human.ok

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ error[M0051]: duplicate definition for m in block
55
error[M0018]: duplicate field name foo in object type
66
┌─ duplicate-field.mo:8:22
77
8 │ type T = {foo : Int; foo: Bool}
8-
│ --- --- used more than once
9-
│ │
8+
│ --- ^^^
9+
│ │ │
10+
│ │
11+
│ │ used more than once
1012
│ first use of foo
1113
error[M0018]: duplicate field name foo in object type
1214
┌─ duplicate-field.mo:21:3
1315
13 │ foo : Int;
1416
│ --- first use of foo
1517
·
1618
21 │ foo: Bool;
17-
│ --- used more than once
19+
│ ^^^
20+
│ │
21+
22+
│ used more than once
1823
error[M0019]: field names foo and nxnnbkddcv in object type have colliding hashes
1924
┌─ duplicate-field.mo:26:22
2025
26 │ type T = {foo : Int; nxnnbkddcv: Bool}
@@ -26,8 +31,10 @@ error[M0019]: tag names foo and nxnnbkddcv in variant type have colliding hashes
2631
error[M0018]: duplicate field name foo in object
2732
┌─ duplicate-field.mo:34:18
2833
34 │ ignore({foo = 5; foo = true});
29-
│ --- --- used more than once
30-
│ │
34+
│ --- ^^^
35+
│ │ │
36+
│ │
37+
│ │ used more than once
3138
│ first use of foo
3239
error[M0019]: field names foo and nxnnbkddcv in object have colliding hashes
3340
┌─ duplicate-field.mo:38:18

test/fail/ok/type-comp.tc-human.ok

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error[M0018]: duplicate type field name T in object type
22
┌─ type-comp.mo:3:42
33
3 │ type MT = module { type T = Null; type T<A> = A }; // reject
4-
│ - - used more than once
5-
│ │
4+
│ - ^
5+
│ │ │
6+
│ │
7+
│ │ used more than once
68
│ first use of T
79
error[M0046]: type argument
810
P2

0 commit comments

Comments
 (0)