Fix "unknown binary op: string + list" errors

Convert lists to strings when adding them to a string.

Bug: 201700692
Test: go test
Change-Id: Iefb68f48191136e7115a6d6bfa0608c73d5afdac
This commit is contained in:
Cole Faust
2021-12-22 14:08:08 -08:00
parent 68542bfcb5
commit 0484c2378f
2 changed files with 36 additions and 3 deletions

View File

@@ -81,10 +81,12 @@ func (pcv productConfigVariable) emitSet(gctx *generationContext, asgn *assignme
emitAppend := func() {
pcv.emitGet(gctx, true)
gctx.write(" += ")
value := asgn.value
if pcv.valueType() == starlarkTypeString {
gctx.writef(`" " + `)
value = &toStringExpr{expr: value}
}
asgn.value.emit(gctx)
value.emit(gctx)
}
switch asgn.flavor {
@@ -136,10 +138,12 @@ func (scv otherGlobalVariable) emitSet(gctx *generationContext, asgn *assignment
emitAppend := func() {
scv.emitGet(gctx, true)
gctx.write(" += ")
value := asgn.value
if scv.valueType() == starlarkTypeString {
gctx.writef(`" " + `)
value = &toStringExpr{expr: value}
}
asgn.value.emit(gctx)
value.emit(gctx)
}
switch asgn.flavor {
@@ -193,10 +197,12 @@ func (lv localVariable) emitSet(gctx *generationContext, asgn *assignmentNode) {
case asgnAppend:
lv.emitGet(gctx, false)
gctx.write(" += ")
value := asgn.value
if lv.valueType() == starlarkTypeString {
gctx.writef(`" " + `)
value = &toStringExpr{expr: value}
}
asgn.value.emit(gctx)
value.emit(gctx)
case asgnMaybeAppend:
gctx.writef("%s(%q, ", cfnLocalAppend, lv)
asgn.value.emit(gctx)