Skip to content

Commit

Permalink
Fix #285: --alias-enum-members=true shouldn't affect global anonymo…
Browse files Browse the repository at this point in the history
…us enums

The members of anonymous are already accessible outside the enum.
Adding aliases are not necessary.
  • Loading branch information
jacob-carlborg committed Jul 4, 2023
1 parent f722a06 commit d4cbaeb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* [Issue 235](https://github.com/jacob-carlborg/dstep/issues/235): Passing `--` as an argument doesn't work properly
* [Issue 224](https://github.com/jacob-carlborg/dstep/issues/224): Dub assumes default installation path for LLVM on Windows
* [Issue 247](https://github.com/jacob-carlborg/dstep/issues/247): `--alias-enum-members` doesn't work properly for typedef enums
* [Issue 285](https://github.com/jacob-carlborg/dstep/issues/285): `--alias-enum-members=true` shouldn't affect global anonymous enums

## Version 1.0.0
### New/Changed Features
Expand Down
2 changes: 1 addition & 1 deletion dstep/translator/Enum.d
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void translateEnumDef(Output output, Context context, Cursor cursor)
}
};

if ((anonymous && variables) || !cursor.isGlobal || context.options.aliasEnumMembers)
if ((anonymous && variables) || !cursor.isGlobal || (context.options.aliasEnumMembers && !anonymous))
generateEnumAliases(context.globalScope, context, cursor, spelling);
}

Expand Down
26 changes: 26 additions & 0 deletions tests/unit/EnumUnitTests.d
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,32 @@ alias BAZ = Enum.BAZ;
D", options);
}

// Test aliasing of all enum members for anonymous enum.
unittest
{
Options options = { aliasEnumMembers: true };

assertTranslates(
q"C
enum
{
FOO,
BAR,
BAZ,
};
C",
q"D
extern (C):
enum
{
FOO = 0,
BAR = 1,
BAZ = 2
}
D", options);
}

// Test a named enum inside a struct.
unittest
{
Expand Down

0 comments on commit d4cbaeb

Please sign in to comment.