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

Method checkCreateList

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

Source from the content-addressed store, hash-verified

423}
424
425func (c *checker) checkCreateList(e ast.Expr) {
426 create := e.AsList()
427 var elemsType *types.Type
428 optionalIndices := create.OptionalIndices()
429 optionals := make(map[int32]bool, len(optionalIndices))
430 for _, optInd := range optionalIndices {
431 optionals[optInd] = true
432 }
433 for i, e := range create.Elements() {
434 c.check(e)
435 elemType := c.getType(e)
436 if optionals[int32(i)] {
437 var isOptional bool
438 elemType, isOptional = maybeUnwrapOptional(elemType)
439 if !isOptional && !isDyn(elemType) {
440 c.errors.typeMismatch(e.ID(), c.location(e), types.NewOptionalType(elemType), elemType)
441 }
442 }
443 elemsType = c.joinTypes(e, elemsType, elemType)
444 }
445 if elemsType == nil {
446 // If the list is empty, assign free type var to elem type.
447 elemsType = c.newTypeVar()
448 }
449 c.setType(e, types.NewListType(elemsType))
450}
451
452func (c *checker) checkCreateMap(e ast.Expr) {
453 mapVal := e.AsMap()

Callers 1

checkMethod · 0.95

Calls 15

checkMethod · 0.95
getTypeMethod · 0.95
locationMethod · 0.95
joinTypesMethod · 0.95
newTypeVarMethod · 0.95
setTypeMethod · 0.95
NewOptionalTypeFunction · 0.92
NewListTypeFunction · 0.92
maybeUnwrapOptionalFunction · 0.85
isDynFunction · 0.85
AsListMethod · 0.65
OptionalIndicesMethod · 0.65

Tested by

no test coverage detected