diff options
author | metagn <metagngn@gmail.com> | 2024-08-20 12:43:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-20 11:43:11 +0200 |
commit | 34719cad9d95b9a13fbbc5bfb9e5e06662a8c6ed (patch) | |
tree | af5fdabc6f32b1c9501b7645a98e20b05ecc7750 /compiler | |
parent | 8bd0422767fbb0adb0080fe2bde0d6300ec038cc (diff) | |
download | Nim-34719cad9d95b9a13fbbc5bfb9e5e06662a8c6ed.tar.gz |
allow `untyped` arguments to fail to compile in overload mismatch error (#23984)
fixes #8697, fixes #9620, fixes #23265 When matching a `template` with an `untyped` argument fails because of a mismatching typed argument, `presentFailedCandidates` tries to sem every single argument to show their types, but trying to type the `untyped` argument can fail if it's supposed to use an injected symbol, so we get an unrelated error message like "undeclared identifier". Instead we use `tryExpr` as the comment suggests, setting the type to `untyped` if it fails to compile. We could also maybe check if an `untyped` argument is expected in its place and not try to compile the expression if it is but this would require a bit of reorganizing the code here and IMO it's better to have the information of what type it would be if it can be typed.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/sigmatch.nim | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 744e0ff8b..a17869b87 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -338,16 +338,27 @@ template describeArgImpl(c: PContext, n: PNode, i: int, startIdx = 1; prefer = p result.add renderTree(n[i][0]) result.add ": " if arg.typ.isNil and arg.kind notin {nkStmtList, nkDo}: - # XXX we really need to 'tryExpr' here! - arg = c.semOperand(c, n[i][1]) - n[i].typ = arg.typ - n[i][1] = arg + arg = c.semTryExpr(c, n[i][1]) + if arg == nil: + arg = n[i][1] + arg.typ = newTypeS(tyUntyped, c) + else: + if arg.typ == nil: + arg.typ = newTypeS(tyVoid, c) + n[i].typ = arg.typ + n[i][1] = arg else: if arg.typ.isNil and arg.kind notin {nkStmtList, nkDo, nkElse, nkOfBranch, nkElifBranch, nkExceptBranch}: - arg = c.semOperand(c, n[i]) - n[i] = arg + arg = c.semTryExpr(c, n[i]) + if arg == nil: + arg = n[i] + arg.typ = newTypeS(tyUntyped, c) + else: + if arg.typ == nil: + arg.typ = newTypeS(tyVoid, c) + n[i] = arg if arg.typ != nil and arg.typ.kind == tyError: return result.add argTypeToString(arg, prefer) |