Convert values to strings when assigning to a string variable

Currently, a string variable can easily be reassigned to
a different type. Make it so that the value it's being
reassigned to is converted to a string first.

Bug: 224601891
Test: go test
Change-Id: I82252cf9e106b5a3677458cf1df2e9d1dfefe0f6
This commit is contained in:
Cole Faust
2022-03-16 14:35:45 -07:00
parent 2316240547
commit 421a192d05
2 changed files with 13 additions and 3 deletions

View File

@@ -566,6 +566,12 @@ func (ctx *parseContext) handleAssignment(a *mkparser.Assignment) []starlarkNode
}
}
if asgn.lhs.valueType() == starlarkTypeString &&
asgn.value.typ() != starlarkTypeUnknown &&
asgn.value.typ() != starlarkTypeString {
asgn.value = &toStringExpr{expr: asgn.value}
}
asgn.previous = ctx.lastAssignment(lhs)
ctx.setLastAssignment(lhs, asgn)
switch a.Type {