summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semcall.nim15
-rw-r--r--compiler/semobjconstr.nim3
-rw-r--r--tests/errmsgs/tundeclared_field.nim40
3 files changed, 55 insertions, 3 deletions
diff --git a/compiler/semcall.nim b/compiler/semcall.nim
index 8f29bdf32..facaa89f7 100644
--- a/compiler/semcall.nim
+++ b/compiler/semcall.nim
@@ -411,8 +411,19 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
 
     if overloadsState == csEmpty and result.state == csEmpty:
       if efNoUndeclared notin flags: # for tests/pragmas/tcustom_pragma.nim
-        # xxx adapt/use errorUndeclaredIdentifierHint(c, n, f.ident)
-        localError(c.config, n.info, getMsgDiagnostic(c, flags, n, f))
+        template impl() =
+          # xxx adapt/use errorUndeclaredIdentifierHint(c, n, f.ident)
+          localError(c.config, n.info, getMsgDiagnostic(c, flags, n, f))
+        if n[0].kind == nkIdent and n[0].ident.s == ".=" and n[2].kind == nkIdent:
+          let sym = n[1].typ.sym
+          if sym == nil:
+            impl()
+          else:
+            let field = n[2].ident.s
+            let msg = errUndeclaredField % field & " for type " & getProcHeader(c.config, sym)
+            localError(c.config, orig[2].info, msg)
+        else:
+          impl()
       return
     elif result.state != csMatch:
       if nfExprCall in n.flags:
diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim
index 6f3cabcbf..16e3c6cee 100644
--- a/compiler/semobjconstr.nim
+++ b/compiler/semobjconstr.nim
@@ -429,7 +429,8 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
           hasError = true
           break
       # 2) No such field exists in the constructed type
-      localError(c.config, field.info, errUndeclaredFieldX % id.s)
+      let msg = errUndeclaredField % id.s & " for type " & getProcHeader(c.config, t.sym)
+      localError(c.config, field.info, msg)
       hasError = true
       break
 
diff --git a/tests/errmsgs/tundeclared_field.nim b/tests/errmsgs/tundeclared_field.nim
new file mode 100644
index 000000000..2b274ae58
--- /dev/null
+++ b/tests/errmsgs/tundeclared_field.nim
@@ -0,0 +1,40 @@
+discard """
+cmd: '''nim check --hints:off $file'''
+action: reject
+nimout: '''
+tundeclared_field.nim(25, 12) Error: undeclared field: 'bad' for type tundeclared_field.A [type declared in tundeclared_field.nim(22, 8)]
+tundeclared_field.nim(30, 16) Error: undeclared field: 'bad' for type tundeclared_field.A [type declared in tundeclared_field.nim(28, 8)]
+tundeclared_field.nim(36, 4) Error: undeclared field: 'bad' for type tundeclared_field.A [type declared in tundeclared_field.nim(33, 8)]
+tundeclared_field.nim(40, 13) Error: cannot instantiate Foo [type declared in tundeclared_field.nim(39, 8)]
+'''
+"""
+
+
+
+
+
+
+
+
+
+# line 20
+block:
+  type A = object
+    a0: int
+  var a: A
+  discard a.bad
+
+block:
+  type A = object
+    a0: int
+  var a = A(bad: 0)
+
+block:
+  type A = object
+    a0: int
+  var a: A
+  a.bad = 0
+
+block:
+  type Foo[T: SomeInteger] = object
+  var a: Foo[float]