Skip to content

Commit dd362ab

Browse files
authored
fix #13538 sigmatch errors are now sorted (#13701)
* fix #13538 sigmatch now sorted and has reliable order * re-enable tests that were disabled because of that bug * fix remaining tests and un-disable 2 other tests that were affected by this bug
1 parent 55d3780 commit dd362ab

File tree

6 files changed

+54
-47
lines changed

6 files changed

+54
-47
lines changed

compiler/semcall.nim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
## This module implements semantic checking for calls.
1111
# included from sem.nim
1212

13+
from algorithm import sort
14+
1315
proc sameMethodDispatcher(a, b: PSym): bool =
1416
result = false
1517
if a.kind == skMethod and b.kind == skMethod:
@@ -178,9 +180,11 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
178180

179181
var maybeWrongSpace = false
180182

183+
var candidatesAll: seq[string]
181184
var candidates = ""
182185
var skipped = 0
183186
for err in errors:
187+
candidates.setLen 0
184188
if filterOnlyFirst and err.firstMismatch.arg == 1:
185189
inc skipped
186190
continue
@@ -225,6 +229,9 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
225229
maybeWrongSpace = true
226230
for diag in err.diagnostics:
227231
candidates.add(diag & "\n")
232+
candidatesAll.add candidates
233+
candidatesAll.sort # fix #13538
234+
candidates = join(candidatesAll)
228235
if skipped > 0:
229236
candidates.add($skipped & " other mismatching symbols have been " &
230237
"suppressed; compile with --showAllMismatches:on to see them\n")

tests/concepts/t3330.nim

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
discard """
22
errormsg: "type mismatch: got <Bar[system.int]>"
3-
disabled: "32bit"
43
nimout: '''
54
t3330.nim(78, 4) Error: type mismatch: got <Bar[system.int]>
65
but expected one of:
@@ -9,33 +8,33 @@ proc test(foo: Foo[int])
98
required type for foo: Foo[int]
109
but expression 'bar' is of type: Bar[system.int]
1110
t3330.nim(63, 8) Hint: Non-matching candidates for add(k, string, T)
12-
proc add(x: var string; y: string)
13-
first type mismatch at position: 1
14-
required type for x: var string
15-
but expression 'k' is of type: Alias
16-
proc add[T](x: var seq[T]; y: openArray[T])
11+
proc add(result: var string; x: float)
1712
first type mismatch at position: 1
18-
required type for x: var seq[T]
13+
required type for result: var string
1914
but expression 'k' is of type: Alias
20-
proc add(result: var string; x: float)
15+
proc add(result: var string; x: int64)
2116
first type mismatch at position: 1
2217
required type for result: var string
2318
but expression 'k' is of type: Alias
24-
proc add[T](x: var seq[T]; y: T)
19+
proc add(x: var string; y: char)
2520
first type mismatch at position: 1
26-
required type for x: var seq[T]
21+
required type for x: var string
2722
but expression 'k' is of type: Alias
2823
proc add(x: var string; y: cstring)
2924
first type mismatch at position: 1
3025
required type for x: var string
3126
but expression 'k' is of type: Alias
32-
proc add(x: var string; y: char)
27+
proc add(x: var string; y: string)
3328
first type mismatch at position: 1
3429
required type for x: var string
3530
but expression 'k' is of type: Alias
36-
proc add(result: var string; x: int64)
31+
proc add[T](x: var seq[T]; y: T)
3732
first type mismatch at position: 1
38-
required type for result: var string
33+
required type for x: var seq[T]
34+
but expression 'k' is of type: Alias
35+
proc add[T](x: var seq[T]; y: openArray[T])
36+
first type mismatch at position: 1
37+
required type for x: var seq[T]
3938
but expression 'k' is of type: Alias
4039
4140
t3330.nim(63, 8) template/generic instantiation of `add` from here
@@ -46,10 +45,11 @@ t3330.nim(71, 6) Foo: 'bar.x' cannot be assigned to
4645
expression: test(bar)'''
4746
"""
4847

49-
# Note: currently disabled on 32bit because the candidates are presented in
50-
# different order on travis with `NIM_COMPILE_TO_CPP=false CPU=i386`;
51-
# a possible fix would be to sort the candidates by proc signature or
52-
# declaration location
48+
49+
50+
51+
52+
5353

5454

5555

tests/concepts/texplain.nim

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,24 @@ texplain.nim(124, 5) ExplainedConcept: concept predicate failed
3737
3838
texplain.nim(168, 20) Error: type mismatch: got <NonMatchingType>
3939
but expected one of:
40+
proc e(i: int): int
41+
first type mismatch at position: 1
42+
required type for i: int
43+
but expression 'n' is of type: NonMatchingType
4044
proc e(o: ExplainedConcept): int
4145
first type mismatch at position: 1
4246
required type for o: ExplainedConcept
4347
but expression 'n' is of type: NonMatchingType
4448
texplain.nim(168, 9) template/generic instantiation of `assert` from here
4549
texplain.nim(124, 5) ExplainedConcept: concept predicate failed
46-
proc e(i: int): int
47-
first type mismatch at position: 1
48-
required type for i: int
49-
but expression 'n' is of type: NonMatchingType
5050
5151
expression: e(n)
5252
texplain.nim(169, 20) Error: type mismatch: got <NonMatchingType>
5353
but expected one of:
54+
proc r(i: string): int
55+
first type mismatch at position: 1
56+
required type for i: string
57+
but expression 'n' is of type: NonMatchingType
5458
proc r(o: RegularConcept): int
5559
first type mismatch at position: 1
5660
required type for o: RegularConcept
@@ -61,21 +65,17 @@ proc r[T](a: SomeNumber; b: T; c: auto)
6165
first type mismatch at position: 1
6266
required type for a: SomeNumber
6367
but expression 'n' is of type: NonMatchingType
64-
proc r(i: string): int
65-
first type mismatch at position: 1
66-
required type for i: string
67-
but expression 'n' is of type: NonMatchingType
6868
6969
expression: r(n)
7070
texplain.nim(170, 20) Hint: Non-matching candidates for r(y)
71-
proc r[T](a: SomeNumber; b: T; c: auto)
72-
first type mismatch at position: 1
73-
required type for a: SomeNumber
74-
but expression 'y' is of type: MatchingType
7571
proc r(i: string): int
7672
first type mismatch at position: 1
7773
required type for i: string
7874
but expression 'y' is of type: MatchingType
75+
proc r[T](a: SomeNumber; b: T; c: auto)
76+
first type mismatch at position: 1
77+
required type for a: SomeNumber
78+
but expression 'y' is of type: MatchingType
7979
8080
texplain.nim(178, 2) Error: type mismatch: got <MatchingType>
8181
but expected one of:
@@ -97,10 +97,10 @@ expression: f(y)'''
9797
errormsg: "type mismatch: got <MatchingType>"
9898
line: 178
9999
100-
disabled: 32bit
101100
"""
102101

103-
# disabled on 32 bit, because the order of suggested alternatives ``r`` differs
102+
103+
104104
# proc r[T](a: SomeNumber; b: T; c: auto)
105105
# proc r(i: string): int
106106
# proc r(o: RegularConcept): int

tests/errmsgs/tsigmatch.nim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ discard """
33
nimout: '''
44
tsigmatch.nim(111, 4) Error: type mismatch: got <A, string>
55
but expected one of:
6+
proc f(a: A)
7+
first type mismatch at position: 2
8+
extra argument given
69
proc f(b: B)
710
first type mismatch at position: 1
811
required type for b: B
912
but expression 'A()' is of type: A
10-
proc f(a: A)
11-
first type mismatch at position: 2
12-
extra argument given
1313
1414
expression: f(A(), "extra")
1515
tsigmatch.nim(125, 6) Error: type mismatch: got <tuple of (string, proc (){.gcsafe, locks: 0.})>
@@ -61,14 +61,14 @@ proc f(a1: string; a2: varargs[string]; a3: float; a4: var string)
6161
expression: f("asdf", "1", "2", "3", "4", 2.3, "bad")
6262
tsigmatch.nim(164, 4) Error: type mismatch: got <string, a0: int literal(12)>
6363
but expected one of:
64-
proc f(x: string; a0: var int)
65-
first type mismatch at position: 2
66-
required type for a0: var int
67-
but expression 'a0 = 12' is immutable, not 'var'
6864
proc f(x: string; a0: string)
6965
first type mismatch at position: 2
7066
required type for a0: string
7167
but expression 'a0 = 12' is of type: int literal(12)
68+
proc f(x: string; a0: var int)
69+
first type mismatch at position: 2
70+
required type for a0: var int
71+
but expression 'a0 = 12' is immutable, not 'var'
7272
7373
expression: f(foo, a0 = 12)
7474
tsigmatch.nim(171, 7) Error: type mismatch: got <Mystring, string>

tests/errmsgs/tsigmatch2.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ discard """
33
nimout: '''
44
tsigmatch2.nim(40, 14) Error: type mismatch: got <float64>
55
but expected one of:
6-
proc foo(i: Foo): string
7-
first type mismatch at position: 1
8-
required type for i: Foo
9-
but expression '1.2' is of type: float64
106
proc foo(args: varargs[string, myproc]): string
117
first type mismatch at position: 1
128
required type for args: varargs[string]
139
but expression '1.2' is of type: float64
10+
proc foo(i: Foo): string
11+
first type mismatch at position: 1
12+
required type for i: Foo
13+
but expression '1.2' is of type: float64
1414
1515
expression: foo(1.2)
1616
tsigmatch2.nim(46, 7) Error: type mismatch: got <int literal(1)>

tests/errmsgs/tunknown_named_parameter.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ proc rsplit(s: string; sep: char; maxsplit: int = -1): seq[string]
66
first type mismatch at position: 2
77
required type for sep: char
88
but expression '{':'}' is of type: set[char]
9-
proc rsplit(s: string; seps: set[char] = Whitespace; maxsplit: int = -1): seq[string]
10-
first type mismatch at position: 3
11-
unknown named parameter: maxsplits
129
proc rsplit(s: string; sep: string; maxsplit: int = -1): seq[string]
1310
first type mismatch at position: 2
1411
required type for sep: string
1512
but expression '{':'}' is of type: set[char]
13+
proc rsplit(s: string; seps: set[char] = Whitespace; maxsplit: int = -1): seq[string]
14+
first type mismatch at position: 3
15+
unknown named parameter: maxsplits
1616
1717
expression: rsplit("abc:def", {':'}, maxsplits = 1)
1818
'''
19-
disabled: 32bit
2019
"""
2120

21+
2222
# bug #8043
2323

24-
# disabled on 32 bit systems because the order of suggested proc alternatives is different.
24+
2525

2626
import strutils
2727
"abc:def".rsplit({':'}, maxsplits = 1)

0 commit comments

Comments
 (0)