Skip to content

Commit 74109d6

Browse files
committed
Fix some incorrect diagnostic messages
1 parent 1d9ba0a commit 74109d6

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Diagnostics/Analyzers/UseGeneratedDependencyPropertyOnManualPropertyAnalyzer.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,6 @@ void HandleSetAccessor(IPropertySymbol propertySymbol, PropertyFlags propertyFla
431431
fieldFlags.PropertyTypeExpressionLocation = propertyTypeArgument.Syntax.GetLocation();
432432
}
433433

434-
// Best effort name to use to interpolate any diagnostics below to emit if the default value is not valid
435-
string propertyNameForMessageFormat = "___";
436-
437434
// We cannot validate the property name from here yet, but let's check it's a constant, and save it for later
438435
if (nameArgument.Value.ConstantValue is { HasValue: true, Value: string propertyName })
439436
{
@@ -442,8 +439,6 @@ void HandleSetAccessor(IPropertySymbol propertySymbol, PropertyFlags propertyFla
442439
fieldFlags.PropertyName = propertyName;
443440
}
444441

445-
propertyNameForMessageFormat = propertyName;
446-
447442
// Additional diagnostic #2: the property name should be the same as the field name, without the "Property" suffix (as per convention)
448443
if (fieldSymbol.Name.EndsWith("Property") && propertyName != fieldSymbol.Name[..^"Property".Length])
449444
{
@@ -555,8 +550,7 @@ void HandleSetAccessor(IPropertySymbol propertySymbol, PropertyFlags propertyFla
555550
InvalidDefaultValueNullOnDependencyPropertyField,
556551
defaultValueArgument.Syntax.GetLocation(),
557552
fieldSymbol,
558-
propertyTypeSymbol,
559-
propertyNameForMessageFormat));
553+
propertyTypeSymbol));
560554
}
561555
}
562556
else
@@ -592,8 +586,7 @@ void HandleSetAccessor(IPropertySymbol propertySymbol, PropertyFlags propertyFla
592586
defaultValueArgument.Syntax.GetLocation(),
593587
fieldSymbol,
594588
operandTypeSymbol,
595-
propertyTypeSymbol,
596-
propertyNameForMessageFormat));
589+
propertyTypeSymbol));
597590
}
598591
}
599592
}

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,28 +422,28 @@ internal static class DiagnosticDescriptors
422422
helpLinkUri: "https://aka.ms/toolkit/labs/windows");
423423

424424
/// <summary>
425-
/// <c>The field '{0}' is registering a dependency property, but its default value is set to 'null', which is not compatible with the property type '{1}' declared in metadata (consider changing the default value, implementing the 'On{2}Get(ref object)' partial method to handle the type mismatch, or suppressing the diagnostic if this is the intended behavior)</c>.
425+
/// <c>The field '{0}' is registering a dependency property, but its default value is set to 'null', which is not compatible with the property type '{1}' declared in metadata (consider changing the default value, setting the property value to a non 'null' value upon object construction, and/or suppressing the diagnostic if this is the intended behavior)</c>.
426426
/// </summary>
427427
public static readonly DiagnosticDescriptor InvalidDefaultValueNullOnDependencyPropertyField = new(
428428
id: "WCTDPG0031",
429429
title: "Invalid 'null' default value in dependency property field metadata",
430-
messageFormat: "The field '{0}' is registering a dependency property, but its default value is set to 'null', which is not compatible with the property type '{1}' declared in metadata (consider changing the default value, implementing the 'On{2}Get(ref object)' partial method to handle the type mismatch, or suppressing the diagnostic if this is the intended behavior)",
430+
messageFormat: "The field '{0}' is registering a dependency property, but its default value is set to 'null', which is not compatible with the property type '{1}' declared in metadata (consider changing the default value, setting the property value to a non 'null' value upon object construction, and/or suppressing the diagnostic if this is the intended behavior)",
431431
category: DiagnosticCategory,
432432
defaultSeverity: DiagnosticSeverity.Warning,
433433
isEnabledByDefault: true,
434-
description: "All dependency property fields setting an explicit default value in metadata should do so with an expression of a type comparible with the property type. Alternatively, the generated getter method (eg. 'OnNameGet', if the property is called 'Name') should be implemented to handle the type mismatch.",
434+
description: "All dependency property fields setting an explicit default value in metadata should do so with an expression of a type comparible with the property type. Alternatively, the property value should be set to a non 'null' value upon object construction.",
435435
helpLinkUri: "https://aka.ms/toolkit/labs/windows");
436436

437437
/// <summary>
438-
/// <c>The field '{0}' is registering a dependency property, but its default value has type '{1}', which is not compatible with the property type '{2}' declared in metadata (consider fixing the default value, or implementing the 'On{3}Get(ref object)' partial method to handle the type mismatch)</c>.
438+
/// <c>The field '{0}' is registering a dependency property, but its default value has type '{1}', which is not compatible with the property type '{2}' declared in metadata (consider fixing the default value, or suppressing the diagnostic if this is the intended behavior)</c>.
439439
/// </summary>
440440
public static readonly DiagnosticDescriptor InvalidDefaultValueTypeOnDependencyPropertyField = new(
441441
id: "WCTDPG0032",
442442
title: "Invalid default value type in dependency property field metadata",
443-
messageFormat: "The field '{0}' is registering a dependency property, but its default value has type '{1}', which is not compatible with the property type '{2}' declared in metadata (consider fixing the default value, or implementing the 'On{3}Get(ref object)' partial method to handle the type mismatch)",
443+
messageFormat: "The field '{0}' is registering a dependency property, but its default value has type '{1}', which is not compatible with the property type '{2}' declared in metadata (consider fixing the default value, or suppressing the diagnostic if this is the intended behavior)",
444444
category: DiagnosticCategory,
445445
defaultSeverity: DiagnosticSeverity.Warning,
446446
isEnabledByDefault: true,
447-
description: "All dependency property fields setting an explicit default value in metadata should do so with an expression of a type comparible with the property type. Alternatively, the generated getter method (eg. 'OnNameGet', if the property is called 'Name') should be implemented to handle the type mismatch.",
447+
description: "All dependency property fields setting an explicit default value in metadata should do so with an expression of a type comparible with the property type.",
448448
helpLinkUri: "https://aka.ms/toolkit/labs/windows");
449449
}

0 commit comments

Comments
 (0)