Skip to content

Commit f2ac314

Browse files
committed
Improve [ICommand] overload diagnostics
1 parent 3ff3d8e commit f2ac314

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

CommunityToolkit.Mvvm.SourceGenerators/Input/ICommandGenerator.Execute.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,16 @@ private static bool IsCommandDefinitionUnique(IMethodSymbol methodSymbol, Immuta
317317
foreach (ISymbol symbol in methodSymbol.ContainingType.GetMembers(methodSymbol.Name))
318318
{
319319
if (symbol is IMethodSymbol otherSymbol &&
320-
!SymbolEqualityComparer.Default.Equals(methodSymbol, otherSymbol) &&
321320
otherSymbol.HasAttributeWithFullyQualifiedName("global::CommunityToolkit.Mvvm.Input.ICommandAttribute"))
322321
{
322+
// If the first [ICommand] overload is the current symbol, return immediately. This makes it so
323+
// that if multiple overloads are present, only the ones after the first declared one will have
324+
// diagnostics generated for them, while the first one will remain valid and will keep working.
325+
if (SymbolEqualityComparer.Default.Equals(methodSymbol, otherSymbol))
326+
{
327+
return true;
328+
}
329+
323330
diagnostics.Add(
324331
MultipleICommandMethodOverloadsError,
325332
methodSymbol,

0 commit comments

Comments
 (0)