From 6bc52737b3481dec2ac7263a3d55466efa6eaca7 Mon Sep 17 00:00:00 2001 From: Jake Leahy Date: Mon, 23 Dec 2024 00:25:36 +1100 Subject: [PATCH] Make 'field is not accessible' and 'field initialized twice' errors point to the field inside the obj construction (#24557) Fixes two line infos to make the error's clearer inside editors - 'field is not accessible' would point to the whole object construction instead of just the field inside the construction - 'field initialized twice' would point to the colon instead of the field --- compiler/semobjconstr.nim | 4 ++-- tests/objects/mobjconstr_msgs.nim | 3 +++ tests/objects/tobjconstr_msgs.nim | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/objects/mobjconstr_msgs.nim create mode 100644 tests/objects/tobjconstr_msgs.nim diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim index 1e4bb90ebca93..b2dfc36b16a5d 100644 --- a/compiler/semobjconstr.nim +++ b/compiler/semobjconstr.nim @@ -79,7 +79,7 @@ proc semConstrField(c: PContext, flags: TExprFlags, if nfSkipFieldChecking in assignment[1].flags: discard elif not fieldVisible(c, field): - localError(c.config, initExpr.info, + localError(c.config, assignment[0].info, "the field '$1' is not accessible." % [field.name.s]) return @@ -521,7 +521,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType for j in 1..