Skip to content

Commit 9cad946

Browse files
ddobrevtritao
authored andcommitted
Fixed ambiguous code when a nested type and a property-like method with overloads have the same name
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent d5ee92b commit 9cad946

File tree

5 files changed

+44
-17
lines changed

5 files changed

+44
-17
lines changed

src/Generator/Passes/GetterSetterToPropertyPass.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ public void GenerateProperties()
3838
foreach (Method getter in
3939
from getter in getters
4040
where getter.IsGenerated &&
41-
getter.SynthKind != FunctionSynthKind.ComplementOperator
41+
getter.SynthKind != FunctionSynthKind.ComplementOperator &&
42+
((Class) getter.Namespace).Methods.All(
43+
m => m == getter || !m.IsGenerated || m.Name != getter.Name ||
44+
m.Parameters.Count(p => p.Kind == ParameterKind.Regular) == 0)
4245
select getter)
4346
{
4447
// Make it a read-only property

tests/CSharp/CSharp.Tests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,6 @@ public class Inter : SimpleInterface
12651265

12661266
private class OverrideVirtualTemplate : VirtualTemplate<int>
12671267
{
1268-
public override int Function => 10;
1268+
public override int Function() => 10;
12691269
}
12701270
}

tests/Common/Common.Tests.cs

+20-15
Original file line numberDiff line numberDiff line change
@@ -480,25 +480,30 @@ public void TestFunctions()
480480
public void TestProperties()
481481
{
482482
// Test field property
483-
var prop = new TestProperties();
484-
Assert.That(prop.Field, Is.EqualTo(0));
485-
prop.Field = 10;
486-
Assert.That(prop.Field, Is.EqualTo(10));
483+
using (var prop = new TestProperties())
484+
{
485+
Assert.That(prop.Field, Is.EqualTo(0));
486+
prop.Field = 10;
487+
Assert.That(prop.Field, Is.EqualTo(10));
488+
489+
// Test getter/setter property
490+
prop.Field = 20;
491+
Assert.That(prop.FieldValue, Is.EqualTo(20));
492+
prop.FieldValue = 10;
493+
Assert.That(prop.FieldValue, Is.EqualTo(10));
487494

488-
// Test getter/setter property
489-
prop.Field = 20;
490-
Assert.That(prop.FieldValue, Is.EqualTo(20));
491-
prop.FieldValue = 10;
492-
Assert.That(prop.FieldValue, Is.EqualTo(10));
495+
prop.GetterAndSetterWithTheSameName = 25;
496+
Assert.That(prop.GetterAndSetterWithTheSameName, Is.EqualTo(25));
493497

494-
prop.GetterAndSetterWithTheSameName = 25;
495-
Assert.That(prop.GetterAndSetterWithTheSameName, Is.EqualTo(25));
498+
prop.SetterReturnsBoolean = 35;
499+
Assert.That(prop.SetterReturnsBoolean, Is.EqualTo(35));
496500

497-
prop.SetterReturnsBoolean = 35;
498-
Assert.That(prop.SetterReturnsBoolean, Is.EqualTo(35));
501+
prop.VirtualSetterReturnsBoolean = 45;
502+
Assert.That(prop.VirtualSetterReturnsBoolean, Is.EqualTo(45));
499503

500-
prop.VirtualSetterReturnsBoolean = 45;
501-
Assert.That(prop.VirtualSetterReturnsBoolean, Is.EqualTo(45));
504+
Assert.That(prop.nestedEnum(), Is.EqualTo(5));
505+
Assert.That(prop.nestedEnum(55), Is.EqualTo(55));
506+
}
502507
}
503508

504509
[Test]

tests/Common/Common.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,16 @@ bool TestProperties::setVirtualSetterReturnsBoolean(int value)
586586
return changed;
587587
}
588588

589+
int TestProperties::nestedEnum()
590+
{
591+
return 5;
592+
}
593+
594+
int TestProperties::nestedEnum(int i)
595+
{
596+
return i;
597+
}
598+
589599
HasOverridenSetter::HasOverridenSetter()
590600
{
591601
}

tests/Common/Common.h

+9
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,12 @@ DLL_API int Function()
578578
struct DLL_API TestProperties
579579
{
580580
public:
581+
enum class NestedEnum
582+
{
583+
Value1,
584+
Value2
585+
};
586+
581587
TestProperties();
582588
int Field;
583589

@@ -600,6 +606,9 @@ struct DLL_API TestProperties
600606

601607
virtual int virtualSetterReturnsBoolean();
602608
virtual bool setVirtualSetterReturnsBoolean(int value);
609+
610+
int nestedEnum();
611+
int nestedEnum(int i);
603612
private:
604613
int FieldValue;
605614
double _refToPrimitiveInSetter;

0 commit comments

Comments
 (0)