Skip to content

Commit

Permalink
Fix unnecessary enum casts.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Oct 16, 2022
1 parent f921f98 commit 3c97eef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions c_decl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,31 @@ const (
VALUE_2 Enum = -2
VALUE_3 Enum = 1
)
`,
},
{
name: "use enum",
src: `
enum Enum
{
VALUE_1,
VALUE_2,
};
enum Enum foo() {
return VALUE_1;
}
`,
exp: `
type Enum int32
const (
VALUE_1 = Enum(iota)
VALUE_2
)
func foo() Enum {
return VALUE_1
}
`,
},
{
Expand Down
2 changes: 1 addition & 1 deletion convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (g *translator) convertEnum(b *cc.Declaration, typ types.Type, d *cc.EnumSp
next = l.Int() + 1
}
}
vd.Names = append(vd.Names, g.newIdent(e.Token.Value.String(), typ))
vd.Names = append(vd.Names, g.convertIdentWith(e.Token.Value.String(), typ, e).Ident)
}
if len(vd.Names) == 0 {
return nil
Expand Down

0 comments on commit 3c97eef

Please sign in to comment.