diff --git a/runtime/sam/expr/function/downcast.go b/runtime/sam/expr/function/downcast.go index da9a99f9f..04697cd6c 100644 --- a/runtime/sam/expr/function/downcast.go +++ b/runtime/sam/expr/function/downcast.go @@ -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) @@ -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 @@ -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. diff --git a/runtime/ztests/expr/function/defuse.yaml b/runtime/ztests/expr/function/defuse.yaml index 286b59189..2822eee1e 100644 --- a/runtime/ztests/expr/function/defuse.yaml +++ b/runtime/ztests/expr/function/defuse.yaml @@ -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