False positive in csharp for useless-assignment-to-local

Đang mở
#22,032 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

@hvitved đang làm issue này rồi.

Từ ngày 23/6/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

false-positive

Description of the false positive

The context is the following: the variable is used inside a lambda and captured by it.

It is not clear to me what the exact cause is. I tried to create a self-contained code sample, but I was not able to trigger the false positive that way, so the sample code relies on AspNetCore, which is the context where I got the warning.

Code samples or links to source code

To reproduce, you need a project that depends on AspNetCore, which is possible with a project file like the following: Sample.csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">
</Project>

The following is helper code to configure a AspNetCore WebApplication:

public static class App
{
    extension(WebApplication app)
    {
        public void Configure()
        {
            string redirectPath = "/app";
            app.MapGet("/", () => Results.Redirect(redirectPath));
        }
    }
}

CodeQL complains about the redirectPath not being used. The type of the lambda passed to MapGet is Delegate. An example with self-contained code with a similar setup and the use of a Delegate type did not trigger the false positive.

Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 11 giờ
Pull request đã merge (30 ngày)
129

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của github/codeql

Tất cả issue của github/codeql

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.