more informative error msg for undeclared field (A(badfield: 1) and a.badfield = expr) (#17777)

This commit is contained in:
Timothee Cour 2021-05-16 10:03:22 -07:00 • committed by GitHub
commit 3619a5a2aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 3 deletions

View file

@ -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]