From 20ff258a084b35e4530f5fe3da14bb72d600f225 Mon Sep 17 00:00:00 2001 From: metagn Date: Sat, 12 Apr 2025 09:39:11 +0300 Subject: [PATCH] clean up opensym encounters in compiler (#24866) To protect against crashes when this stops being experimental, in most places handled the exact same as normal symchoices (not encountered in typed ast) (cherry picked from commit 4d075dc3017c967a48ddc9f1ef92e72516ff39cb) --- compiler/ast.nim | 3 +-- compiler/lookups.nim | 4 +--- compiler/patterns.nim | 2 +- compiler/renderer.nim | 9 +++------ compiler/reorder.nim | 2 +- compiler/semexprs.nim | 4 +--- compiler/trees.nim | 6 +++--- compiler/vm.nim | 4 ++-- compiler/vmgen.nim | 2 +- 9 files changed, 14 insertions(+), 22 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 3ed9a7c675..e35a0b2031 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -933,8 +933,7 @@ proc getPIdent*(a: PNode): PIdent {.inline.} = case a.kind of nkSym: a.sym.name of nkIdent: a.ident - of nkOpenSymChoice, nkClosedSymChoice: a.sons[0].sym.name - of nkOpenSym: getPIdent(a.sons[0]) + of nkOpenSymChoice, nkClosedSymChoice, nkOpenSym: a.sons[0].sym.name else: nil const diff --git a/compiler/lookups.nim b/compiler/lookups.nim index e452da959d..ec5fdd69b0 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -58,13 +58,11 @@ proc considerQuotedIdent*(c: PContext; n: PNode, origin: PNode = nil): PIdent = of nkLiterals - nkFloatLiterals: id.add(x.renderTree) else: handleError(n, origin) result = getIdent(c.cache, id) - of nkOpenSymChoice, nkClosedSymChoice: + of nkOpenSymChoice, nkClosedSymChoice, nkOpenSym: if n[0].kind == nkSym: result = n[0].sym.name else: handleError(n, origin) - of nkOpenSym: - result = considerQuotedIdent(c, n[0], origin) else: handleError(n, origin) diff --git a/compiler/patterns.nim b/compiler/patterns.nim index 32ec7fb537..17e5a86cf9 100644 --- a/compiler/patterns.nim +++ b/compiler/patterns.nim @@ -77,7 +77,7 @@ proc inSymChoice(sc, x: PNode): bool = result = false for i in 0.. 0: result = bracketKind(g, n[0]) else: result = bkNone of nkSym: @@ -1421,10 +1421,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) = of nkPrefix: gsub(g, n, 0) if n.len > 1: - let opr = if n[0].kind == nkIdent: n[0].ident - elif n[0].kind == nkSym: n[0].sym.name - elif n[0].kind in {nkOpenSymChoice, nkClosedSymChoice}: n[0][0].sym.name - else: nil + let opr = getPIdent(n[0]) let nNext = skipHiddenNodes(n[1]) if nNext.kind == nkPrefix or (opr != nil and renderer.isKeyword(opr)): put(g, tkSpaces, Space) diff --git a/compiler/reorder.nim b/compiler/reorder.nim index 2f7c04af10..dac316fb75 100644 --- a/compiler/reorder.nim +++ b/compiler/reorder.nim @@ -93,7 +93,7 @@ proc computeDeps(cache: IdentCache; n: PNode, declares, uses: var IntSet; topLev of nkIdent: uses.incl n.ident.id of nkSym: uses.incl n.sym.name.id of nkAccQuoted: uses.incl accQuoted(cache, n).id - of nkOpenSymChoice, nkClosedSymChoice: + of nkOpenSymChoice, nkClosedSymChoice, nkOpenSym: uses.incl n[0].sym.name.id of nkStmtList, nkStmtListExpr, nkWhenStmt, nkElifBranch, nkElse, nkStaticStmt: for i in 0..