Skip to content

NET-5208 Fix S3240 FP: Use the '??=' operator in record with { .. } assignment #9846

Open

Description

@chklauser

Description

Rule suggests to apply the ??= syntax to the field initializer inside a record with {..} block.

This is wrong in two ways.

  1. it confuses two unrelated members (C.F and A.F in the reproducer example).
  2. the syntax ??= does not exist for with {..} initializers

Reproducer

class A {
	record C {
	  string? F { get; init; }
	}
	string? F { get; init; }
	public C AppliedTo(C c) =>
	    c with
	    {
	        F = F ?? input.F,
	    };
}

Product and Version

SonarAnalyzer.CSharp 10.35.0.4138

Activity

  1. added
    False Positive
    on Nov 19, 2026
  2. changed the title [-]Fix S3240 FP: Use the '??=' operator in record `with { .. }` assignment[/-] [+]NET-5208 Fix S3240 FP: Use the '??=' operator in record `with { .. }` assignment[/+] on Nov 19, 2026
  3. github-actions commented on Nov 19, 2026

    @github-actions
    Contributor

    Internal ticket NET-5208

  4. mary-georgiou commented on Nov 19, 2026

    @mary-georgiou
    Contributor

    Thanks for the report!

    I confirm, this is a false positive.

    Best
    Mary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions