Skip to content

Commit

Permalink
recover multi same field error
Browse files Browse the repository at this point in the history
  • Loading branch information
tsingbx committed Jan 13, 2025
1 parent e1509eb commit 57c5f07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/gogensig/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func testFromDir(t *testing.T, relDir string, gen bool) {
if strings.HasPrefix(name, "_") || strings.HasPrefix(name, ".") {
continue
}
if name != "samefieldname" {
continue
}
t.Run(name, func(t *testing.T) {
testFrom(t, name, dir+"/"+name, gen, nil)
})
Expand Down
13 changes: 11 additions & 2 deletions cmd/gogensig/convert/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,17 @@ func (p *TypeConv) RecordTypeToStruct(recordType *ast.RecordType) (types.Type, e
fields = []*types.Var{maxFld}
}
}
uniFields := p.uniqueFields(fields)
return types.NewStruct(uniFields, nil), nil
var pStruct *types.Struct
defer func() (types.Type, error) {
e := recover()
if e != nil {
newFields := p.uniqueFields(fields)
return types.NewStruct(newFields, nil), nil
}
return pStruct, nil
}()
pStruct = types.NewStruct(fields, nil)
return pStruct, nil
}

func genUniqueName(name string, index int, fieldMap map[string]struct{}) string {
Expand Down

0 comments on commit 57c5f07

Please sign in to comment.