compiler: fix string/numbers equality/inequality gen again

Unfortunately d58fbe0c88 didn't really fix the
problem because tinfo.Type (the expression resulting type) actually is a bool
and we need to check its parameters. Also, there is need to fix the NEQ
operation.
This commit is contained in:
Roman Khimov 2019-08-19 19:18:17 +03:00
parent 0574bcf1fe
commit 4ccda04eea

View file

@ -392,11 +392,19 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
}
case n.Op == token.EQL:
// 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)
} else {
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:
c.convertToken(n.Op)
}