Skip to content

Unable to compile conditional access expression in context of expression-bodied void method/lambda expression #11

@controlflow

Description

@controlflow

Related commit: dd8f041

?. invocation in context of a statement-expression should be allowed even if result type of the invocation cannot be made nullable.

I'm expecting it also to work with void methods in expression-bodied form, as well as void lambda expressions:

using System;

class C<T> {
    void F1(C<T> c) {
        c?.M(); // compiles fine

        // error CS0023: Operator '?' cannot be applied to operand of type 'T'
        Action a = () => c?.M();
    }

    // error CS0023: Operator '?' cannot be applied to operand of type 'T'
    void F2(C<T> c) => c?.M();


    T M() => default(T);
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions