Skip to content

Commit 54c6159

Browse files
committed
Fix naming conflicts with nested types and members
Fixes #1353. Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 0f0e174 commit 54c6159

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

src/Generator/Passes/RenamePass.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ protected RenamePass(RenameTargets targets)
4747

4848
public virtual bool Rename(Declaration decl, out string newName)
4949
{
50-
var method = decl as Method;
51-
if (method != null && !method.IsStatic)
50+
if (decl is Method method && !method.IsStatic)
5251
{
5352
Method rootBaseMethod;
54-
var @class = method.OriginalNamespace as Class;
55-
if (@class != null && @class.IsInterface)
53+
if (method.OriginalNamespace is Class @class && @class.IsInterface)
5654
rootBaseMethod = (Method) method.OriginalFunction;
5755
else
5856
rootBaseMethod = method.GetRootBaseMethod();
@@ -63,8 +61,7 @@ public virtual bool Rename(Declaration decl, out string newName)
6361
}
6462
}
6563

66-
var property = decl as Property;
67-
if (property != null && !property.IsStatic)
64+
if (decl is Property property && !property.IsStatic)
6865
{
6966
var rootBaseProperty = ((Class) property.Namespace).GetBasePropertyByName(property);
7067
if (rootBaseProperty != null && rootBaseProperty != property)
@@ -74,6 +71,16 @@ public virtual bool Rename(Declaration decl, out string newName)
7471
}
7572
}
7673

74+
if (!(decl is ClassTemplateSpecialization) &&
75+
!string.IsNullOrEmpty(decl.Name) && AreThereConflicts(decl, decl.Name))
76+
{
77+
char initialLetter = char.IsUpper(decl.Name[0]) ?
78+
char.ToLowerInvariant(decl.Name[0]) :
79+
char.ToUpperInvariant(decl.Name[0]);
80+
newName = initialLetter + decl.Name.Substring(1);
81+
return true;
82+
}
83+
7784
newName = decl.Name;
7885
return false;
7986
}

tests/Common/Common.Tests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ public void TestProperties()
567567
prop.StartWithVerb = 5;
568568

569569
Assert.That(prop.Contains('a'), Is.EqualTo(prop.Contains("a")));
570+
571+
Assert.That(prop.conflict, Is.EqualTo(CommonTest.TestProperties.Conflict.Value1));
572+
prop.conflict = CommonTest.TestProperties.Conflict.Value2;
573+
Assert.That(prop.conflict, Is.EqualTo(CommonTest.TestProperties.Conflict.Value2));
570574
}
571575
using (var prop = new HasOverridenSetter())
572576
{

tests/Common/Common.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ SomeNamespace::AbstractClass::~AbstractClass()
541541
}
542542

543543
TestProperties::TestProperties() : Field(0), _refToPrimitiveInSetter(0),
544-
_getterAndSetterWithTheSameName(0), _setterReturnsBoolean(0), _virtualSetterReturnsBoolean(0)
544+
_getterAndSetterWithTheSameName(0), _setterReturnsBoolean(0),
545+
_virtualSetterReturnsBoolean(0), _conflict(Conflict::Value1)
545546
{
546547
}
547548

@@ -550,7 +551,8 @@ TestProperties::TestProperties(const TestProperties& other) : Field(other.Field)
550551
_refToPrimitiveInSetter(other._refToPrimitiveInSetter),
551552
_getterAndSetterWithTheSameName(other._getterAndSetterWithTheSameName),
552553
_setterReturnsBoolean(other._setterReturnsBoolean),
553-
_virtualSetterReturnsBoolean(other._virtualSetterReturnsBoolean)
554+
_virtualSetterReturnsBoolean(other._virtualSetterReturnsBoolean),
555+
_conflict(other._conflict)
554556
{
555557
}
556558

@@ -693,6 +695,16 @@ bool TestProperties::contains(const char* str)
693695
return true;
694696
}
695697

698+
TestProperties::Conflict TestProperties::GetConflict()
699+
{
700+
return _conflict;
701+
}
702+
703+
void TestProperties::SetConflict(Conflict conflict)
704+
{
705+
_conflict = conflict;
706+
}
707+
696708
HasOverridenSetter::HasOverridenSetter()
697709
{
698710
}

tests/Common/Common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,12 @@ struct DLL_API TestProperties
590590
Value2
591591
};
592592

593+
enum class Conflict
594+
{
595+
Value1,
596+
Value2
597+
};
598+
593599
TestProperties();
594600
TestProperties(const TestProperties& other);
595601
int Field;
@@ -636,12 +642,16 @@ struct DLL_API TestProperties
636642
bool contains(char c);
637643
bool contains(const char* str);
638644

645+
Conflict GetConflict();
646+
void SetConflict(Conflict _conflict);
647+
639648
private:
640649
int FieldValue;
641650
double _refToPrimitiveInSetter;
642651
int _getterAndSetterWithTheSameName;
643652
int _setterReturnsBoolean;
644653
int _virtualSetterReturnsBoolean;
654+
Conflict _conflict;
645655
};
646656

647657
class DLL_API HasOverridenSetter : public TestProperties

0 commit comments

Comments
 (0)