Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ private static void CheckTypeMembers(IEnumerable<ISymbol> members, Action<Diagno
using var membersByName = PooledDictionary<string, PooledHashSet<ISymbol>>.GetInstance(StringComparer.OrdinalIgnoreCase);
foreach (var member in members)
{
// Ignore constructors, indexers, operators and destructors for name check
// Ignore constructors, indexers, operators, destructors and extension blocks for name check
if (member.IsConstructor() ||
member.IsDestructor() ||
member.IsIndexer() ||
member.IsUserDefinedOperator() ||
member.IsExtension() ||
overloadsToSkip.Contains(member))
{
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ internal static class INamedTypeSymbolExtensions

private static readonly Func<INamedTypeSymbol, bool> s_isFileLocal = LightupHelpers.CreateSymbolPropertyAccessor<INamedTypeSymbol, bool>(typeof(INamedTypeSymbol), nameof(IsFileLocal), fallbackResult: false);

private static readonly Func<INamedTypeSymbol, bool> s_isExtension = LightupHelpers.CreateSymbolPropertyAccessor<INamedTypeSymbol, bool>(typeof(INamedTypeSymbol), nameof(IsExtension), fallbackResult: false);

public static bool IsFileLocal(this INamedTypeSymbol symbol) => s_isFileLocal(symbol);

public static bool IsExtension(this INamedTypeSymbol symbol) => s_isExtension(symbol);

public static IEnumerable<INamedTypeSymbol> GetBaseTypesAndThis(this INamedTypeSymbol type)
{
INamedTypeSymbol current = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public static bool IsConversionOperator([NotNullWhen(returnValue: true)] this IS
return symbol is IMethodSymbol { MethodKind: MethodKind.Conversion };
}

public static bool IsExtension([NotNullWhen(returnValue: true)] this ISymbol? symbol)
{
return symbol is INamedTypeSymbol namedTypeSymbol && namedTypeSymbol.IsExtension();
}

public static ImmutableArray<IParameterSymbol> GetParameters(this ISymbol? symbol)
{
return symbol switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,35 @@ public partial class D
GetCA1708CSharpResultAt(30, 30, Parameter, "N.D.SomeDelegate"));
}

[Fact]
public async Task TestMultipleExtensionBlocks()
{
string code = @"
public static class StringExtensions
{
private const string ExtensionString = ""Extension"";

// Static class extensions
extension(string)
{
public static string CreateExtension() => ExtensionString;
}

// Instance extensions
extension(string s)
{
public bool IsExtensionString() => s == ExtensionString;
}
}
";

await new VerifyCS.Test
{
TestCode = code,
LanguageVersion = CodeAnalysis.CSharp.LanguageVersion.CSharp14,
}.RunAsync();
}

#endregion

#region Helper Methods
Expand Down