Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions runtime/sam/expr/function/downcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ func (d *downcast) downcast(typ super.Type, bytes scode.Bytes, to super.Type) (s
return d.toEnum(typ, bytes, to)
case *super.TypeError:
return d.toError(typ, bytes, to)
case *super.TypeNamed:
return d.toNamed(typ, bytes, to)
case *super.TypeFusion:
// Can't downcast to a super type
return super.Value{}, d.sctx.WrapError("downcast: cannot downcast to a fusion type", super.NewValue(typ, bytes)).Ptr()
Expand Down Expand Up @@ -278,38 +276,6 @@ func (d *downcast) toError(typ super.Type, bytes scode.Bytes, to *super.TypeErro
return super.Value{}, d.errMismatch(typ, bytes, to)
}

func (d *downcast) toNamed(typ super.Type, bytes scode.Bytes, to *super.TypeNamed) (super.Value, *super.Value) {
if unionType, ok := typ.(*super.TypeUnion); ok {
typ, bytes = deunion(typ, bytes)
// If we are casting a union type to a named, we need to look through the
// union for the named type in question since type fusion fuses named
// types by name. Then when we find the name, we need to form the subtype
// from the union options present.
for _, t := range unionType.Types {
if named, ok := t.(*super.TypeNamed); ok && named.Name == to.Name {
typ, bytes = deunion(typ, bytes)
return super.NewValue(to, bytes), nil
}
}
return super.Value{}, d.errMismatch(typ, bytes, to)
}
if fromType, ok := typ.(*super.TypeNamed); ok {
if fromType.Name != to.Name {
return super.Value{}, d.errMismatch(typ, bytes, to)
}
val, errVal := d.downcast(fromType.Type, bytes, to.Type)
if errVal != nil {
return super.Value{}, errVal
}
return super.NewValue(to, val.Bytes()), errVal
}
val, errVal := d.downcast(typ, bytes, to.Type)
if errVal != nil {
return super.Value{}, errVal
}
return super.NewValue(to, val.Bytes()), errVal
}

func (d *downcast) errNonOptionNone(to super.Type) *super.Value {
return d.sctx.NewErrorf("downcast: none value in non-option type: %s", sup.FormatType(to)).Ptr()
}
Expand Down
9 changes: 0 additions & 9 deletions runtime/sam/expr/function/upcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func (u *Upcast) upcast(b *scode.Builder, typ super.Type, bytes scode.Bytes, to
return u.toEnum(b, typ, bytes, to)
case *super.TypeError:
return u.toError(b, typ, bytes, to)
case *super.TypeNamed:
return u.toNamed(b, typ, bytes, to)
case *super.TypeFusion:
return u.toFusion(b, typ, bytes, to)
default:
Expand Down Expand Up @@ -229,10 +227,3 @@ func (u *Upcast) toError(b *scode.Builder, typ super.Type, bytes scode.Bytes, to
}
return false
}

func (u *Upcast) toNamed(b *scode.Builder, typ super.Type, bytes scode.Bytes, to *super.TypeNamed) bool {
if named, ok := typ.(*super.TypeNamed); ok {
return u.upcast(b, named.Type, bytes, to.Type)
}
return false
}
16 changes: 0 additions & 16 deletions runtime/vam/expr/function/downcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ func (d *downcast) downcast(vec vector.Any, to super.Type) vector.Any {
return d.toEnum(vec, to)
case *super.TypeError:
return d.toError(vec, to)
case *super.TypeNamed:
return d.toNamed(vec, to)
case *super.TypeFusion:
return d.err(vector.NewWrappedError(d.sctx, "downcast: cannot downcast to a fusion type", vec))
default:
Expand Down Expand Up @@ -445,20 +443,6 @@ func (d *downcast) toError(vec vector.Any, to *super.TypeError) vector.Any {
return d.errMismatch(vec, to)
}

func (d *downcast) toNamed(vec vector.Any, to *super.TypeNamed) vector.Any {
if fromVec, ok := vec.(*vector.Named); ok {
if fromVec.Typ != to {
return d.errMismatch(vec, to)
}
return vec
}
out := d.downcast(vec, to.Type)
if isErrDowncast(out) {
return out
}
return vector.NewNamed(to, out)
}

func (d *downcast) deunion(vec vector.Any, f func(vector.Any) vector.Any) vector.Any {
return vector.Apply(true, func(vecs ...vector.Any) vector.Any {
return f(vecs[0])
Expand Down
14 changes: 0 additions & 14 deletions runtime/vam/expr/function/upcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ func (u *Upcast) upcast(vec vector.Any, to super.Type) vector.Any {
return u.toEnum(vec, to)
case *super.TypeError:
return u.toError(vec, to)
case *super.TypeNamed:
return u.toNamed(vec, to)
case *super.TypeFusion:
return u.toFusion(vec, to)
default:
Expand Down Expand Up @@ -273,18 +271,6 @@ func (u *Upcast) toError(vec vector.Any, to *super.TypeError) vector.Any {
return vector.NewError(to, values)
}

func (u *Upcast) toNamed(vec vector.Any, to *super.TypeNamed) vector.Any {
namedVec, ok := vec.(*vector.Named)
if !ok {
return nil
}
vec = u.upcast(namedVec.Any, to.Type)
if vec == nil {
return nil
}
return vector.NewNamed(to, vec)
}

func (u *Upcast) toFusion(vec vector.Any, to *super.TypeFusion) vector.Any {
values := u.upcast(vec, to.Type)
if values == nil {
Expand Down
6 changes: 3 additions & 3 deletions runtime/ztests/expr/function/downcast.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ input: |
["foo"::(int64|string),<foo>]

output: |
error({message:"downcast: type mismatch to foo",on:1})
error({message:"downcast: type mismatch to foo",on:1})
type foo=int64
1::foo
1::foo
error({message:"downcast: type mismatch to bar",on:1::foo})
error({message:"downcast: type mismatch to int64",on:"foo"})
error({message:"downcast: type mismatch to foo",on:"foo"})
22 changes: 10 additions & 12 deletions runtime/ztests/expr/function/upcast.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,41 @@ input: |
["x"::enum(x,y),<fusion(enum(y,z))>]
[fusion(1::(int64|string),<int64>),<fusion(int64|string)>]
type n31=int64
type n32=int64
[1::n31,<n32>]
[1::n31,<n31>]
type n41=int64
type n42={b:n41}
type n43={a:n42}
type n46=int64
type n45={b:n46}
type n44={a:n45}
[{a:{b:1}}::n43,<n44>]
[{a:{b:1}}::n44,<n44>]
type n51=int64
type n52=[n51]
type n53=[n52]
type n56=int64
type n55=[n56]
type n54=[n55]
[[[1]]::n53,<n54>]
[[[1]]::n54,<n54>]
type n61=int64
type n62=set[n61]
type n63=set[n62]
type n66=int64
type n65=set[n66]
type n64=set[n65]
[set[set[1]]::n63,<n64>]
[set[set[1]]::n64,<n64>]
type n71=int64
type n72=int64
type n73=map{n71:n72}
type n75=int64
type n76=int64
type n74=map{n75:n76}
[map{1:2}::n73,<n74>]
[map{1:2}::n74,<n74>]
type n82=int64
type n81=n82
type n83=string
[1::n81,<n81|n83>]
type n91=enum(a,b)
type n92=enum(a,b)
["a"::n91,<n92>]
["a"::n91,<n91>]
type n101=int64
[1::n101,<fusion(n101|string)>]

Expand All @@ -73,8 +71,8 @@ output: |
fusion("x"::enum(x,y,z),<enum(x,y)>)
error({message:"upcast: value not a subtype of fusion(enum(y,z))",on:"x"::enum(x,y)})
fusion(1::(int64|string),<int64|string>)
type n32=int64
1::n32
type n31=int64
1::n31
type n46=int64
type n45={b:n46}
type n44={a:n45}
Expand All @@ -95,8 +93,8 @@ output: |
type n81=n82
type n83=string
1::n81::(n81|n83)
type n92=enum(a,b)
"a"::n92
type n91=enum(a,b)
"a"::n91
type n101=int64
fusion(1::n101::(n101|string),<n101>)

Expand Down
Loading