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

Method checkCreateMap

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

Source from the content-addressed store, hash-verified

458}
459
460func (c *checker) checkCreateMap(e ast.Expr) {
461 mapVal := e.AsMap()
462 var mapKeyType *types.Type
463 var mapValueType *types.Type
464 for _, e := range mapVal.Entries() {
465 entry := e.AsMapEntry()
466 key := entry.Key()
467 c.check(key)
468 mapKeyType = c.joinTypes(key, mapKeyType, c.getType(key))
469
470 val := entry.Value()
471 c.check(val)
472 valType := c.getType(val)
473 if entry.IsOptional() {
474 var isOptional bool
475 valType, isOptional = maybeUnwrapOptional(valType)
476 if !isOptional && !isDyn(valType) {
477 c.errors.typeMismatch(val.ID(), c.location(val), types.NewOptionalType(valType), valType)
478 }
479 }
480 mapValueType = c.joinTypes(val, mapValueType, valType)
481 }
482 if mapKeyType == nil {
483 // If the map is empty, assign free type variables to typeKey and value type.
484 mapKeyType = c.newTypeVar()
485 mapValueType = c.newTypeVar()
486 }
487 c.setType(e, types.NewMapType(mapKeyType, mapValueType))
488}
489
490func (c *checker) checkCreateStruct(e ast.Expr) {
491 msgVal := e.AsStruct()

Callers 1

checkMethod · 0.95

Calls 15

checkMethod · 0.95
joinTypesMethod · 0.95
getTypeMethod · 0.95
locationMethod · 0.95
newTypeVarMethod · 0.95
setTypeMethod · 0.95
NewOptionalTypeFunction · 0.92
NewMapTypeFunction · 0.92
maybeUnwrapOptionalFunction · 0.85
isDynFunction · 0.85
AsMapMethod · 0.65
EntriesMethod · 0.65

Tested by

no test coverage detected