MCPcopy Create free account
hub / github.com/cel-expr/cel-go / checkOptSelect

Method checkOptSelect

checker/checker.go:187–213  ·  view source on GitHub ↗
(e ast.Expr)

Source from the content-addressed store, hash-verified

185}
186
187func (c *checker) checkOptSelect(e ast.Expr) {
188 // Collect metadata related to the opt select call packaged by the parser.
189 call := e.AsCall()
190 if len(call.Args()) != 2 || call.IsMemberFunction() {
191 t := ""
192 if call.IsMemberFunction() {
193 t = " member call with"
194 }
195 c.errors.notAnOptionalFieldSelectionCall(e.ID(), c.location(e),
196 fmt.Sprintf(
197 "incorrect signature.%s argument count: %d", t, len(call.Args())))
198 return
199 }
200
201 operand := call.Args()[0]
202 field := call.Args()[1]
203 fieldName, isString := maybeUnwrapString(field)
204 if !isString {
205 c.errors.notAnOptionalFieldSelection(field.ID(), c.location(field), field)
206 return
207 }
208
209 // Perform type-checking using the field selection logic.
210 resultType := c.checkSelectField(e, operand, fieldName, true)
211 c.setType(e, substitute(c.mappings, resultType, false))
212 c.setReference(e, ast.NewFunctionReference("select_optional_field"))
213}
214
215func (c *checker) checkSelectField(e, operand ast.Expr, field string, optional bool) *types.Type {
216 // Interpret as field selection, first traversing down the operand.

Callers 1

checkCallMethod · 0.95

Calls 13

locationMethod · 0.95
checkSelectFieldMethod · 0.95
setTypeMethod · 0.95
setReferenceMethod · 0.95
NewFunctionReferenceFunction · 0.92
maybeUnwrapStringFunction · 0.85
substituteFunction · 0.85
AsCallMethod · 0.65
ArgsMethod · 0.65
IsMemberFunctionMethod · 0.65

Tested by

no test coverage detected