Skip to content

Commit

Permalink
fix: handle typeless objc struct field edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Jun 22, 2024
1 parent 7eb5830 commit e65521a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions types/objc/type_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,13 @@ func decodeStructOrUnion(typ, kind string) string {
// necessary to disambiguate {"x0"@"x1"c}.
if fieldName != "" && rest != "" && strings.HasSuffix(field, `"`) && !strings.HasPrefix(rest, `"`) {
penultQuoteIdx := strings.LastIndex(strings.TrimRight(field, `"`), `"`)
rest = field[penultQuoteIdx:] + rest
field = field[:penultQuoteIdx]
if penultQuoteIdx == -1 {
rest = field + rest
field = "id"
} else {
rest = field[penultQuoteIdx:] + rest
field = field[:penultQuoteIdx]
}
}

if fieldName == "" {
Expand Down
7 changes: 7 additions & 0 deletions types/objc/type_encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ func Test_decodeType(t *testing.T) {
},
want: "struct __cfobservers_t { id slot; struct __cfobservers_t *next; }",
},
{
name: "Test struct 5",
args: args{
encType: "{_UISmallVector<unsigned short, 16UL>=\"_vector\"\"_size\"Q}",
},
want: "struct _UISmallVector<unsigned short, 16UL> { id _vector; unsigned long long _size; }",
},
{
name: "Test union 0",
args: args{
Expand Down

0 comments on commit e65521a

Please sign in to comment.