newArray returns an array of vals. If vals is empty, newArray returns super.Null.
(sctx *super.Context, vals []super.Value)
| 37 | // newArray returns an array of vals. If vals is empty, newArray returns |
| 38 | // super.Null. |
| 39 | func newArray(sctx *super.Context, vals []super.Value) super.Value { |
| 40 | if len(vals) == 0 { |
| 41 | return super.Null |
| 42 | } |
| 43 | var types []super.Type |
| 44 | for _, val := range vals { |
| 45 | types = append(types, val.Type()) |
| 46 | } |
| 47 | types = super.UniqueTypes(types) |
| 48 | var b scode.Builder |
| 49 | var typ super.Type |
| 50 | if len(types) == 1 { |
| 51 | for _, val := range vals { |
| 52 | b.Append(val.Bytes()) |
| 53 | } |
| 54 | typ = types[0] |
| 55 | } else { |
| 56 | union := sctx.LookupTypeUnion(types) |
| 57 | for _, val := range vals { |
| 58 | super.BuildUnion(&b, union.TagOf(val.Type()), val.Bytes()) |
| 59 | } |
| 60 | typ = union |
| 61 | } |
| 62 | return super.NewValue(sctx.LookupTypeArray(typ), b.Bytes()) |
| 63 | } |
| 64 | |
| 65 | func (c *Collect) ConsumeAsPartial(val super.Value) { |
| 66 | if val.IsNull() { |
no test coverage detected