From 739631e88fed16ed98edf2ae7df03ec3ccdc4b5f Mon Sep 17 00:00:00 2001 From: Jake Leahy Date: Sun, 22 Dec 2024 15:08:37 +1100 Subject: [PATCH 1/4] Add test case --- tests/objects/mobjconstr_msgs.nim | 3 +++ tests/objects/tobjconstr_msgs.nim | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 tests/objects/mobjconstr_msgs.nim create mode 100644 tests/objects/tobjconstr_msgs.nim diff --git a/tests/objects/mobjconstr_msgs.nim b/tests/objects/mobjconstr_msgs.nim new file mode 100644 index 0000000000000..ee0691376c23c --- /dev/null +++ b/tests/objects/mobjconstr_msgs.nim @@ -0,0 +1,3 @@ +type + PrivateField* = object + priv: string diff --git a/tests/objects/tobjconstr_msgs.nim b/tests/objects/tobjconstr_msgs.nim new file mode 100644 index 0000000000000..09e22e7f8b35e --- /dev/null +++ b/tests/objects/tobjconstr_msgs.nim @@ -0,0 +1,7 @@ +import mobjconstr_msgs + + +discard PrivateField( + priv: "test" #[tt.Error + ^ the field 'priv' is not accessible]# +) From 66901c4adf2c05c79bba7e62ab71b80f9207e21f Mon Sep 17 00:00:00 2001 From: Jake Leahy Date: Sun, 22 Dec 2024 15:14:44 +1100 Subject: [PATCH 2/4] Make the error point to the actual field instead of the whole object --- compiler/semobjconstr.nim | 2 +- tests/objects/tobjconstr_msgs.nim | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim index 1e4bb90ebca93..5a20ede5d950e 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 diff --git a/tests/objects/tobjconstr_msgs.nim b/tests/objects/tobjconstr_msgs.nim index 09e22e7f8b35e..77ebd541f399c 100644 --- a/tests/objects/tobjconstr_msgs.nim +++ b/tests/objects/tobjconstr_msgs.nim @@ -1,7 +1,8 @@ import mobjconstr_msgs -discard PrivateField( - priv: "test" #[tt.Error - ^ the field 'priv' is not accessible]# -) +block: # Private field has correct line info + discard PrivateField( + priv: "test" #[tt.Error + ^ the field 'priv' is not accessible]# + ) From 1b4129a7699c0cc8b9a6eff80c7c27b7d1d71a94 Mon Sep 17 00:00:00 2001 From: Jake Leahy Date: Sun, 22 Dec 2024 16:13:54 +1100 Subject: [PATCH 3/4] Add fix for 'initialized twice' error pointing to the colon and not the field --- compiler/semobjconstr.nim | 2 +- tests/objects/tobjconstr_msgs.nim | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim index 5a20ede5d950e..b2dfc36b16a5d 100644 --- a/compiler/semobjconstr.nim +++ b/compiler/semobjconstr.nim @@ -521,7 +521,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType for j in 1.. Date: Sun, 22 Dec 2024 21:47:10 +1100 Subject: [PATCH 4/4] Restart CI