(e ast.Expr)
| 450 | } |
| 451 | |
| 452 | func (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 | |
| 482 | func (c *checker) checkCreateStruct(e ast.Expr) { |
| 483 | msgVal := e.AsStruct() |
no test coverage detected