eqIdent new returns false on non identifier types (#7629)
This commit is contained in:
parent
b1b517128e
commit
9d4fd1f1bb
2 changed files with 30 additions and 5 deletions
|
|
@ -1397,8 +1397,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
let bNode = regs[rc].node
|
let bNode = regs[rc].node
|
||||||
# these are cstring to prevent string copy, and cmpIgnoreStyle from
|
# these are cstring to prevent string copy, and cmpIgnoreStyle from
|
||||||
# takes cstring arguments
|
# takes cstring arguments
|
||||||
var aStrVal: cstring
|
var aStrVal: cstring = nil
|
||||||
var bStrVal: cstring
|
var bStrVal: cstring = nil
|
||||||
# extract strVal from argument ``a``
|
# extract strVal from argument ``a``
|
||||||
case aNode.kind
|
case aNode.kind
|
||||||
of {nkStrLit..nkTripleStrLit}:
|
of {nkStrLit..nkTripleStrLit}:
|
||||||
|
|
@ -1407,8 +1407,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
aStrVal = aNode.ident.s.cstring
|
aStrVal = aNode.ident.s.cstring
|
||||||
of nkSym:
|
of nkSym:
|
||||||
aStrVal = aNode.sym.name.s.cstring
|
aStrVal = aNode.sym.name.s.cstring
|
||||||
|
of nkOpenSymChoice, nkClosedSymChoice:
|
||||||
|
aStrVal = aNode[0].sym.name.s.cstring
|
||||||
else:
|
else:
|
||||||
stackTrace(c, tos, pc, errFieldXNotFound, "strVal")
|
discard
|
||||||
# extract strVal from argument ``b``
|
# extract strVal from argument ``b``
|
||||||
case bNode.kind
|
case bNode.kind
|
||||||
of {nkStrLit..nkTripleStrLit}:
|
of {nkStrLit..nkTripleStrLit}:
|
||||||
|
|
@ -1417,11 +1419,17 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
bStrVal = bNode.ident.s.cstring
|
bStrVal = bNode.ident.s.cstring
|
||||||
of nkSym:
|
of nkSym:
|
||||||
bStrVal = bNode.sym.name.s.cstring
|
bStrVal = bNode.sym.name.s.cstring
|
||||||
|
of nkOpenSymChoice, nkClosedSymChoice:
|
||||||
|
bStrVal = bNode[0].sym.name.s.cstring
|
||||||
else:
|
else:
|
||||||
stackTrace(c, tos, pc, errFieldXNotFound, "strVal")
|
discard
|
||||||
# set result
|
# set result
|
||||||
regs[ra].intVal =
|
regs[ra].intVal =
|
||||||
|
if aStrVal != nil and bStrVal != nil:
|
||||||
ord(idents.cmpIgnoreStyle(aStrVal,bStrVal,high(int)) == 0)
|
ord(idents.cmpIgnoreStyle(aStrVal,bStrVal,high(int)) == 0)
|
||||||
|
else:
|
||||||
|
0
|
||||||
|
|
||||||
of opcStrToIdent:
|
of opcStrToIdent:
|
||||||
decodeB(rkNode)
|
decodeB(rkNode)
|
||||||
if regs[rb].node.kind notin {nkStrLit..nkTripleStrLit}:
|
if regs[rb].node.kind notin {nkStrLit..nkTripleStrLit}:
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,19 @@ import strutils
|
||||||
template assertNot(arg: untyped): untyped =
|
template assertNot(arg: untyped): untyped =
|
||||||
assert(not(arg))
|
assert(not(arg))
|
||||||
|
|
||||||
|
|
||||||
|
proc foo(arg: int): void =
|
||||||
|
discard
|
||||||
|
|
||||||
|
proc foo(arg: float): void =
|
||||||
|
discard
|
||||||
|
|
||||||
static:
|
static:
|
||||||
## test eqIdent
|
## test eqIdent
|
||||||
let a = "abc_def"
|
let a = "abc_def"
|
||||||
let b = "abcDef"
|
let b = "abcDef"
|
||||||
let c = "AbcDef"
|
let c = "AbcDef"
|
||||||
|
let d = nnkBracketExpr.newTree() # not an identifier at all
|
||||||
|
|
||||||
assert eqIdent( a , b )
|
assert eqIdent( a , b )
|
||||||
assert eqIdent(newIdentNode(a), b )
|
assert eqIdent(newIdentNode(a), b )
|
||||||
|
|
@ -62,3 +70,12 @@ static:
|
||||||
assertNot eqIdent(genSym(nskLet, c), newIdentNode( b))
|
assertNot eqIdent(genSym(nskLet, c), newIdentNode( b))
|
||||||
assertNot eqIdent(newIdentNode( c), genSym(nskLet, b))
|
assertNot eqIdent(newIdentNode( c), genSym(nskLet, b))
|
||||||
assertNot eqIdent(genSym(nskLet, 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")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue