Merge pull request #298 from nspcc-dev/fix/294

Closes #294.
This commit is contained in:
Roman Khimov 2019-08-16 17:04:09 +03:00 committed by GitHub
commit 399c5781a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -382,15 +382,22 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
ast.Walk(c, n.X) ast.Walk(c, n.X)
ast.Walk(c, n.Y) ast.Walk(c, n.Y)
// VM has separate opcode for string concatenation switch {
if n.Op == token.ADD { case n.Op == token.ADD:
typ, ok := tinfo.Type.Underlying().(*types.Basic) // VM has separate opcodes for number and string concatenation
if ok && typ.Kind() == types.String { if isStringType(tinfo.Type) {
emitOpcode(c.prog, vm.CAT) emitOpcode(c.prog, vm.CAT)
} else { } else {
emitOpcode(c.prog, vm.ADD) emitOpcode(c.prog, vm.ADD)
} }
} else { case n.Op == token.EQL:
// VM has separate opcodes for number and string equality
if isStringType(tinfo.Type) {
emitOpcode(c.prog, vm.EQUAL)
} else {
emitOpcode(c.prog, vm.NUMEQUAL)
}
default:
c.convertToken(n.Op) c.convertToken(n.Op)
} }
return nil return nil