Skip to content

Commit d2ebabb

Browse files
committed
Restore mapping of overloaded getters to methods
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 499ecc3 commit d2ebabb

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

src/Generator/Passes/GetterSetterToPropertyPass.cs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -169,25 +169,16 @@ private static void ProcessProperties(Class @class, HashSet<Property> newPropert
169169
@class.Properties.Remove(property);
170170
continue;
171171
}
172-
173-
foreach (var method in @class.Methods.Where(
174-
m => m.IsGenerated && m.Name == property.Name))
175-
{
176-
var oldName = method.Name;
177-
method.Name = $@"get{char.ToUpperInvariant(method.Name[0])}{
178-
method.Name.Substring(1)}";
179-
Diagnostics.Debug("Method {0}::{1} renamed to {2}",
180-
method.Namespace.Name, oldName, method.Name);
181-
}
182-
foreach (var @event in @class.Events.Where(
183-
e => e.Name == property.Name))
172+
if (property.SetMethod == null &&
173+
@class.GetOverloads(property.GetMethod).Any(
174+
m => m != property.GetMethod && !m.Ignore))
184175
{
185-
var oldName = @event.Name;
186-
@event.Name = $@"on{char.ToUpperInvariant(@event.Name[0])}{
187-
@event.Name.Substring(1)}";
188-
Diagnostics.Debug("Event {0}::{1} renamed to {2}",
189-
@event.Namespace.Name, oldName, @event.Name);
176+
property.GetMethod.GenerationKind = GenerationKind.Generate;
177+
@class.Properties.Remove(property);
178+
continue;
190179
}
180+
181+
RenameConflictingMethods(@class, property);
191182
CombineComments(property);
192183
}
193184
}
@@ -211,6 +202,28 @@ private static Property GetBaseProperty(Class @class, Property @override)
211202
return null;
212203
}
213204

205+
private static void RenameConflictingMethods(Class @class, Property property)
206+
{
207+
foreach (var method in @class.Methods.Where(
208+
m => m.IsGenerated && m.Name == property.Name))
209+
{
210+
var oldName = method.Name;
211+
method.Name = $@"get{char.ToUpperInvariant(method.Name[0])}{
212+
method.Name.Substring(1)}";
213+
Diagnostics.Debug("Method {0}::{1} renamed to {2}",
214+
method.Namespace.Name, oldName, method.Name);
215+
}
216+
foreach (var @event in @class.Events.Where(
217+
e => e.Name == property.Name))
218+
{
219+
var oldName = @event.Name;
220+
@event.Name = $@"on{char.ToUpperInvariant(@event.Name[0])}{
221+
@event.Name.Substring(1)}";
222+
Diagnostics.Debug("Event {0}::{1} renamed to {2}",
223+
@event.Namespace.Name, oldName, @event.Name);
224+
}
225+
}
226+
214227
private static string GetReadWritePropertyName(INamedDecl getter, string afterSet)
215228
{
216229
string name = GetPropertyName(getter.Name);

tests/CSharp/CSharp.Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ public class Inter : SimpleInterface
13301330

13311331
private class OverrideVirtualTemplate : VirtualTemplate<int>
13321332
{
1333-
public override int Function => 10;
1333+
public override int Function() => 10;
13341334
}
13351335

13361336
[Test]

tests/Common/Common.Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ public void TestProperties()
517517
prop.VirtualSetterReturnsBoolean = 45;
518518
Assert.That(prop.VirtualSetterReturnsBoolean, Is.EqualTo(45));
519519

520-
Assert.That(prop.nestedEnum, Is.EqualTo(5));
521-
Assert.That(prop.GetNestedEnum(55), Is.EqualTo(55));
520+
Assert.That(prop.nestedEnum(), Is.EqualTo(5));
521+
Assert.That(prop.nestedEnum(55), Is.EqualTo(55));
522522

523523
Assert.That(prop.Get32Bit, Is.EqualTo(10));
524524
}

0 commit comments

Comments
 (0)