Skip to content

Target-typed expressions with nested elements/branches don't get converted when one of nested expressions is directly an error #81365

@DoctorKrolic

Description

@DoctorKrolic

Discovered in #80907

Steps to Reproduce:

class C
{
    public void M(bool b, int i)
    {
        C[] cs = [a, default];

        C c1 = b ? a : default;

        C c2 = i switch
        {
            1 => a,
            _ => default,
        };

        (C, int) t = (a, default);
    }
}

Hover over default literal in each expression

Expected Behavior:
I get type information about the literal

Actual Behavior:
Nothing is shown

Breakdown:
The underlying issue lies in the compiler layer. Althouth in each case target type can be determined, expressions don't get converted to it due to one of nested elements/expressions being directly an error. If an error isn't directly in the element/branch, e.g. if I change collection expression to [new(a), default] even though the first element still contains an error, types start to flow through, so I get correct type information both on new and default. The same applies to other examples as well.

There is theoretical IDE impact, but I believe it is extreamly rare to see it in practical applications

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersConcept-Design DebtEngineering Debt, Design Debt, or poor product code qualityhelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions