(args []super.Value)
| 23 | } |
| 24 | |
| 25 | func (c *cast) Call(args []super.Value) super.Value { |
| 26 | from, to := args[0], args[1] |
| 27 | if from.IsError() { |
| 28 | return from |
| 29 | } |
| 30 | switch toUnder := to.Under(); toUnder.Type().ID() { |
| 31 | case super.IDString: |
| 32 | typ, err := c.sctx.LookupTypeNamed(toUnder.AsString(), super.TypeUnder(from.Type())) |
| 33 | if err != nil { |
| 34 | return c.sctx.WrapError("cannot cast to named type: "+err.Error(), from) |
| 35 | } |
| 36 | return super.NewValue(typ, from.Bytes()) |
| 37 | case super.IDType: |
| 38 | typ, err := c.sctx.LookupByValue(toUnder.Bytes()) |
| 39 | if err != nil { |
| 40 | panic(err) |
| 41 | } |
| 42 | val, _ := c.Cast(from, typ) |
| 43 | return val |
| 44 | } |
| 45 | return c.sctx.WrapError("cast target must be a type or type name", to) |
| 46 | } |
| 47 | |
| 48 | func (c *cast) Cast(from super.Value, to super.Type) (super.Value, bool) { |
| 49 | from = from.Deunion() |
nothing calls this directly
no test coverage detected