MCPcopy Index your code
hub / github.com/expr-lang/expr / checkBuiltinGet

Method checkBuiltinGet

checker/checker.go:959–994  ·  view source on GitHub ↗
(node *ast.BuiltinNode)

Source from the content-addressed store, hash-verified

957}
958
959func (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
996func (v *Checker) checkFunction(f *builtin.Function, node ast.Node, arguments []ast.Node) Nature {
997 if f.Validate != nil {

Callers 1

builtinNodeMethod · 0.95

Implementers 3

Configconf/config.go
Checkerchecker/checker.go
OperatorOverloadingpatcher/operator_override.go

Calls 9

errorMethod · 0.95
visitMethod · 0.95
DerefMethod · 0.80
IsUnknownMethod · 0.80
ElemMethod · 0.80
AssignableToMethod · 0.80
KeyMethod · 0.80
GetMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected