Skip to content

Commit c47ebea

Browse files
committed
fix
1 parent ec21a2a commit c47ebea

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

src/Analyzers/Activities/MatchingInputOutputTypeActivityAnalyzer.cs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,6 @@ public override void Initialize(AnalysisContext context)
111111
string activityName = constant.Value!.ToString();
112112

113113
// Try to extract the input argument from the invocation
114-
// Note: Two cases result in inputType being null:
115-
// 1. No input argument provided: CallActivityAsync("activity")
116-
// 2. Explicit null literal: CallActivityAsync("activity", null)
117-
// Both are treated the same - as passing null to the activity parameter
118114
ITypeSymbol? inputType = null;
119115
IArgumentOperation? inputArgumentParameter = invocationOperation.Arguments.SingleOrDefault(a => a.Parameter?.Name == "input");
120116
if (inputArgumentParameter != null && inputArgumentParameter.ArgumentKind != ArgumentKind.DefaultValue)
@@ -351,28 +347,27 @@ public override void Initialize(AnalysisContext context)
351347
/// </summary>
352348
static bool AreTypesCompatible(Compilation compilation, ITypeSymbol? sourceType, ITypeSymbol? targetType)
353349
{
354-
// Both null = compatible
355-
if (sourceType == null && targetType == null)
350+
if (sourceType is null)
356351
{
357-
return true;
358-
}
352+
// target is nullable value type
353+
if (targetType?.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T)
354+
{
355+
return true;
356+
}
359357

360-
// One is null, the other isn't
361-
if (sourceType == null || targetType == null)
362-
{
363-
// Special case: null literals can be passed to nullable parameters
364-
// This handles both nullable reference types (string?) and nullable value types (int?)
365-
if (sourceType == null && targetType != null)
358+
// nullable reference type (string?)
359+
if (targetType?.NullableAnnotation == NullableAnnotation.Annotated)
366360
{
367-
// Check if target is a nullable reference type (NullableAnnotation.Annotated)
368-
// or a nullable value type (Nullable<T>)
369-
if (targetType.NullableAnnotation == NullableAnnotation.Annotated ||
370-
targetType.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T)
371-
{
372-
return true;
373-
}
361+
return true;
374362
}
375-
363+
364+
// reference type and Nullable reference types is off
365+
if (targetType?.IsReferenceType == true &&
366+
targetType.NullableAnnotation == NullableAnnotation.None)
367+
{
368+
return true;
369+
}
370+
376371
return false;
377372
}
378373

0 commit comments

Comments
 (0)