From ca82b4ea16eb7d48b6851110bcb4667570a97f52 Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 2 May 2023 12:15:06 +0300 Subject: underscore as special word (#21766) * underscore as special word * fix really hard to notice error --- compiler/lookups.nim | 6 +++--- compiler/sempass2.nim | 2 +- compiler/semstmts.nim | 4 ++-- compiler/semtempl.nim | 4 ++-- compiler/semtypes.nim | 2 +- compiler/wordrecg.nim | 1 + 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 81ea63c32..188bb1a6b 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -15,7 +15,7 @@ when defined(nimPreviewSlimSystem): import intsets, ast, astalgo, idents, semdata, types, msgs, options, - renderer, nimfix/prettybase, lineinfos, modulegraphs, astmsgs, sets + renderer, nimfix/prettybase, lineinfos, modulegraphs, astmsgs, sets, wordrecg proc ensureNoMissingOrUnusedSymbols(c: PContext; scope: PScope) @@ -340,7 +340,7 @@ proc wrongRedefinition*(c: PContext; info: TLineInfo, s: string; # xxx pending bootstrap >= 1.4, replace all those overloads with a single one: # proc addDecl*(c: PContext, sym: PSym, info = sym.info, scope = c.currentScope) {.inline.} = proc addDeclAt*(c: PContext; scope: PScope, sym: PSym, info: TLineInfo) = - if sym.name.s == "_": return + if sym.name.id == ord(wUnderscore): return let conflict = scope.addUniqueSym(sym) if conflict != nil: if sym.kind == skModule and conflict.kind == skModule: @@ -397,7 +397,7 @@ proc addOverloadableSymAt*(c: PContext; scope: PScope, fn: PSym) = if fn.kind notin OverloadableSyms: internalError(c.config, fn.info, "addOverloadableSymAt") return - if fn.name.s != "_": + if fn.name.id != ord(wUnderscore): let check = strTableGet(scope.symbols, fn.name) if check != nil and check.kind notin OverloadableSyms: wrongRedefinition(c, fn.info, fn.name.s, check.info) diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index f0e55887c..baa37a45f 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -1117,7 +1117,7 @@ proc track(tracked: PEffects, n: PNode) = elif child.kind == nkVarTuple: for i in 0..