Skip to content

Inferred nullable flow state from a finally block #34018

@gafter

Description

@gafter

I don't think our current inference design interacts with finally blocks well:

C? c = null;
try
{
    c = SomeNonNullComputation;
}
finally
{
    if (c != null) c.Cleanup();
}
c.Operation(); // undeserved warning

We infer from c != null that c might be null. That inference leaks out to the enclosing construct. The result is a warning when c is used after the try-finally statement. This will be a common pain point.

I don't think indirect inferences from inside a finally block should leak out to the enclosing context. An inference from an actual assignment in the finally block should indeed leak out, though.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions