Skip to content

Commit 733eec5

Browse files
GenAPI should not filter out base generic interfaces. (#31545)
1 parent 7460d6e commit 733eec5

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

src/GenAPI/Microsoft.DotNet.GenAPI/INamedTypeSymbolExtension.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public static bool IsBoundGenericType(this INamedTypeSymbol namedType)
177177
/// <param name="symbolFilter">Assembly symbol filter <see cref="ISymbolFilter"/>.</param>
178178
/// <returns>Boolean</returns>
179179
public static bool HasInaccessibleTypeArgument(this INamedTypeSymbol namedType, ISymbolFilter symbolFilter)
180-
=> namedType.IsGenericType && namedType.TypeArguments.Any(a => !symbolFilter.Include(a));
180+
=> namedType.IsGenericType && namedType.TypeArguments.Any(a => a.DeclaredAccessibility != Accessibility.NotApplicable && !symbolFilter.Include(a));
181181

182182
/// <summary>
183183
/// Synthesize an internal default constructor for the type with implicit default constructor and the base type without.

src/Tests/Microsoft.DotNet.GenAPI.Tests/CSharpFileBuilderTests.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,56 @@ public class PublicClass { }
20422042
expected: expected,
20432043
includeInternalSymbols: includeInternalSymbols);
20442044
}
2045+
2046+
[Fact]
2047+
public void TestGenericClassImplementsGenericInterface()
2048+
{
2049+
RunTest(original: """
2050+
using System;
2051+
namespace A
2052+
{
2053+
public class Foo<T> : System.Collections.ICollection, System.Collections.Generic.ICollection<T>
2054+
{
2055+
int System.Collections.Generic.ICollection<T>.Count => throw new NotImplementedException();
2056+
bool System.Collections.Generic.ICollection<T>.IsReadOnly => throw new NotImplementedException();
2057+
int System.Collections.ICollection.Count => throw new NotImplementedException();
2058+
bool System.Collections.ICollection.IsSynchronized => throw new NotImplementedException();
2059+
object System.Collections.ICollection.SyncRoot => throw new NotImplementedException();
2060+
void System.Collections.Generic.ICollection<T>.Add(T item) => throw new NotImplementedException();
2061+
void System.Collections.Generic.ICollection<T>.Clear() => throw new NotImplementedException();
2062+
bool System.Collections.Generic.ICollection<T>.Contains(T item) => throw new NotImplementedException();
2063+
void System.Collections.Generic.ICollection<T>.CopyTo(T[] array, int arrayIndex) => throw new NotImplementedException();
2064+
bool System.Collections.Generic.ICollection<T>.Remove(T item) => throw new NotImplementedException();
2065+
System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerable<T>.GetEnumerator() => throw new NotImplementedException();
2066+
void System.Collections.ICollection.CopyTo(System.Array array, int index) => throw new NotImplementedException();
2067+
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => throw new NotImplementedException();
2068+
2069+
}
2070+
}
2071+
2072+
""",
2073+
expected: """
2074+
namespace A
2075+
{
2076+
public partial class Foo<T> : System.Collections.ICollection, System.Collections.Generic.ICollection<T>
2077+
{
2078+
int System.Collections.Generic.ICollection<T>.Count { get { throw null; } }
2079+
bool System.Collections.Generic.ICollection<T>.IsReadOnly { get { throw null; } }
2080+
int System.Collections.ICollection.Count { get { throw null; } }
2081+
bool System.Collections.ICollection.IsSynchronized { get { throw null; } }
2082+
object System.Collections.ICollection.SyncRoot { get { throw null; } }
2083+
void System.Collections.Generic.ICollection<T>.Add(T item) { }
2084+
void System.Collections.Generic.ICollection<T>.Clear() { }
2085+
bool System.Collections.Generic.ICollection<T>.Contains(T item) { throw null; }
2086+
void System.Collections.Generic.ICollection<T>.CopyTo(T[] array, int arrayIndex) { }
2087+
bool System.Collections.Generic.ICollection<T>.Remove(T item) { throw null; }
2088+
System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerable<T>.GetEnumerator() { throw null; }
2089+
void System.Collections.ICollection.CopyTo(System.Array array, int index) { }
2090+
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
2091+
}
2092+
}
2093+
""",
2094+
includeInternalSymbols: false);
2095+
}
20452096
}
20462097
}
2047-

0 commit comments

Comments
 (0)