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
10 changes: 2 additions & 8 deletions runtime/sam/expr/function/downcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (d *downcast) downcast(b *scode.Builder, typ super.Type, bytes scode.Bytes,
superBytes, _ := superType.Deref(d.sctx, bytes)
return d.downcast(b, superType.Type, superBytes, to)
}
typ = super.TypeUnder(typ)
switch to := to.(type) {
case *super.TypeRecord:
return d.toRecord(b, typ, bytes, to)
Expand All @@ -58,7 +59,7 @@ func (d *downcast) downcast(b *scode.Builder, typ super.Type, bytes scode.Bytes,
case *super.TypeError:
return d.toError(b, typ, bytes, to)
case *super.TypeNamed:
return d.toNamed(b, typ, bytes, to)
return d.downcast(b, typ, bytes, to.Type)
case *super.TypeFusion:
// Can't downcast to a super type
return false
Expand Down Expand Up @@ -171,13 +172,6 @@ func (d *downcast) toError(b *scode.Builder, typ super.Type, bytes scode.Bytes,
return false
}

func (d *downcast) toNamed(b *scode.Builder, typ super.Type, bytes scode.Bytes, to *super.TypeNamed) bool {
if namedType, ok := typ.(*super.TypeNamed); ok {
return d.downcast(b, namedType.Type, bytes, to.Type)
}
return false
}

func (d *downcast) subTypeOf(typ super.Type, bytes scode.Bytes, types []super.Type) int {
// XXX TBD we should make a subtype() function that returns true if a type is
// a subtype of another and use that here and expose it to the language.
Expand Down
15 changes: 15 additions & 0 deletions runtime/ztests/expr/function/defuse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,18 @@ input: &input |

output: *input

---

spq: fuse | defuse(this)

input: &input |
1::=p1
{a:{b:1::=r1}::=r2}::=r3
[[1::=a1]::=a2]::=a3
|[|[1::=s1]|::=s2]|::=s3
|{1::=m1:2::=m2}|::=m3
"a"::(en1=enum(a,b))
1::=n1::(n2=n1|(n3=string))
error(1::=er1)::=er2

output: *input
Loading