(e ast.Expr)
| 458 | } |
| 459 | |
| 460 | func (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 | |
| 490 | func (c *checker) checkCreateStruct(e ast.Expr) { |
| 491 | msgVal := e.AsStruct() |
no test coverage detected