Call rblf.setDefault() when appending to a variable without +=

Bug: 222737841
Test: go test
Change-Id: I10e9e994fb1979e2e06ad30bbe66a21657d1e3db
This commit is contained in:
Cole Faust
2022-03-04 12:04:31 -08:00
parent fc74246c98
commit 816e080c4d
2 changed files with 22 additions and 8 deletions

View File

@@ -88,20 +88,33 @@ func (pcv productConfigVariable) emitSet(gctx *generationContext, asgn *assignme
}
value.emit(gctx)
}
switch asgn.flavor {
case asgnSet:
emitAssignment()
case asgnAppend:
emitAppend()
case asgnMaybeAppend:
// If we are not sure variable has been assigned before, emit setdefault
emitSetDefault := func() {
if pcv.typ == starlarkTypeList {
gctx.writef("%s(handle, %q)", cfnSetListDefault, pcv.name())
} else {
gctx.writef("cfg.setdefault(%q, %s)", pcv.name(), pcv.defaultValueString())
}
gctx.newLine()
}
switch asgn.flavor {
case asgnSet:
isSelfReferential := false
asgn.value.transform(func(expr starlarkExpr) starlarkExpr {
if ref, ok := expr.(*variableRefExpr); ok && ref.ref.name() == pcv.name() {
isSelfReferential = true
}
return nil
})
if isSelfReferential {
emitSetDefault()
}
emitAssignment()
case asgnAppend:
emitAppend()
case asgnMaybeAppend:
// If we are not sure variable has been assigned before, emit setdefault
emitSetDefault()
emitAppend()
case asgnMaybeSet:
gctx.writef("if cfg.get(%q) == None:", pcv.nam)