generate: make branch functions generic, take in ~ of base type

This commit is contained in:
Sasha Koshka 2025-08-06 18:38:30 -04:00
parent 12142706e1
commit fa4f591126

View File

@ -589,11 +589,11 @@ func (this *Generator) generateDecodeBranchCall(typ Type, valueSource, tagSource
// generateDecodeBranch generates an aggregate decoder function definition for a // generateDecodeBranch generates an aggregate decoder function definition for a
// specified type. It assumes that hash == HashType(typ). // specified type. It assumes that hash == HashType(typ).
func (this *Generator) generateDecodeBranch(hash [16]byte, typ Type) (n int, err error) { func (this *Generator) generateDecodeBranch(hash [16]byte, typ Type) (n int, err error) {
nn, err := this.iprintf("\nfunc %s(this *", this.decodeBranchName(hash)) nn, err := this.iprintf("\nfunc %s[T ~", this.decodeBranchName(hash))
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
nn, err = this.generateType(typ) nn, err = this.generateType(typ)
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
nn, err = this.printf(", decoder *tape.Decoder, tag tape.Tag) (nn int, err error) {\n") nn, err = this.printf("](this *T, decoder *tape.Decoder, tag tape.Tag) (nn int, err error) {\n")
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
this.push() this.push()
@ -632,7 +632,7 @@ func (this *Generator) generateDecodeBranch(hash [16]byte, typ Type) (n int, err
this.pop() this.pop()
nn, err = this.iprintf("}\n") nn, err = this.iprintf("}\n")
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
nn, err = this.iprintf("return n, nil") nn, err = this.iprintf("return n, nil\n")
n += nn; if err != nil { return n, err } n += nn; if err != nil { return n, err }
return n, nil return n, nil
} }