Skip to content

Commit

Permalink
fix: fix ResolveMonomorphised (#2161)
Browse files Browse the repository at this point in the history
resolve through type aliases if underlying type can be resolved to data
  • Loading branch information
worstell authored Jul 25, 2024
1 parent 304510c commit 1b43b73
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions backend/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,28 @@ func (s *Schema) Hash() [sha256.Size]byte {
// ResolveMonomorphised resolves a reference to a monomorphised Data type.
// If a Ref is not found, returns ErrNotFound.
func (s *Schema) ResolveMonomorphised(ref *Ref) (*Data, error) {
out := &Data{}
return s.resolveToDataMonomorphised(ref, nil)
}

err := s.ResolveToType(ref, out)
if err != nil {
// If a ref is not found, returns ErrNotFound
return nil, err
func (s *Schema) resolveToDataMonomorphised(n Node, parent Node) (*Data, error) {
switch typ := n.(type) {
case *Ref:
resolved, ok := s.Resolve(typ).Get()
if !ok {
return nil, fmt.Errorf("unknown ref %s", typ)
}
return s.resolveToDataMonomorphised(resolved, typ)
case *Data:
p, ok := parent.(*Ref)
if !ok {
return nil, fmt.Errorf("expected data node parent to be a ref, got %T", p)
}
return typ.Monomorphise(p)
case *TypeAlias:
return s.resolveToDataMonomorphised(typ.Type, typ)
default:
return nil, fmt.Errorf("expected data or type alias of data, got %T", typ)
}
return out.Monomorphise(ref)
}

// Resolve a reference to a declaration.
Expand Down

0 comments on commit 1b43b73

Please sign in to comment.