dotnet/roslyn

Unreachable code detection does not respect local scopes and throw statements

Open

#75,605 创建于 2024年10月23日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)C# (4,257 fork)batch import
Area-Compilershelp wanted

仓库指标

Star
 (20,414 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

Version Used

VS 2022 Version 17.11.5 Roslyn 4.11.0 (5649376e0e5f)

Project info C# 12.0 .NET 8.0

Steps to Reproduce

Use the following code:

public static int Add(int a, int b)
{
    {
        return a + b;
    }

    throw new InvalidOperationException();

    {
        throw new InvalidOperationException();
    }

    {
        const int x = 523;
        throw new InvalidOperationException();
    }

    {
        throw new InvalidOperationException();
    }
}

Expected Behavior

In VS, the unreachable code will dim out showing that the dimmed out region is unreachable. In the above example, we expect all the code from the throw statement onwards to be dimmed out.

Actual Behavior

The resulting dimming is very different and limited to the scope that starts with non-throw statements. Image

贡献者指南