summary refs log tree commit diff stats
path: root/compiler/semobjconstr.nim
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-10-29 04:19:40 +0800
committerGitHub <noreply@github.com>2022-10-28 16:19:40 -0400
commit141abb7b75e1dcea8c138ba625831cce7e314e4a (patch)
tree837a9b1ac176b1181fda66e4c546f95b7fd266d3 /compiler/semobjconstr.nim
parent779b1cc5beefa6064cb640401f1969c95a96c205 (diff)
downloadNim-141abb7b75e1dcea8c138ba625831cce7e314e4a.tar.gz
fixes #20681; add efSkipFieldVisibilityCheck to skip check (#20639)
* don't sem const objectConstr defaults

* fixes

* add `efSkipFieldVisibilityCheck`; fixes nkBracket types

* fixes #20681

* fixes tests

* suggestion from @metagn

* fixes tests

Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
Diffstat (limited to 'compiler/semobjconstr.nim')
-rw-r--r--compiler/semobjconstr.nim8
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim
index 1463ba833..e51684913 100644
--- a/compiler/semobjconstr.nim
+++ b/compiler/semobjconstr.nim
@@ -76,7 +76,8 @@ proc semConstrField(c: PContext, flags: TExprFlags,
   let assignment = locateFieldInInitExpr(c, field, initExpr)
   if assignment != nil:
     if nfSem in assignment.flags: return assignment[1]
-    if nfUseDefaultField in assignment[1].flags:
+    if nfUseDefaultField in assignment[1].flags or
+       efSkipFieldVisibilityCheck in flags:
       discard
     elif not fieldVisible(c, field):
       localError(c.config, initExpr.info,
@@ -415,7 +416,10 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType
   # field (if this is a case object, initialized fields in two different
   # branches will be reported as an error):
   var constrCtx = initConstrContext(t, result)
-  let (initResult, defaults) = semConstructTypeAux(c, constrCtx, flags)
+  let (initResult, defaults) = if nfUseDefaultField in n.flags:
+        semConstructTypeAux(c, constrCtx, flags + {efSkipFieldVisibilityCheck})
+      else:
+        semConstructTypeAux(c, constrCtx, flags)
   result[0].sons.add defaults
   var hasError = false # needed to split error detect/report for better msgs