Skip to content

Commit 634c231

Browse files
committed
Generate valid C# for unions in templates with non-type args
Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
1 parent 540c165 commit 634c231

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/Generator/Driver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ public void SetupPasses(ILibrary library)
221221
if (Options.IsCSharpGenerator)
222222
TranslationUnitPasses.AddPass(new EqualiseAccessOfOverrideAndBasePass());
223223

224-
TranslationUnitPasses.AddPass(new CheckIgnoredDeclsPass());
225224
TranslationUnitPasses.AddPass(new FlattenAnonymousTypesToFields());
225+
TranslationUnitPasses.AddPass(new CheckIgnoredDeclsPass());
226226
TranslationUnitPasses.AddPass(new MarkUsedClassInternalsPass());
227227

228228
if (Options.IsCSharpGenerator)

src/Generator/Passes/FlattenAnonymousTypesToFields.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ public override bool VisitClassDecl(Class @class)
3131
ReplaceField(@class, i, fieldType);
3232
fieldType.Fields.Clear();
3333
fieldType.ExplicitlyIgnore();
34-
if (fieldType.IsUnion)
35-
@class.HasUnionFields = true;
3634
}
3735

3836
if (@class.Layout == null)
@@ -50,6 +48,8 @@ public override bool VisitClassDecl(Class @class)
5048
ReplaceLayoutField(@class, i, fieldType);
5149
fieldType.Fields.Clear();
5250
fieldType.ExplicitlyIgnore();
51+
if (fieldType.IsUnion)
52+
@class.HasUnionFields = true;
5353
}
5454

5555
return true;

tests/CSharp/CSharp.Tests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void TestUncompilableCode()
3838
new HasProtectedVirtual().Dispose();
3939
new Proprietor(5).Dispose();
4040
new HasCtorWithMappedToEnum<TestFlag>(TestFlag.Flag1).Dispose();
41+
new TestAnonymousMemberNameCollision().Dispose();
4142
using (var testOverrideFromSecondaryBase = new TestOverrideFromSecondaryBase())
4243
{
4344
testOverrideFromSecondaryBase.function();
@@ -1749,12 +1750,6 @@ public void TestTypemapTypedefParam()
17491750
Assert.That(CSharp.CSharp.TakeTypemapTypedefParam(false), Is.False);
17501751
}
17511752

1752-
[Test]
1753-
public void TestAnonymousMemberNameCollision()
1754-
{
1755-
StringAssert.EndsWith(nameof(CSharp.TestAnonymousMemberNameCollision._0.__0), "__0");
1756-
}
1757-
17581753
[Test]
17591754
public void TestStringMarshall()
17601755
{

tests/CSharp/CSharpTemplates.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,12 @@ class ClassWithNonTypeTemplateArgument
832832
{
833833
public:
834834
ClassWithNonTypeTemplateArgument() { }
835+
private:
836+
union
837+
{
838+
int i;
839+
DependentValueFields<TestFlag> d;
840+
};
835841
};
836842

837843
class SpecializationOfClassWithNonTypeTemplateArgument : public ClassWithNonTypeTemplateArgument<0>

0 commit comments

Comments
 (0)