Support variables with dashes in their names
Bug: 221946551 Test: go test Change-Id: I085fc35159c4f3afe53868fbc731fcaeac3a69a8
This commit is contained in:
@@ -278,6 +278,14 @@ var presetVariables = map[string]bool{
|
||||
// addVariable returns a variable with a given name. A variable is
|
||||
// added if it does not exist yet.
|
||||
func (ctx *parseContext) addVariable(name string) variable {
|
||||
// Heuristics: if variable's name is all lowercase, consider it local
|
||||
// string variable.
|
||||
isLocalVariable := name == strings.ToLower(name)
|
||||
// Local variables can't have special characters in them, because they
|
||||
// will be used as starlark identifiers
|
||||
if isLocalVariable {
|
||||
name = strings.ReplaceAll(strings.TrimSpace(name), "-", "_")
|
||||
}
|
||||
v, found := ctx.variables[name]
|
||||
if !found {
|
||||
_, preset := presetVariables[name]
|
||||
@@ -288,9 +296,7 @@ func (ctx *parseContext) addVariable(name string) variable {
|
||||
case VarClassSoong:
|
||||
v = &otherGlobalVariable{baseVariable{nam: name, typ: vi.valueType, preset: preset}}
|
||||
}
|
||||
} else if name == strings.ToLower(name) {
|
||||
// Heuristics: if variable's name is all lowercase, consider it local
|
||||
// string variable.
|
||||
} else if isLocalVariable {
|
||||
v = &localVariable{baseVariable{nam: name, typ: starlarkTypeUnknown}}
|
||||
} else {
|
||||
vt := starlarkTypeUnknown
|
||||
|
Reference in New Issue
Block a user