summaryrefslogtreecommitdiff
path: root/mk2rbc/variable.go
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2022-03-16 00:40:11 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2022-03-16 00:40:11 +0000
commit0ddc5724b0432c5ba2596eb041a62e46c32e6457 (patch)
tree7b7b93cafa02413b2729b1c6af0a18f8dde80165 /mk2rbc/variable.go
parentb6a55c53e73e1a43aa9f79d7e759530a893e4f4c (diff)
parentf92c9f2809465b826fc4a9b4b7414c3ed13b2b07 (diff)
Merge "Add type hints to mk2rbc"
Diffstat (limited to 'mk2rbc/variable.go')
-rw-r--r--mk2rbc/variable.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/mk2rbc/variable.go b/mk2rbc/variable.go
index 3241a3854..506266a29 100644
--- a/mk2rbc/variable.go
+++ b/mk2rbc/variable.go
@@ -291,6 +291,12 @@ 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 {
+ // Get the hintType before potentially changing the variable name
+ var hintType starlarkType
+ var ok bool
+ if hintType, ok = ctx.typeHints[name]; !ok {
+ hintType = starlarkTypeUnknown
+ }
// Heuristics: if variable's name is all lowercase, consider it local
// string variable.
isLocalVariable := name == strings.ToLower(name)
@@ -301,8 +307,8 @@ func (ctx *parseContext) addVariable(name string) variable {
}
v, found := ctx.variables[name]
if !found {
- _, preset := presetVariables[name]
if vi, found := KnownVariables[name]; found {
+ _, preset := presetVariables[name]
switch vi.class {
case VarClassConfig:
v = &productConfigVariable{baseVariable{nam: name, typ: vi.valueType, preset: preset}}
@@ -310,10 +316,10 @@ func (ctx *parseContext) addVariable(name string) variable {
v = &otherGlobalVariable{baseVariable{nam: name, typ: vi.valueType, preset: preset}}
}
} else if isLocalVariable {
- v = &localVariable{baseVariable{nam: name, typ: starlarkTypeUnknown}}
+ v = &localVariable{baseVariable{nam: name, typ: hintType}}
} else {
- vt := starlarkTypeUnknown
- if strings.HasPrefix(name, "LOCAL_") {
+ vt := hintType
+ if strings.HasPrefix(name, "LOCAL_") && vt == starlarkTypeUnknown {
// Heuristics: local variables that contribute to corresponding config variables
if cfgVarName, found := localProductConfigVariables[name]; found {
vi, found2 := KnownVariables[cfgVarName]