diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-06-13 23:21:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-14 08:21:18 +0200 |
commit | 065243dc5988fbfcbed8236e19a588b98d63b199 (patch) | |
tree | 14bd3bee950b6158e4b441d1d7183747a5479d88 /compiler | |
parent | a266c549212d1d6e09dbfa01344edbca8b2f6222 (diff) | |
download | Nim-065243dc5988fbfcbed8236e19a588b98d63b199.tar.gz |
followup #17777: declaredloc field error msgs now work with generics (#18259)
* followup #17777: declaredloc field error msgs now work with generics * fix tests * cleanup
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/astmsgs.nim | 5 | ||||
-rw-r--r-- | compiler/semcall.nim | 5 |
2 files changed, 8 insertions, 2 deletions
diff --git a/compiler/astmsgs.nim b/compiler/astmsgs.nim index 924f0ddea..90bdce7cf 100644 --- a/compiler/astmsgs.nim +++ b/compiler/astmsgs.nim @@ -2,6 +2,11 @@ import std/strutils import options, ast, msgs +proc typSym*(t: PType): PSym = + result = t.sym + if result == nil and t.kind == tyGenericInst: # this might need to be refined + result = t[0].sym + proc addDeclaredLoc*(result: var string, conf: ConfigRef; sym: PSym) = result.add " [$1 declared in $2]" % [sym.kind.toHumanStr, toFileLineCol(conf, sym.info)] diff --git a/compiler/semcall.nim b/compiler/semcall.nim index facaa89f7..b56a1dbac 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -326,7 +326,7 @@ proc getMsgDiagnostic(c: PContext, flags: TExprFlags, n, f: PNode): string = let ident = considerQuotedIdent(c, f, n).s if {nfDotField, nfExplicitCall} * n.flags == {nfDotField}: - let sym = n[1].typ.sym + let sym = n[1].typ.typSym var typeHint = "" if sym == nil: # Perhaps we're in a `compiles(foo.bar)` expression, or @@ -337,7 +337,8 @@ proc getMsgDiagnostic(c: PContext, flags: TExprFlags, n, f: PNode): string = discard else: typeHint = " for type " & getProcHeader(c.config, sym) - result = errUndeclaredField % ident & typeHint & " " & result + let suffix = if result.len > 0: " " & result else: "" + result = errUndeclaredField % ident & typeHint & suffix else: if result.len == 0: result = errUndeclaredRoutine % ident else: result = errBadRoutine % [ident, result] |