diff --git a/compiler/vm.nim b/compiler/vm.nim index 09226988a6..5ef782abde 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -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}: diff --git a/tests/macros/tmacro1.nim b/tests/macros/tmacro1.nim index 0b83345a14..ac2bf90945 100644 --- a/tests/macros/tmacro1.nim +++ b/tests/macros/tmacro1.nim @@ -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")