Merge pull request #300 from nspcc-dev/equal-numequal-fix-294

compiler: fix string/numbers equality/inequality gen again

Closes: #294.
This commit is contained in:
Roman Khimov 2019-08-19 20:22:22 +03:00 committed by GitHub
commit 5bab4b8bb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -392,11 +392,19 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
} }
case n.Op == token.EQL: case n.Op == token.EQL:
// VM has separate opcodes for number and string equality // VM has separate opcodes for number and string equality
if isStringType(tinfo.Type) { if isStringType(c.typeInfo.Types[n.X].Type) {
emitOpcode(c.prog, vm.EQUAL) emitOpcode(c.prog, vm.EQUAL)
} else { } else {
emitOpcode(c.prog, vm.NUMEQUAL) emitOpcode(c.prog, vm.NUMEQUAL)
} }
case n.Op == token.NEQ:
// VM has separate opcodes for number and string equality
if isStringType(c.typeInfo.Types[n.X].Type) {
emitOpcode(c.prog, vm.EQUAL)
emitOpcode(c.prog, vm.NOT)
} else {
emitOpcode(c.prog, vm.NUMNOTEQUAL)
}
default: default:
c.convertToken(n.Op) c.convertToken(n.Op)
} }