MCPcopy Create free account
hub / github.com/brimdata/super / Call

Method Call

runtime/sam/expr/function/cast.go:25–46  ·  view source on GitHub ↗
(args []super.Value)

Source from the content-addressed store, hash-verified

23}
24
25func (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
48func (c *cast) Cast(from super.Value, to super.Type) (super.Value, bool) {
49 from = from.Deunion()

Callers

nothing calls this directly

Calls 13

CastMethod · 0.95
TypeUnderFunction · 0.92
NewValueFunction · 0.92
IsErrorMethod · 0.80
UnderMethod · 0.80
LookupTypeNamedMethod · 0.80
AsStringMethod · 0.80
WrapErrorMethod · 0.80
LookupByValueMethod · 0.80
IDMethod · 0.65
TypeMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected