summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semcall.nim37
1 files changed, 19 insertions, 18 deletions
diff --git a/compiler/semcall.nim b/compiler/semcall.nim
index 9111e3807..13f2273a9 100644
--- a/compiler/semcall.nim
+++ b/compiler/semcall.nim
@@ -246,10 +246,18 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
       candidates.add(getProcHeader(c.config, err.sym, prefer))
     candidates.addDeclaredLocMaybe(c.config, err.sym)
     candidates.add("\n")
-    let nArg = if err.firstMismatch.arg < n.len: n[err.firstMismatch.arg] else: nil
+    const genericParamMismatches = {kGenericParamTypeMismatch, kExtraGenericParam, kMissingGenericParam}
+    let isGenericMismatch = err.firstMismatch.kind in genericParamMismatches
+    var argList = n
+    if isGenericMismatch and n[0].kind == nkBracketExpr:
+      argList = n[0]
+    let nArg =
+      if err.firstMismatch.arg < argList.len:
+        argList[err.firstMismatch.arg]
+      else:
+        nil
     let nameParam = if err.firstMismatch.formal != nil: err.firstMismatch.formal.name.s else: ""
     if n.len > 1:
-      const genericParamMismatches = {kGenericParamTypeMismatch, kExtraGenericParam, kMissingGenericParam}
       if verboseTypeMismatch notin c.config.legacyFeatures:
         case err.firstMismatch.kind
         of kUnknownNamedParam:
@@ -309,7 +317,7 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
           var wanted = err.firstMismatch.formal.typ
           if wanted.kind == tyGenericParam and wanted.genericParamHasConstraints:
             wanted = wanted.genericConstraint
-          let got = arg.typ
+          let got = arg.typ.skipTypes({tyTypeDesc})
           doAssert err.firstMismatch.formal != nil
           doAssert wanted != nil
           doAssert got != nil
@@ -350,17 +358,9 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
         of kMissingGenericParam:
           candidates.add("\n  missing generic parameter: " & nameParam)
         of kTypeMismatch, kGenericParamTypeMismatch, kVarNeeded:
-          var arg: PNode = nArg
-          let genericMismatch = err.firstMismatch.kind == kGenericParamTypeMismatch
-          if genericMismatch:
-            let pos = err.firstMismatch.arg
-            doAssert n[0].kind == nkBracketExpr and pos < n[0].len
-            arg = n[0][pos]
-          else:
-            arg = nArg
-          doAssert arg != nil
+          doAssert nArg != nil
           var wanted = err.firstMismatch.formal.typ
-          if genericMismatch and wanted.kind == tyGenericParam and
+          if isGenericMismatch and wanted.kind == tyGenericParam and
               wanted.genericParamHasConstraints:
             wanted = wanted.genericConstraint
           doAssert err.firstMismatch.formal != nil
@@ -368,16 +368,17 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
           candidates.addTypeDeclVerboseMaybe(c.config, wanted)
           candidates.add "\n  but expression '"
           if err.firstMismatch.kind == kVarNeeded:
-            candidates.add renderNotLValue(arg)
+            candidates.add renderNotLValue(nArg)
             candidates.add "' is immutable, not 'var'"
           else:
-            candidates.add renderTree(arg)
+            candidates.add renderTree(nArg)
             candidates.add "' is of type: "
-            let got = arg.typ
+            var got = nArg.typ
+            if isGenericMismatch: got = got.skipTypes({tyTypeDesc})
             candidates.addTypeDeclVerboseMaybe(c.config, got)
-            if arg.kind in nkSymChoices:
+            if nArg.kind in nkSymChoices:
               candidates.add "\n"
-              candidates.add ambiguousIdentifierMsg(arg, indent = 2)
+              candidates.add ambiguousIdentifierMsg(nArg, indent = 2)
             doAssert wanted != nil
             if got != nil:
               if got.kind == tyProc and wanted.kind == tyProc:
2' href='#n242'>242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458