summary refs log tree commit diff stats
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2023-05-02 12:15:06 +0300
committerGitHub <noreply@github.com>2023-05-02 11:15:06 +0200
commitca82b4ea16eb7d48b6851110bcb4667570a97f52 (patch)
tree8c66caaa79415e307ee6ccc9b265acbf79032fc0
parentc2bcfd8cd908265c358c60c4da137783b10a8549 (diff)
downloadNim-ca82b4ea16eb7d48b6851110bcb4667570a97f52.tar.gz
underscore as special word (#21766)
* underscore as special word

* fix really hard to notice error
-rw-r--r--compiler/lookups.nim6
-rw-r--r--compiler/sempass2.nim2
-rw-r--r--compiler/semstmts.nim4
-rw-r--r--compiler/semtempl.nim4
-rw-r--r--compiler/semtypes.nim2
-rw-r--r--compiler/wordrecg.nim1
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..<child.len-1:
           if child[i].kind == nkEmpty or
-            child[i].kind == nkSym and child[i].sym.name.s == "_":
+            child[i].kind == nkSym and child[i].sym.name.id == ord(wUnderscore):
             continue
           varDecl(tracked, child[i])
           if last.kind != nkEmpty:
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 43d22bc55..e6fade528 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -393,7 +393,7 @@ proc addToVarSection(c: PContext; result: var PNode; orig, identDefs: PNode) =
     result.add identDefs
 
 proc isDiscardUnderscore(v: PSym): bool =
-  if v.name.s == "_":
+  if v.name.id == ord(wUnderscore):
     v.flags.incl(sfGenSym)
     result = true
 
@@ -613,7 +613,7 @@ proc makeVarTupleSection(c: PContext, n, a, def: PNode, typ: PType, symkind: TSy
   result = newNodeI(n.kind, a.info)
   for j in 0..<a.len-2:
     let name = a[j]
-    if useTemp and name.kind == nkIdent and name.ident.s == "_":
+    if useTemp and name.kind == nkIdent and name.ident.id == ord(wUnderscore):
       # skip _ assignments if we are using a temp as they are already evaluated
       continue
     if name.kind == nkVarTuple:
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim
index 8882e14f3..84622f0ad 100644
--- a/compiler/semtempl.nim
+++ b/compiler/semtempl.nim
@@ -227,7 +227,7 @@ proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) =
           closeScope(c)
     let ident = getIdentNode(c, n)
     if not isTemplParam(c, ident):
-      if n.kind != nkSym and not (n.kind == nkIdent and n.ident.s == "_"):
+      if n.kind != nkSym and not (n.kind == nkIdent and n.ident.id == ord(wUnderscore)):
         let local = newGenSym(k, ident, c)
         addPrelimDecl(c.c, local)
         styleCheckDef(c.c, n.info, local)
@@ -645,7 +645,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
     # body by the absence of the sfGenSym flag:
     for i in 1..<s.typ.n.len:
       let param = s.typ.n[i].sym
-      if param.name.s != "_":
+      if param.name.id != ord(wUnderscore):
         param.flags.incl sfTemplateParam
         param.flags.excl sfGenSym
       if param.typ.kind != tyUntyped: allUntyped = false
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 288ed9d88..e54de80a8 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -1306,7 +1306,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
 
     for j in 0..<a.len-2:
       var arg = newSymG(skParam, if a[j].kind == nkPragmaExpr: a[j][0] else: a[j], c)
-      if arg.name.s == "_":
+      if arg.name.id == ord(wUnderscore):
         arg.flags.incl(sfGenSym)
       elif containsOrIncl(check, arg.name.id):
         localError(c.config, a[j].info, "attempt to redefine: '" & arg.name.s & "'")
diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim
index 29a50ac52..3369d244e 100644
--- a/compiler/wordrecg.nim
+++ b/compiler/wordrecg.nim
@@ -32,6 +32,7 @@ type
 
     wColon = ":", wColonColon = "::", wEquals = "=", wDot = ".", wDotDot = "..",
     wStar = "*", wMinus = "-",
+    wUnderscore = "_",
     wMagic = "magic", wThread = "thread", wFinal = "final", wProfiler = "profiler",
     wMemTracker = "memtracker", wObjChecks = "objchecks",
     wIntDefine = "intdefine", wStrDefine = "strdefine", wBoolDefine = "booldefine",