Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Inconsistent suppression behavior for nested functions #2727

Open

Description

@sbomer

Extracted from #2689 (comment):

With local functions the IL reference (if there is one at all) doesn't tell us where it is defined. So M1 and M2 produce effectively the same IL:

public class C {
    void M1() {
        void Outer() {
            Inner();
            
            void Inner() {
            }
        }
    }
    
    void M2() {
        void Outer() {
            Inner();
        }
        
        void Inner() {
        }
    }
}

For this reason the linker will not try to associate local functions with the immediately containing local function - instead it will only associate local functions with the containing user method. However, the analyzer does consider suppressions from enclosing local functions. So one question is whether the analyzer should behave more like the linker by only "inheriting" suppressions from the containing user method.

It might be possible to do better for cases where they capture enclosing state - there we could potentially infer the nesting from what got captured - but this would mean more reliance on compiler implementation details.

This is only really an issue for local functions. We could do better for lambdas since the IL will always have an actual reference to the generated lambda method at the point where it is defined. It's debatable whether we should implement better understanding of nested lambdas, or leave lambdas with the same limitation for consistency with local functions.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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