func (v *evalVariableAccess) Eval(scope ast.Scope, _ *ast.Stack) (interface{}, ast.Type, error) { // Look up the variable in the map variable, ok := scope.LookupVar(v.Name) if !ok { return nil, ast.TypeInvalid, fmt.Errorf( "unknown variable accessed: %s", v.Name) } // Check if the variable contains any unknown types. If so, then // mark it as unknown and return that type. if ast.IsUnknown(variable) { return nil, ast.TypeUnknown, nil } return variable.Value, variable.Type, nil }
func (tc *typeCheckVariableAccess) TypeCheck(v *TypeCheck) (ast.Node, error) { // Look up the variable in the map variable, ok := v.Scope.LookupVar(tc.n.Name) if !ok { return nil, fmt.Errorf( "unknown variable accessed: %s", tc.n.Name) } // Check if the variable contains any unknown types. If so, then // mark it as unknown. if ast.IsUnknown(variable) { v.StackPush(ast.TypeUnknown) return tc.n, nil } // Add the type to the stack v.StackPush(variable.Type) return tc.n, nil }