Skip to content

Syntax error in if() in catch in lambda completely breaks brace matching #4009

@SLaks

Description

@SLaks

Source:

using System;

class C {
    C() {
        try {
            Action a = () => {
                try {
                    try {
                    } catch (ArgumentException ex) {
                        if (1 2)
                            ex.ParamName.ToString();
                    }
                } catch (AggregateException ex) { }
            };
        } catch (Exception ex) { }
    }
}

(all three catch blocks are required to reproduce the bug)

The invalid if causes brace matching to drop out of sync; the } following the ToString() matches the outermost try {, and the remaining catch blocks become class & namespace-level scoping.

This breaks brace highlighting and Ctrl+}, and gives very strange semantic errors (ex.ParamName fails because the field AggregateException ex has no such member).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersBugConcept-Diagnostic ClarityThe issues deals with the ease of understanding of errors and warnings.help wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions