(sctx *super.Context, set *ast.Set, cast super.Type)
| 422 | } |
| 423 | |
| 424 | func (a Analyzer) convertSet(sctx *super.Context, set *ast.Set, cast super.Type) (Value, error) { |
| 425 | var elemType super.Type |
| 426 | if cast != nil { |
| 427 | setType, ok := super.TypeUnder(cast).(*super.TypeSet) |
| 428 | if !ok { |
| 429 | return nil, fmt.Errorf("set decorator not of type set: %T", cast) |
| 430 | } |
| 431 | elemType = setType.Type |
| 432 | } |
| 433 | vals := make([]Value, 0, len(set.Elements)) |
| 434 | for _, elem := range set.Elements { |
| 435 | v, err := a.convertValue(sctx, elem, elemType) |
| 436 | if err != nil { |
| 437 | return nil, err |
| 438 | } |
| 439 | vals = append(vals, v) |
| 440 | } |
| 441 | if cast != nil || len(vals) == 0 { |
| 442 | if cast == nil { |
| 443 | cast = sctx.LookupTypeSet(super.TypeNull) |
| 444 | } |
| 445 | return &Array{ |
| 446 | Type: cast, |
| 447 | Elements: vals, |
| 448 | }, nil |
| 449 | } |
| 450 | elems, inner, err := a.normalizeElems(sctx, vals) |
| 451 | if err != nil { |
| 452 | return nil, err |
| 453 | } |
| 454 | return &Set{ |
| 455 | Type: sctx.LookupTypeSet(inner), |
| 456 | Elements: elems, |
| 457 | }, nil |
| 458 | } |
| 459 | |
| 460 | func (a Analyzer) convertUnion(v Value, union *super.TypeUnion, cast super.Type) (Value, error) { |
| 461 | valType := v.TypeOf() |
no test coverage detected