mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-14 23:33:28 +00:00
eqIdent new returns false on non identifier types (#7629)
This commit is contained in:
committed by
Andreas Rumpf
parent
b1b517128e
commit
9d4fd1f1bb
@@ -1397,8 +1397,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||
let bNode = regs[rc].node
|
||||
# these are cstring to prevent string copy, and cmpIgnoreStyle from
|
||||
# takes cstring arguments
|
||||
var aStrVal: cstring
|
||||
var bStrVal: cstring
|
||||
var aStrVal: cstring = nil
|
||||
var bStrVal: cstring = nil
|
||||
# extract strVal from argument ``a``
|
||||
case aNode.kind
|
||||
of {nkStrLit..nkTripleStrLit}:
|
||||
@@ -1407,8 +1407,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||
aStrVal = aNode.ident.s.cstring
|
||||
of nkSym:
|
||||
aStrVal = aNode.sym.name.s.cstring
|
||||
of nkOpenSymChoice, nkClosedSymChoice:
|
||||
aStrVal = aNode[0].sym.name.s.cstring
|
||||
else:
|
||||
stackTrace(c, tos, pc, errFieldXNotFound, "strVal")
|
||||
discard
|
||||
# extract strVal from argument ``b``
|
||||
case bNode.kind
|
||||
of {nkStrLit..nkTripleStrLit}:
|
||||
@@ -1417,11 +1419,17 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||
bStrVal = bNode.ident.s.cstring
|
||||
of nkSym:
|
||||
bStrVal = bNode.sym.name.s.cstring
|
||||
of nkOpenSymChoice, nkClosedSymChoice:
|
||||
bStrVal = bNode[0].sym.name.s.cstring
|
||||
else:
|
||||
stackTrace(c, tos, pc, errFieldXNotFound, "strVal")
|
||||
discard
|
||||
# set result
|
||||
regs[ra].intVal =
|
||||
ord(idents.cmpIgnoreStyle(aStrVal,bStrVal,high(int)) == 0)
|
||||
if aStrVal != nil and bStrVal != nil:
|
||||
ord(idents.cmpIgnoreStyle(aStrVal,bStrVal,high(int)) == 0)
|
||||
else:
|
||||
0
|
||||
|
||||
of opcStrToIdent:
|
||||
decodeB(rkNode)
|
||||
if regs[rb].node.kind notin {nkStrLit..nkTripleStrLit}:
|
||||
|
||||
@@ -27,11 +27,19 @@ import strutils
|
||||
template assertNot(arg: untyped): untyped =
|
||||
assert(not(arg))
|
||||
|
||||
|
||||
proc foo(arg: int): void =
|
||||
discard
|
||||
|
||||
proc foo(arg: float): void =
|
||||
discard
|
||||
|
||||
static:
|
||||
## test eqIdent
|
||||
let a = "abc_def"
|
||||
let b = "abcDef"
|
||||
let c = "AbcDef"
|
||||
let d = nnkBracketExpr.newTree() # not an identifier at all
|
||||
|
||||
assert eqIdent( a , b )
|
||||
assert eqIdent(newIdentNode(a), b )
|
||||
@@ -62,3 +70,12 @@ static:
|
||||
assertNot eqIdent(genSym(nskLet, c), newIdentNode( b))
|
||||
assertNot eqIdent(newIdentNode( c), genSym(nskLet, b))
|
||||
assertNot eqIdent(genSym(nskLet, c), genSym(nskLet, b))
|
||||
|
||||
# eqIdent on non identifier at all
|
||||
assertNot eqIdent(a,d)
|
||||
|
||||
# eqIdent on sym choice
|
||||
let fooSym = bindSym"foo"
|
||||
assert fooSym.kind in {nnkOpenSymChoice, nnkClosedSymChoice}
|
||||
assert fooSym.eqIdent("fOO")
|
||||
assertNot fooSym.eqIdent("bar")
|
||||
|
||||
Reference in New Issue
Block a user