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
diff --git a/mk2rbc/mk2rbc.go b/mk2rbc/mk2rbc.go
index 35d7d4d..212b7f6 100644
--- a/mk2rbc/mk2rbc.go
+++ b/mk2rbc/mk2rbc.go
@@ -566,6 +566,12 @@
}
}
+ 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 {