summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2024-09-09 10:50:45 +0300
committerGitHub <noreply@github.com>2024-09-09 09:50:45 +0200
commitf223f016f35af0e32252560ad650c04a81a102ee (patch)
tree67bca40e1688301aeb3bae1e22555b5fffba78ff /compiler
parent7de4ace94908f515a98fbe6f3a4a022b6fa9e3f8 (diff)
downloadNim-f223f016f35af0e32252560ad650c04a81a102ee.tar.gz
show symchoices as ambiguous in overload type mismatches (#24077)
fixes #23397

All ambiguous symbols generate symchoices for call arguments since
#23123. So, if a type mismatch receives a symchoice node for an
argument, we now treat it as an ambiguous identifier and list the
ambiguous symbols in the error message.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/lookups.nim28
-rw-r--r--compiler/semcall.nim8
2 files changed, 27 insertions, 9 deletions
diff --git a/compiler/lookups.nim b/compiler/lookups.nim
index 0e576d765..2a48f6349 100644
--- a/compiler/lookups.nim
+++ b/compiler/lookups.nim
@@ -563,23 +563,33 @@ proc errorUseQualifier*(c: PContext; info: TLineInfo; s: PSym) =
   var amb: bool = false
   discard errorUseQualifier(c, info, s, amb)
 
-proc errorUseQualifier*(c: PContext; info: TLineInfo; candidates: seq[PSym]; prefix = "use one of") =
-  var err = "ambiguous identifier: '" & candidates[0].name.s & "'"
+proc ambiguousIdentifierMsg*(candidates: seq[PSym], prefix = "use one of", indent = 0): string =
+  result = ""
+  for i in 0 ..< indent:
+    result.add(' ')
+  result.add "ambiguous identifier: '" & candidates[0].name.s & "'"
   var i = 0
   for candidate in candidates:
-    if i == 0: err.add " -- $1 the following:\n" % prefix
-    else: err.add "\n"
-    err.add "  " & candidate.owner.name.s & "." & candidate.name.s
-    err.add ": " & typeToString(candidate.typ)
+    if i == 0: result.add " -- $1 the following:\n" % prefix
+    else: result.add "\n"
+    for i in 0 ..< indent:
+      result.add(' ')
+    result.add "  " & candidate.owner.name.s & "." & candidate.name.s
+    result.add ": " & typeToString(candidate.typ)
     inc i
-  localError(c.config, info, errGenerated, err)
 
-proc errorUseQualifier*(c: PContext; info:TLineInfo; choices: PNode) =
+proc errorUseQualifier*(c: PContext; info: TLineInfo; candidates: seq[PSym]) =
+  localError(c.config, info, errGenerated, ambiguousIdentifierMsg(candidates))
+
+proc ambiguousIdentifierMsg*(choices: PNode, indent = 0): string =
   var candidates = newSeq[PSym](choices.len)
   let prefix = if choices[0].typ.kind != tyProc: "use one of" else: "you need a helper proc to disambiguate"
   for i, n in choices:
     candidates[i] = n.sym
-  errorUseQualifier(c, info, candidates, prefix)
+  result = ambiguousIdentifierMsg(candidates, prefix, indent)
+
+proc errorUseQualifier*(c: PContext; info:TLineInfo; choices: PNode) =
+  localError(c.config, info, errGenerated, ambiguousIdentifierMsg(choices))
 
 proc errorUndeclaredIdentifier*(c: PContext; info: TLineInfo; name: string, extra = "") =
   var err: string
diff --git a/compiler/semcall.nim b/compiler/semcall.nim
index 06dd09b69..b81bc2a63 100644
--- a/compiler/semcall.nim
+++ b/compiler/semcall.nim
@@ -285,6 +285,8 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
           candidates.add "\n"
         of kTypeMismatch:
           doAssert nArg != nil
+          if nArg.kind in nkSymChoices:
+            candidates.add ambiguousIdentifierMsg(nArg, indent = 2)
           let wanted = err.firstMismatch.formal.typ
           doAssert err.firstMismatch.formal != nil
           doAssert wanted != nil
@@ -317,6 +319,9 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
           candidates.add renderTree(arg)
           candidates.add "' of type: "
           candidates.addTypeDeclVerboseMaybe(c.config, got)
+          if nArg.kind in nkSymChoices:
+            candidates.add "\n"
+            candidates.add ambiguousIdentifierMsg(nArg, indent = 2)
           if got != nil and got.kind == tyProc and wanted.kind == tyProc:
             # These are proc mismatches so,
             # add the extra explict detail of the mismatch
@@ -370,6 +375,9 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
             candidates.add "' is of type: "
             let got = arg.typ
             candidates.addTypeDeclVerboseMaybe(c.config, got)
+            if arg.kind in nkSymChoices:
+              candidates.add "\n"
+              candidates.add ambiguousIdentifierMsg(arg, indent = 2)
             doAssert wanted != nil
             if got != nil:
               if got.kind == tyProc and wanted.kind == tyProc:
;rumpf_a@web.de> 2012-09-15 01:27:53 +0200 profiler documentation' href='/ahoang/Nim/commit/doc/estp.txt?h=devel&id=ad6ee9e85723a742fe76e6903a63f2796136fe98'>ad6ee9e85 ^
436af88d8 ^
ad6ee9e85 ^


d43febf81 ^



0b44d812f ^
d43febf81 ^

436af88d8 ^


83ae70cb5 ^
d43febf81 ^

83ae70cb5 ^
d43febf81 ^


ad6ee9e85 ^


0b44d812f ^
ad6ee9e85 ^
3ea644690 ^
0b44d812f ^
83ae70cb5 ^
ad6ee9e85 ^


0b44d812f ^
ad6ee9e85 ^

6505bd347 ^





































































































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206