Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion compiler/semobjconstr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 40 additions & 0 deletions tests/errmsgs/tundeclared_field.nim
Original file line number Diff line number Diff line change
@@ -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]