From 7142078707c3e7349dffd5c42069e7b48353deee Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 6 Jun 2023 15:26:17 +0800 Subject: [PATCH] =?UTF-8?q?fixes=20#3770;=20templates=20with=20untyped=20p?= =?UTF-8?q?arameters=20resolve=20private=20fields=E2=80=A6=20(#22014)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #3770; templates with untyped parameters resolve private fields wrongly in generics (#21554) * fixes #3770; templates with untyped parameters resolve private fields wrongly * add a test case for #3770 * rename to `nfSkipFieldChecking` --- compiler/ast.nim | 4 +++- compiler/semgnrc.nim | 22 ++++++++++++++++++++++ compiler/semobjconstr.nim | 4 +++- tests/generics/m3770.nim | 6 ++++++ tests/generics/t3770.nim | 9 +++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 tests/generics/m3770.nim create mode 100644 tests/generics/t3770.nim diff --git a/compiler/ast.nim b/compiler/ast.nim index 7b26703fe0..b252923972 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -505,6 +505,7 @@ type nfLastRead # this node is a last read nfFirstWrite# this node is a first write nfHasComment # node has a comment + nfSkipFieldChecking # node skips field visable checking TNodeFlags* = set[TNodeFlag] TTypeFlag* = enum # keep below 32 for efficiency reasons (now: 45) @@ -1071,7 +1072,8 @@ const nfDotSetter, nfDotField, nfIsRef, nfIsPtr, nfPreventCg, nfLL, nfFromTemplate, nfDefaultRefsParam, - nfExecuteOnReload, nfLastRead, nfFirstWrite} + nfExecuteOnReload, nfLastRead, + nfFirstWrite, nfSkipFieldChecking} namePos* = 0 patternPos* = 1 # empty except for term rewriting macros genericParamsPos* = 2 diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index ca0b05fa21..bfa3b65785 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -78,14 +78,18 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, if macroToExpandSym(s): onUse(n.info, s) result = semTemplateExpr(c, n, s, {efNoSemCheck}) + c.friendModules.add(s.owner.getModule) result = semGenericStmt(c, result, {}, ctx) + discard c.friendModules.pop() else: result = symChoice(c, n, s, scOpen) of skMacro: if macroToExpandSym(s): onUse(n.info, s) result = semMacroExpr(c, n, n, s, {efNoSemCheck}) + c.friendModules.add(s.owner.getModule) result = semGenericStmt(c, result, {}, ctx) + discard c.friendModules.pop() else: result = symChoice(c, n, s, scOpen) of skGenericParam: @@ -249,7 +253,9 @@ proc semGenericStmt(c: PContext, n: PNode, if macroToExpand(s) and sc.safeLen <= 1: onUse(fn.info, s) result = semMacroExpr(c, n, n, s, {efNoSemCheck}) + c.friendModules.add(s.owner.getModule) result = semGenericStmt(c, result, flags, ctx) + discard c.friendModules.pop() else: n[0] = sc result = n @@ -258,7 +264,9 @@ proc semGenericStmt(c: PContext, n: PNode, if macroToExpand(s) and sc.safeLen <= 1: onUse(fn.info, s) result = semTemplateExpr(c, n, s, {efNoSemCheck}) + c.friendModules.add(s.owner.getModule) result = semGenericStmt(c, result, flags, ctx) + discard c.friendModules.pop() else: n[0] = sc result = n @@ -497,6 +505,20 @@ proc semGenericStmt(c: PContext, n: PNode, of nkExprColonExpr, nkExprEqExpr: checkMinSonsLen(n, 2, c.config) result[1] = semGenericStmt(c, n[1], flags, ctx) + of nkObjConstr: + for i in 0..