Skip to content

Commit

Permalink
Fix S6964 FP: Should not raise for reference properties in nullable c…
Browse files Browse the repository at this point in the history
…ontext (#9308)
  • Loading branch information
mary-georgiou-sonarsource committed May 22, 2024
1 parent 15d082d commit 91826ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static void CheckInvalidProperties(INamedTypeSymbol parameterType, Sonar

private static bool CanBeNull(ITypeSymbol type) =>
type is ITypeParameterSymbol { HasValueTypeConstraint: false }
|| (type.IsReferenceType && type.NullableAnnotation() != NullableAnnotation.NotAnnotated)
|| type.IsReferenceType
|| type.IsNullableValueType();

private static void GetAllDeclaredProperties(ITypeSymbol type, ConcurrentDictionary<ITypeSymbol, bool> examinedTypes, List<IPropertySymbol> declaredProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ namespace NullableReferences
public class ModelUsedInController
{
#nullable enable
public string NonNullableReferenceProperty { get; set; } // Noncompliant
public string NonNullableReferenceProperty { get; set; } // Compliant - ASP.NET Core treats non-nullable reference types as if they were decorated with the [Required] attribute
public object AnotherNonNullableReferenceProperty { get; set; }
[Required] public string RequiredNonNullableReferenceProperty { get; set; }
public string? NullableReferenceProperty { get; set; }
public int ValueProperty { get; set; } // Noncompliant
public int? NullableValueProperty { get; set; }
#nullable disable
public string ReferenceProperty { get; set; }
public object AnotherReferenceProperty { get; set; }
public int? AnotherNullableValueProperty { get; set; }
}

public class DerivedFromController : Controller
Expand Down

0 comments on commit 91826ed

Please sign in to comment.