Skip to content

Commit

Permalink
cli/daemon: fix rendering of type args in first run (#1620)
Browse files Browse the repository at this point in the history
  • Loading branch information
eandre authored Dec 16, 2024
1 parent 30bbfbc commit 821c94d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cli/daemon/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type schemaRenderer struct {
*jsoniter.Stream
meta *meta.Data
seenDecls map[uint32]*schema.Decl
typeArgs []*schema.Type
}

func (r *schemaRenderer) Render(d *schema.Type) []byte {
Expand Down Expand Up @@ -65,6 +66,12 @@ func (r *schemaRenderer) renderType(typ *schema.Type) {
default:
panic(fmt.Sprintf("unknown literal type %T", v))
}
case *schema.Type_TypeParameter:
if idx := typ.TypeParameter.ParamIdx; len(r.typeArgs) > int(idx) {
r.renderType(r.typeArgs[idx])
} else {
r.WriteNil()
}
case *schema.Type_Config:
// Config is invisible here
r.renderType(typ.Config.Elem)
Expand Down Expand Up @@ -147,6 +154,14 @@ func (r *schemaRenderer) renderNamed(n *schema.Named) {
return
}

// Store type arguments in scope. Restore the previous
// type arguments when we're done.
prevTypeArgs := r.typeArgs
defer func() {
r.typeArgs = prevTypeArgs
}()
r.typeArgs = n.TypeArguments

// Avoid infinite recursion
decl := r.meta.Decls[n.Id]
r.seenDecls[n.Id] = decl
Expand Down

0 comments on commit 821c94d

Please sign in to comment.