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

Method checkCreateMap

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

Source from the content-addressed store, hash-verified

450}
451
452func (c *checker) checkCreateMap(e ast.Expr) {
453 mapVal := e.AsMap()
454 var mapKeyType *types.Type
455 var mapValueType *types.Type
456 for _, e := range mapVal.Entries() {
457 entry := e.AsMapEntry()
458 key := entry.Key()
459 c.check(key)
460 mapKeyType = c.joinTypes(key, mapKeyType, c.getType(key))
461
462 val := entry.Value()
463 c.check(val)
464 valType := c.getType(val)
465 if entry.IsOptional() {
466 var isOptional bool
467 valType, isOptional = maybeUnwrapOptional(valType)
468 if !isOptional && !isDyn(valType) {
469 c.errors.typeMismatch(val.ID(), c.location(val), types.NewOptionalType(valType), valType)
470 }
471 }
472 mapValueType = c.joinTypes(val, mapValueType, valType)
473 }
474 if mapKeyType == nil {
475 // If the map is empty, assign free type variables to typeKey and value type.
476 mapKeyType = c.newTypeVar()
477 mapValueType = c.newTypeVar()
478 }
479 c.setType(e, types.NewMapType(mapKeyType, mapValueType))
480}
481
482func (c *checker) checkCreateStruct(e ast.Expr) {
483 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