From 235e355d8d78743b860f79ddc3c7c7dac8f7cf21 Mon Sep 17 00:00:00 2001 From: Alexander Komarov Date: Thu, 12 Nov 2026 00:19:43 +0400 Subject: [PATCH 1/2] C# -> VB: Add Overloads when an inherited member has the same name A VB method or property without Overloads hides every inherited member of the same name, while C# only hides the same signature. The converter added Overloads only next to an override of the same name in the same type, so: - `Equals(Item x, Item y)` of an IEqualityComparer hid Object.Equals(Object, Object), and `x.Name == y.Name` converted to `Equals(x.Name, y.Name)` bound to the comparer's own method (BC30311); - a derived indexer hid the base indexer (`this["a"]` failed to compile); - in a derived interface, `Run(string)` hid `Run(int)` of the base interface, and with Option Strict Off `d.Run(1)` silently called `Run("1")`. Overloads is now added to an ordinary method or a non-explicit property (including indexers, compared by metadata name "Item") when an accessible member of the same kind and name (ignoring case) is inherited from a base class or, for an interface, a base interface. Members of a static class that becomes a Module are skipped: a Module inherits nothing and doesn't allow Overloads (BC36917). --- CHANGELOG.md | 1 + CodeConverter/VB/NodesVisitor.cs | 39 ++- .../CSToVB/OverloadsTests.cs | 86 ++++++ Tests/VB/MemberTests.cs | 271 ++++++++++++++++++ 4 files changed, 391 insertions(+), 6 deletions(-) create mode 100644 Tests/TestData/SelfVerifyingTests/CSToVB/OverloadsTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 62d640b16..9f8d1dc8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) * Don't emit Me on the first parameter of an extension method - [#1118](https://github.com/icsharpcode/CodeConverter/issues/1118) * Truncate towards zero when converting a fractional number to an integer, instead of inheriting VB's rounding - [#1021](https://github.com/icsharpcode/CodeConverter/issues/1021) +* Add Overloads to methods, properties and indexers when an inherited member has the same name ## [10.0.2] - 2026-11-08 diff --git a/CodeConverter/VB/NodesVisitor.cs b/CodeConverter/VB/NodesVisitor.cs index f988e5ea1..93096c828 100644 --- a/CodeConverter/VB/NodesVisitor.cs +++ b/CodeConverter/VB/NodesVisitor.cs @@ -538,10 +538,7 @@ public override VisualBasicSyntaxNode VisitMethodDeclaration(CSSyntax.MethodDecl if (!((CS.CSharpSyntaxTree)node.SyntaxTree).HasUsingDirective("System.Runtime.CompilerServices")) _extraImports.Add(nameof(System) + "." + nameof(System.Runtime) + "." + nameof(System.Runtime.CompilerServices)); } - var needsOverloads = methodInfo?.ContainingType?.GetMembers(methodInfo.Name).Except(methodInfo.Yield()).Any(m => m.IsOverride); - if (needsOverloads == true) { - modifiers = modifiers.Add(SyntaxFactory.Token(SyntaxKind.OverloadsKeyword)); - } + modifiers = WithOverloadsIfNeeded(modifiers, node, methodInfo); var implementsClause = methodInfo == null ? null : CreateImplementsClauseSyntaxOrNull(methodInfo, ref id); if (isVoidSub) { var stmt = SyntaxFactory.SubStatement( @@ -566,6 +563,36 @@ public override VisualBasicSyntaxNode VisitMethodDeclaration(CSSyntax.MethodDecl } } + /// + /// A VB method or property declared without Overloads, Overrides or Shadows hides every accessible inherited member + /// of the same name (case-insensitively, BC40003/BC40004), also in interfaces, whereas C# only hides the same signature. + /// Overloads keeps the C# lookup. Once one member of a name is Overloads or Overrides, VB requires Overloads on the + /// others in the type (BC31409). A Module inherits nothing and doesn't allow Overloads (BC36917). + /// https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/modifiers/overloads + /// + private SyntaxTokenList WithOverloadsIfNeeded(SyntaxTokenList modifiers, CSSyntax.MemberDeclarationSyntax node, ISymbol member) + { + if (member == null || modifiers.Any(SyntaxKind.OverloadsKeyword) || GetMemberContext(node) == TokenContext.MemberInModule) return modifiers; + var hasOverrideOfSameName = member.ContainingType.GetMembers(member.Name).Except(member.Yield()).Any(m => m.IsOverride); + var needsOverloads = hasOverrideOfSameName || !member.IsOverride && IsOverloadable(member) && HasAccessibleInheritedNamesake(member); + return needsOverloads ? modifiers.Add(SyntaxFactory.Token(SyntaxKind.OverloadsKeyword)) : modifiers; + } + + private static bool IsOverloadable(ISymbol member) => + member is IMethodSymbol { MethodKind: MethodKind.Ordinary } or IPropertySymbol { ExplicitInterfaceImplementations.IsEmpty: true }; + + /// Compares metadata names: an indexer is "this[]" in C# and "Item" in VB. + private bool HasAccessibleInheritedNamesake(ISymbol member) + { + var containingType = member.ContainingType; + IEnumerable inheritedTypes = containingType.TypeKind == TypeKind.Interface ? containingType.AllInterfaces : containingType.GetBaseTypes(); + return inheritedTypes + .SelectMany(t => t.GetMembers()) + .Any(m => m.Kind == member.Kind && IsOverloadable(m) + && string.Equals(m.MetadataName, member.MetadataName, StringComparison.OrdinalIgnoreCase) + && _semanticModel.Compilation.IsSymbolAccessibleWithin(m, containingType)); + } + /// /// PERF: Computational complexity high due to starting with all members and narrowing down /// @@ -609,7 +636,7 @@ private ImplementsClauseSyntax CreateImplementsClauseSyntax(IEnumerable public override VisualBasicSyntaxNode VisitPropertyDeclaration(CSSyntax.PropertyDeclarationSyntax node) { var id = _commonConversions.ConvertIdentifier(node.Identifier); - var modifiers = CommonConversions.ConvertModifiers(node.Modifiers, GetMemberContext(node)); + var modifiers = WithOverloadsIfNeeded(CommonConversions.ConvertModifiers(node.Modifiers, GetMemberContext(node)), node, _semanticModel.GetDeclaredSymbol(node)); var initializer = node.Initializer == null ? null : SyntaxFactory.EqualsValue((ExpressionSyntax)_commonConversions.ConvertTopLevelExpression(node.Initializer.Value)); return ConvertPropertyBlock(node, id, modifiers, null, node.ExpressionBody, initializer); @@ -618,7 +645,7 @@ public override VisualBasicSyntaxNode VisitPropertyDeclaration(CSSyntax.Property public override VisualBasicSyntaxNode VisitIndexerDeclaration(CSSyntax.IndexerDeclarationSyntax node) { var id = _commonConversions.ConvertIdentifier(node.ThisKeyword); - var modifiers = CommonConversions.ConvertModifiers(node.Modifiers, GetMemberContext(node)); + var modifiers = WithOverloadsIfNeeded(CommonConversions.ConvertModifiers(node.Modifiers, GetMemberContext(node)), node, _semanticModel.GetDeclaredSymbol(node)); if (modifiers.Any(x => x.IsKind(SyntaxKind.PrivateKeyword))) { } else { modifiers = modifiers.Insert(0, SyntaxFactory.Token(SyntaxKind.DefaultKeyword)); diff --git a/Tests/TestData/SelfVerifyingTests/CSToVB/OverloadsTests.cs b/Tests/TestData/SelfVerifyingTests/CSToVB/OverloadsTests.cs new file mode 100644 index 000000000..a397a9bb5 --- /dev/null +++ b/Tests/TestData/SelfVerifyingTests/CSToVB/OverloadsTests.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using Xunit; + +public class OverloadsTestItem +{ + public string Name; +} + +public class OverloadsTestComparer : IEqualityComparer +{ + public bool Equals(OverloadsTestItem x, OverloadsTestItem y) => x.Name == y.Name; + + public int GetHashCode(OverloadsTestItem obj) => obj.Name.GetHashCode(); + + public bool SameName(OverloadsTestItem x, object name) => Equals(x.Name, name); +} + +public class OverloadsTestBase +{ + public string this[string key] => "base " + key; + + public string Describe(object value) => "base object"; + + public static string Create() => "base create"; +} + +public class OverloadsTestDerived : OverloadsTestBase +{ + public string this[int index] => "derived " + index; + + public string Describe(int value) => "derived int"; + + public static string Create(string name) => "derived " + name; + + public string DescribeText() => Describe("text"); + + public string LookupText() => this["key"]; + + public static string CreateDefault() => Create(); +} + +public interface IOverloadsTestBase +{ + string Run(int i); +} + +public interface IOverloadsTestDerived : IOverloadsTestBase +{ + string Run(string s); +} + +public class OverloadsTestRunner : IOverloadsTestDerived +{ + public string Run(int i) => "int"; + + public string Run(string s) => "string"; +} + +public class OverloadsTests +{ + [Fact] + public void ComparerEqualsKeepsObjectEquals() + { + var comparer = new OverloadsTestComparer(); + Assert.True(comparer.Equals(new OverloadsTestItem { Name = "a" }, new OverloadsTestItem { Name = "a" })); + Assert.True(comparer.SameName(new OverloadsTestItem { Name = "a" }, "a")); + } + + [Fact] + public void BaseMethodStaysCallable() => Assert.Equal("base object", new OverloadsTestDerived().DescribeText()); + + [Fact] + public void BaseIndexerStaysCallable() => Assert.Equal("base key", new OverloadsTestDerived().LookupText()); + + [Fact] + public void BaseStaticMethodStaysCallable() => Assert.Equal("base create", OverloadsTestDerived.CreateDefault()); + + [Fact] + public void BaseInterfaceMethodStaysCallable() + { + IOverloadsTestDerived runner = new OverloadsTestRunner(); + Assert.Equal("int", runner.Run(1)); + Assert.Equal("string", runner.Run("s")); + } +} diff --git a/Tests/VB/MemberTests.cs b/Tests/VB/MemberTests.cs index 193c1ec13..f044fd3e3 100644 --- a/Tests/VB/MemberTests.cs +++ b/Tests/VB/MemberTests.cs @@ -272,6 +272,277 @@ End Sub End Class", conversionOptions: EmptyNamespaceOptionStrictOff); } + [Fact] + public async Task TestMethodOverloadingInheritedMethodIsOverloadsAsync() + { + await TestConversionCSharpToVisualBasicAsync( + @"class BaseClass +{ + public static void SomeAction() + { + } +} + +class DerivedClass : BaseClass +{ + public static void SomeAction(string t) + { + SomeAction(); + } +}", @"Friend Class BaseClass + Public Shared Sub SomeAction() + End Sub +End Class + +Friend Class DerivedClass + Inherits BaseClass + Public Shared Overloads Sub SomeAction(t As String) + SomeAction() + End Sub +End Class"); + } + + [Fact] + public async Task TestMethodOverloadingObjectMethodIsOverloadsAsync() + { + await TestConversionCSharpToVisualBasicAsync( + @"using System.Collections.Generic; + +public class Item +{ + public string Name; +} + +public class Comparer : IEqualityComparer +{ + public bool Equals(Item x, Item y) + { + return x.Name == y.Name; + } + + public int GetHashCode(Item obj) + { + return obj.Name.GetHashCode(); + } +}", @"Imports System.Collections.Generic + +Public Class Item + Public Name As String +End Class + +Public Class Comparer + Implements IEqualityComparer(Of Item) + Public Overloads Function Equals(x As Item, y As Item) As Boolean Implements IEqualityComparer(Of Item).Equals + Return Equals(x.Name, y.Name) + End Function + + Public Overloads Function GetHashCode(obj As Item) As Integer Implements IEqualityComparer(Of Item).GetHashCode + Return obj.Name.GetHashCode() + End Function +End Class"); + } + + [Fact] + public async Task TestMembersOverloadingInheritedMembersAreOverloadsAsync() + { + await TestConversionCSharpToVisualBasicAsync( + @"using System; + +public struct Point : IEquatable +{ + public int X; + public bool Equals(Point other) { return X == other.X; } + public string ToString(string format) { return X.ToString(format); } +} + +public class BaseList +{ + public string this[string key] { get { return key; } } + public virtual void Add(object item) { } + public void Remove(T item) { } +} + +public class DerivedList : BaseList +{ + public int this[int index] { get { return index + this[""a""].Length; } } + public void Add(int item) { Add((object)item); } + public void Remove(int item) { Remove(item); } + public void remove(string item) { } +} + +public interface IBase +{ + void Run(int i); +} + +public interface IDerived : IBase +{ + void Run(string s); +} + +public static class User +{ + public static void Use(IDerived d) { d.Run(1); d.Run(""s""); } +}", + @"Imports System + +Public Structure Point + Implements IEquatable(Of Point) + Public X As Integer + Public Overloads Function Equals(other As Point) As Boolean Implements IEquatable(Of Point).Equals + Return X = other.X + End Function + Public Overloads Function ToString(format As String) As String + Return X.ToString(format) + End Function +End Structure + +Public Class BaseList + Default Public ReadOnly Property Item(key As String) As String + Get + Return key + End Get + End Property + Public Overridable Sub Add(item As Object) + End Sub + Public Sub Remove(Of T)(item As T) + End Sub +End Class + +Public Class DerivedList + Inherits BaseList + Default Public Overloads ReadOnly Property Item(index As Integer) As Integer + Get + Return index + Me(""a"").Length + End Get + End Property + Public Overloads Sub Add(item As Integer) + MyBase.Add(item) + End Sub + Public Overloads Sub Remove(item As Integer) + Remove(Of Object)(item) + End Sub + Public Overloads Sub remove(item As String) + End Sub +End Class + +Public Interface IBase + Sub Run(i As Integer) +End Interface + +Public Interface IDerived + Inherits IBase + Overloads Sub Run(s As String) +End Interface + +Public Module User + Public Sub Use(d As IDerived) + d.Run(1) + d.Run(""s"") + End Sub +End Module"); + } + + [Fact] + public async Task TestNestedStaticClassMethodOverloadingObjectMethodIsOverloadsAsync() + { + await TestConversionCSharpToVisualBasicAsync( + @"class Outer +{ + public static class Helpers + { + public static bool Equals(int a, int b) + { + return a == b; + } + } +}", @"Friend Class Outer + Public NotInheritable Class Helpers + Public Shared Overloads Function Equals(a As Integer, b As Integer) As Boolean + Return a = b + End Function + End Class +End Class"); + } + + [Fact] + public async Task TestMethodNotOverloadingInheritedMethodHasNoOverloadsAsync() + { + await TestConversionCSharpToVisualBasicAsync( + @"class BaseClass +{ + public virtual void Run() + { + } + + private void Hidden() + { + } + + public int Count { get; set; } +} + +class DerivedClass : BaseClass +{ + public override void Run() + { + } + + public int Count(int i) + { + return i; + } + + public void Hidden(int i) + { + } +} + +static class Helpers +{ + public static bool Equals(int a, int b) + { + return a == b; + } + + public static string ToString(int[] values, string separator) + { + return string.Join(separator, values); + } +}", @"Friend Class BaseClass + Public Overridable Sub Run() + End Sub + + Private Sub Hidden() + End Sub + + Public Property Count As Integer +End Class + +Friend Class DerivedClass + Inherits BaseClass + Public Overrides Sub Run() + End Sub + + Public Function Count(i As Integer) As Integer + Return i + End Function + + Public Sub Hidden(i As Integer) + End Sub +End Class + +Friend Module Helpers + Public Function Equals(a As Integer, b As Integer) As Boolean + Return a = b + End Function + + Public Function ToString(values As Integer(), separator As String) As String + Return String.Join(separator, values) + End Function +End Module"); + } + [Fact] public async Task OperatorOverloadsAsync() From 382950747ea5cb104b0c85d7824f18ce4d41228b Mon Sep 17 00:00:00 2001 From: Alexander Komarov Date: Wed, 18 Nov 2026 11:49:28 +0400 Subject: [PATCH 2/2] Look up inherited namesakes once per type and keep indexer names - Cache the accessible inherited members of a type by name, so a type with many members reads its base types once instead of once per member. - Compare names with CaseInsensitiveComparison, as VB does. - Declare an indexer under its metadata name, so [IndexerName("Chars")] gives `Default Property Chars` rather than `Item`, and the Overloads check compares the names VB actually declares. Explicit implementations keep `Item`, bound through Implements. - Explain why only an inherited member of the same kind counts. --- CHANGELOG.md | 1 + CodeConverter/VB/NodesVisitor.cs | 44 ++++++++++++++----- .../CSToVB/OverloadsTests.cs | 25 +++++++++++ Tests/VB/MemberTests.cs | 38 ++++++++++++++++ 4 files changed, 96 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f8d1dc8f..bc6e3d3c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### C# -> VB +* Name a converted indexer by its [IndexerName] instead of always Item * Don't emit Me on the first parameter of an extension method - [#1118](https://github.com/icsharpcode/CodeConverter/issues/1118) * Truncate towards zero when converting a fractional number to an integer, instead of inheriting VB's rounding - [#1021](https://github.com/icsharpcode/CodeConverter/issues/1021) * Add Overloads to methods, properties and indexers when an inherited member has the same name diff --git a/CodeConverter/VB/NodesVisitor.cs b/CodeConverter/VB/NodesVisitor.cs index 93096c828..fa3dcebb1 100644 --- a/CodeConverter/VB/NodesVisitor.cs +++ b/CodeConverter/VB/NodesVisitor.cs @@ -53,6 +53,7 @@ internal class NodesVisitor : CS.CSharpSyntaxVisitor private readonly CSharpHelperMethodDefinition _cSharpHelperMethodDefinition; private readonly CommonConversions _commonConversions; private readonly HashSet _addedNames = new(); + private readonly Dictionary> _inheritedOverloadableMembers = new(SymbolEqualityComparer.Default); private int _placeholder = 1; private readonly bool _outputWillBeOverflowChecked; @@ -565,9 +566,11 @@ public override VisualBasicSyntaxNode VisitMethodDeclaration(CSSyntax.MethodDecl /// /// A VB method or property declared without Overloads, Overrides or Shadows hides every accessible inherited member - /// of the same name (case-insensitively, BC40003/BC40004), also in interfaces, whereas C# only hides the same signature. + /// of the same name (case-insensitively, BC40003), also in interfaces, whereas C# only hides the same signature. /// Overloads keeps the C# lookup. Once one member of a name is Overloads or Overrides, VB requires Overloads on the /// others in the type (BC31409). A Module inherits nothing and doesn't allow Overloads (BC36917). + /// Only an inherited member of the same kind counts: VB can't overload a property with a method (or the reverse), + /// so such a member stays hidden by name either way. /// https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/modifiers/overloads /// private SyntaxTokenList WithOverloadsIfNeeded(SyntaxTokenList modifiers, CSSyntax.MemberDeclarationSyntax node, ISymbol member) @@ -581,16 +584,22 @@ private SyntaxTokenList WithOverloadsIfNeeded(SyntaxTokenList modifiers, CSSynta private static bool IsOverloadable(ISymbol member) => member is IMethodSymbol { MethodKind: MethodKind.Ordinary } or IPropertySymbol { ExplicitInterfaceImplementations.IsEmpty: true }; - /// Compares metadata names: an indexer is "this[]" in C# and "Item" in VB. - private bool HasAccessibleInheritedNamesake(ISymbol member) + /// Compares metadata names, which are the VB names: an indexer is "this[]" in C#. + private bool HasAccessibleInheritedNamesake(ISymbol member) => + GetAccessibleInheritedOverloadableMembers(member.ContainingType)[member.MetadataName].Any(m => m.Kind == member.Kind); + + /// Cached per type, so a type with many members reads its base types once. + private ILookup GetAccessibleInheritedOverloadableMembers(INamedTypeSymbol type) { - var containingType = member.ContainingType; - IEnumerable inheritedTypes = containingType.TypeKind == TypeKind.Interface ? containingType.AllInterfaces : containingType.GetBaseTypes(); - return inheritedTypes - .SelectMany(t => t.GetMembers()) - .Any(m => m.Kind == member.Kind && IsOverloadable(m) - && string.Equals(m.MetadataName, member.MetadataName, StringComparison.OrdinalIgnoreCase) - && _semanticModel.Compilation.IsSymbolAccessibleWithin(m, containingType)); + if (!_inheritedOverloadableMembers.TryGetValue(type, out var members)) { + IEnumerable inheritedTypes = type.TypeKind == TypeKind.Interface ? type.AllInterfaces : type.GetBaseTypes(); + members = inheritedTypes + .SelectMany(t => t.GetMembers()) + .Where(m => IsOverloadable(m) && _semanticModel.Compilation.IsSymbolAccessibleWithin(m, type)) + .ToLookup(m => m.MetadataName, CaseInsensitiveComparison.Comparer); + _inheritedOverloadableMembers.Add(type, members); + } + return members; } /// @@ -644,8 +653,9 @@ public override VisualBasicSyntaxNode VisitPropertyDeclaration(CSSyntax.Property public override VisualBasicSyntaxNode VisitIndexerDeclaration(CSSyntax.IndexerDeclarationSyntax node) { - var id = _commonConversions.ConvertIdentifier(node.ThisKeyword); - var modifiers = WithOverloadsIfNeeded(CommonConversions.ConvertModifiers(node.Modifiers, GetMemberContext(node)), node, _semanticModel.GetDeclaredSymbol(node)); + var indexer = _semanticModel.GetDeclaredSymbol(node) as IPropertySymbol; + var id = WithIndexerName(_commonConversions.ConvertIdentifier(node.ThisKeyword), indexer); + var modifiers = WithOverloadsIfNeeded(CommonConversions.ConvertModifiers(node.Modifiers, GetMemberContext(node)), node, indexer); if (modifiers.Any(x => x.IsKind(SyntaxKind.PrivateKeyword))) { } else { modifiers = modifiers.Insert(0, SyntaxFactory.Token(SyntaxKind.DefaultKeyword)); @@ -654,6 +664,16 @@ public override VisualBasicSyntaxNode VisitIndexerDeclaration(CSSyntax.IndexerDe return ConvertPropertyBlock(node, id, modifiers, parameterListSyntax, node.ExpressionBody, null); } + /// + /// VB declares an indexer as a default property under its metadata name, which [IndexerName] changes from "Item". + /// An explicit implementation keeps "Item": its metadata name is qualified, and Implements does the binding. + /// + private static SyntaxToken WithIndexerName(SyntaxToken id, IPropertySymbol indexer) + { + if (indexer == null || !indexer.ExplicitInterfaceImplementations.IsEmpty || indexer.MetadataName == id.ValueText) return id; + return id.CopyAnnotationsTo(SyntaxFactory.Identifier(id.LeadingTrivia, indexer.MetadataName, id.TrailingTrivia)); + } + private VisualBasicSyntaxNode ConvertPropertyBlock(CSSyntax.BasePropertyDeclarationSyntax node, SyntaxToken id, SyntaxTokenList modifiers, ParameterListSyntax parameterListSyntax, CSSyntax.ArrowExpressionClauseSyntax arrowExpressionClauseSyntax, diff --git a/Tests/TestData/SelfVerifyingTests/CSToVB/OverloadsTests.cs b/Tests/TestData/SelfVerifyingTests/CSToVB/OverloadsTests.cs index a397a9bb5..7c412bee2 100644 --- a/Tests/TestData/SelfVerifyingTests/CSToVB/OverloadsTests.cs +++ b/Tests/TestData/SelfVerifyingTests/CSToVB/OverloadsTests.cs @@ -40,6 +40,20 @@ public class OverloadsTestDerived : OverloadsTestBase public static string CreateDefault() => Create(); } +public class OverloadsTestNamedIndexerBase +{ + [System.Runtime.CompilerServices.IndexerName("Value")] + public string this[string key] => "base " + key; +} + +public class OverloadsTestNamedIndexerDerived : OverloadsTestNamedIndexerBase +{ + [System.Runtime.CompilerServices.IndexerName("Value")] + public string this[int index] => "derived " + index; + + public string LookupText() => this["key"]; +} + public interface IOverloadsTestBase { string Run(int i); @@ -73,6 +87,17 @@ public void ComparerEqualsKeepsObjectEquals() [Fact] public void BaseIndexerStaysCallable() => Assert.Equal("base key", new OverloadsTestDerived().LookupText()); + [Fact] + public void BaseNamedIndexerStaysCallable() + { + var derived = new OverloadsTestNamedIndexerDerived(); + Assert.Equal("base key", derived.LookupText()); + Assert.Equal("derived 1", derived[1]); + } + + [Fact] + public void NamedIndexerKeepsItsName() => Assert.NotNull(typeof(OverloadsTestNamedIndexerBase).GetProperty("Value")); + [Fact] public void BaseStaticMethodStaysCallable() => Assert.Equal("base create", OverloadsTestDerived.CreateDefault()); diff --git a/Tests/VB/MemberTests.cs b/Tests/VB/MemberTests.cs index f044fd3e3..a3eaebe5e 100644 --- a/Tests/VB/MemberTests.cs +++ b/Tests/VB/MemberTests.cs @@ -465,6 +465,44 @@ End Class End Class"); } + [Fact] + public async Task TestIndexerWithIndexerNameAsync() + { + await TestConversionCSharpToVisualBasicAsync( + @"using System.Runtime.CompilerServices; + +public class BaseText +{ + [IndexerName(""Chars"")] + public char this[string key] { get { return key[0]; } } +} + +public class DerivedText : BaseText +{ + [IndexerName(""Chars"")] + public char this[int index] { get { return this[""a""]; } } +}", @"Imports System.Runtime.CompilerServices + +Public Class BaseText + + Default Public ReadOnly Property Chars(key As String) As Char + Get + Return key(0) + End Get + End Property +End Class + +Public Class DerivedText + Inherits BaseText + + Default Public Overloads ReadOnly Property Chars(index As Integer) As Char + Get + Return Me(""a"") + End Get + End Property +End Class"); + } + [Fact] public async Task TestMethodNotOverloadingInheritedMethodHasNoOverloadsAsync() {