Skip to content

Null-coalescing test should inform nullability #26747

@jcouv

Description

@jcouv

Splitting issue out of #26745

Null-coalescing operators should affect the flow analysis of null values.
Here's an example reported by @bgrainger: https://github.com/bgrainger/NullableReferenceTypes/blob/master/NullCoalescingProperty.cs

namespace NullableReferenceTypes
{
	class NullCoalescingProperty
	{
		public void ClearChild(Node? parent)
		{
			if (parent?.Left != null)
			{
				// warning CS8602: Possible dereference of a null reference.
				// however, we know that parent.Left != null, therefore parent != null
				parent.Left = null;
			}
		}
	}

	class Node
	{
		public Node? Left { get; set; }
		public Node? Right { get; set; }
	}
}

Once fixed, please update this speclet section.

Tagging @cston @gafter

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions