Skip to content

Commit

Permalink
Fixed ambiguous code when a nested type and a property-like method wi…
Browse files Browse the repository at this point in the history
…th overloads have the same name

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information
ddobrev authored and tritao committed Mar 6, 2019
1 parent d5ee92b commit 9cad946
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/Generator/Passes/GetterSetterToPropertyPass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public void GenerateProperties()
foreach (Method getter in
from getter in getters
where getter.IsGenerated &&
getter.SynthKind != FunctionSynthKind.ComplementOperator
getter.SynthKind != FunctionSynthKind.ComplementOperator &&
((Class) getter.Namespace).Methods.All(
m => m == getter || !m.IsGenerated || m.Name != getter.Name ||
m.Parameters.Count(p => p.Kind == ParameterKind.Regular) == 0)
select getter)
{
// Make it a read-only property
Expand Down
2 changes: 1 addition & 1 deletion tests/CSharp/CSharp.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,6 @@ public class Inter : SimpleInterface

private class OverrideVirtualTemplate : VirtualTemplate<int>
{
public override int Function => 10;
public override int Function() => 10;
}
}
35 changes: 20 additions & 15 deletions tests/Common/Common.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,25 +480,30 @@ public void TestFunctions()
public void TestProperties()
{
// Test field property
var prop = new TestProperties();
Assert.That(prop.Field, Is.EqualTo(0));
prop.Field = 10;
Assert.That(prop.Field, Is.EqualTo(10));
using (var prop = new TestProperties())
{
Assert.That(prop.Field, Is.EqualTo(0));
prop.Field = 10;
Assert.That(prop.Field, Is.EqualTo(10));

// Test getter/setter property
prop.Field = 20;
Assert.That(prop.FieldValue, Is.EqualTo(20));
prop.FieldValue = 10;
Assert.That(prop.FieldValue, Is.EqualTo(10));

// Test getter/setter property
prop.Field = 20;
Assert.That(prop.FieldValue, Is.EqualTo(20));
prop.FieldValue = 10;
Assert.That(prop.FieldValue, Is.EqualTo(10));
prop.GetterAndSetterWithTheSameName = 25;
Assert.That(prop.GetterAndSetterWithTheSameName, Is.EqualTo(25));

prop.GetterAndSetterWithTheSameName = 25;
Assert.That(prop.GetterAndSetterWithTheSameName, Is.EqualTo(25));
prop.SetterReturnsBoolean = 35;
Assert.That(prop.SetterReturnsBoolean, Is.EqualTo(35));

prop.SetterReturnsBoolean = 35;
Assert.That(prop.SetterReturnsBoolean, Is.EqualTo(35));
prop.VirtualSetterReturnsBoolean = 45;
Assert.That(prop.VirtualSetterReturnsBoolean, Is.EqualTo(45));

prop.VirtualSetterReturnsBoolean = 45;
Assert.That(prop.VirtualSetterReturnsBoolean, Is.EqualTo(45));
Assert.That(prop.nestedEnum(), Is.EqualTo(5));
Assert.That(prop.nestedEnum(55), Is.EqualTo(55));
}
}

[Test]
Expand Down
10 changes: 10 additions & 0 deletions tests/Common/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,16 @@ bool TestProperties::setVirtualSetterReturnsBoolean(int value)
return changed;
}

int TestProperties::nestedEnum()
{
return 5;
}

int TestProperties::nestedEnum(int i)
{
return i;
}

HasOverridenSetter::HasOverridenSetter()
{
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,12 @@ DLL_API int Function()
struct DLL_API TestProperties
{
public:
enum class NestedEnum
{
Value1,
Value2
};

TestProperties();
int Field;

Expand All @@ -600,6 +606,9 @@ struct DLL_API TestProperties

virtual int virtualSetterReturnsBoolean();
virtual bool setVirtualSetterReturnsBoolean(int value);

int nestedEnum();
int nestedEnum(int i);
private:
int FieldValue;
double _refToPrimitiveInSetter;
Expand Down

0 comments on commit 9cad946

Please sign in to comment.