Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S6964 FP: Should not raise for reference properties in nullable context #9308

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
zsolt-kolbay-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
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