Skip to content

Null-conditional LINQ chain over a value type is emitted as invalid query syntax (CS1936) #3968

Description

@sailro

Input code

using System.Collections.Immutable;
using System.Linq;

public sealed class Box
{
	public ImmutableArray<int> Values { get; init; }
}

public static class C
{
	public static string? FirstPositive(Box? box) =>
		box?.Values
			.Where(value => value > 0)
			.Select(value => value.ToString())
			.FirstOrDefault();
}

Erroneous output

public static string? FirstPositive(Box? box)
{
	return (from value in box?.Values
		where value > 0
		select value.ToString()).FirstOrDefault();
}

This does not compile:

error CS1936: Could not find an implementation of the query pattern for source type 'ImmutableArray<int>?'

The null-conditional access lifts Values to ImmutableArray<int>?. The method chain must remain inside the conditional access.

Details

Product: ICSharpCode.Decompiler / ilspycmd.

Version: master 9ea8d7c.

The input was compiled in Release for net10.0.

I can submit a small fix and regression test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions