mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Fix converter analyzer false positive when handling non-scalars or nullable types
This commit is contained in:
@@ -37,7 +37,16 @@ public class OptionMustHaveValidConverterAnalyzer : AnalyzerBase
|
||||
.FirstOrDefault();
|
||||
|
||||
// Value returned by the converter must be assignable to the property type
|
||||
if (converterValueType is null || !property.Type.IsAssignableFrom(converterValueType))
|
||||
var isCompatible =
|
||||
converterValueType is not null && (option.IsScalar()
|
||||
// Scalar
|
||||
? context.Compilation.IsAssignable(converterValueType, property.Type)
|
||||
// Non-scalar (assume we can handle all IEnumerable types for simplicity)
|
||||
: property.Type.TryGetEnumerableUnderlyingType() is { } enumerableUnderlyingType &&
|
||||
context.Compilation.IsAssignable(converterValueType, enumerableUnderlyingType)
|
||||
);
|
||||
|
||||
if (!isCompatible)
|
||||
{
|
||||
context.ReportDiagnostic(
|
||||
CreateDiagnostic(propertyDeclaration.Identifier.GetLocation())
|
||||
|
||||
Reference in New Issue
Block a user