(node *ast.BuiltinNode)
| 957 | } |
| 958 | |
| 959 | func (v *Checker) checkBuiltinGet(node *ast.BuiltinNode) Nature { |
| 960 | if len(node.Arguments) != 2 { |
| 961 | return v.error(node, "invalid number of arguments (expected 2, got %d)", len(node.Arguments)) |
| 962 | } |
| 963 | |
| 964 | base := v.visit(node.Arguments[0]) |
| 965 | prop := v.visit(node.Arguments[1]) |
| 966 | prop = prop.Deref(&v.config.NtCache) |
| 967 | |
| 968 | if id, ok := node.Arguments[0].(*ast.IdentifierNode); ok && id.Value == "$env" { |
| 969 | if s, ok := node.Arguments[1].(*ast.StringNode); ok { |
| 970 | if nt, ok := v.config.Env.Get(&v.config.NtCache, s.Value); ok { |
| 971 | return nt |
| 972 | } |
| 973 | } |
| 974 | return Nature{} |
| 975 | } |
| 976 | |
| 977 | if base.IsUnknown(&v.config.NtCache) { |
| 978 | return Nature{} |
| 979 | } |
| 980 | |
| 981 | switch base.Kind { |
| 982 | case reflect.Slice, reflect.Array: |
| 983 | if !prop.IsInteger && !prop.IsUnknown(&v.config.NtCache) { |
| 984 | return v.error(node.Arguments[1], "non-integer slice index %s", prop.String()) |
| 985 | } |
| 986 | return base.Elem(&v.config.NtCache) |
| 987 | case reflect.Map: |
| 988 | if !prop.AssignableTo(base.Key(&v.config.NtCache)) && !prop.IsUnknown(&v.config.NtCache) { |
| 989 | return v.error(node.Arguments[1], "cannot use %s to get an element from %s", prop.String(), base.String()) |
| 990 | } |
| 991 | return base.Elem(&v.config.NtCache) |
| 992 | } |
| 993 | return v.error(node.Arguments[0], "type %v does not support indexing", base.String()) |
| 994 | } |
| 995 | |
| 996 | func (v *Checker) checkFunction(f *builtin.Function, node ast.Node, arguments []ast.Node) Nature { |
| 997 | if f.Validate != nil { |
no test coverage detected