github / github/codeql

LGTM.com - false positive This assignment to is useless, since its value is never read.

Đang mở
#6,785 5 bình luận 0 reaction 0 người được giao Xem trên GitHub
C# false-positive not security
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

**Description of the false positive**

In the code below it warns that `spanDirective` is never read even though the value is passed to a method in which it is read:

```csharp
if (directiveNode is LineSpanDirectiveTriviaSyntax spanDirective)
{
return GetLineSpanDirectiveEntry(spanDirective, directiveLineNumber);
}
```

The compiler transforms the code into this (you can view the IL [here](https://sharplab.io/#v2:CYLg1APgAgTAjAWAFDKgZgASwwGQJYB2ApgMoAOAhgQCJ4BORAxgC54BuRAKne3hSQE8CzCgA8MAb2QYZWTIWa5CRDAF4AfBgAsMANzIAvslSZsAYUnTZ6DAowBZABQB5AEYArJouD0v7IgByAPbAKgCUlkiy0bYAZhiOPgws/sGhtgDOSsTkVLTJrBzcvPxCIuIZlDS+KRxhVjGRjY1QAOwYAOJEzPg5Vfl+HACiwnQCjpV5NYVEYfpRzUYLjQ0xbRihsRQArgA2zPPRS9GrZDxsFMwqdl09yrnVBf4jzGOOvaT90/7FbHyCwjEGEmj0Gs1WUmWa3aIIGtSIADoPodZEsDEA===))
```csharp
LineSpanDirectiveTriviaSyntax lineSpanDirectiveTriviaSyntax = directiveNode as LineSpanDirectiveTriviaSyntax;
if (lineSpanDirectiveTriviaSyntax != null)
{
return GetLineSpanDirectiveEntry(spanDirective, directiveLineNumber);
}
```

So this is a false positive unless we can prove that there exists no conversion to `LineSpanDirectiveTriviaSyntax` that can ever succeed.

**URL to the alert on the project page on LGTM.com**

https://lgtm.com/projects/g/dotnet/roslyn/snapshot/c9e0dd1ec0e440897388bbd55184fb53a555e3a4/files/src/Compilers/CSharp/Portable/Syntax/CSharpLineDirectiveMap.cs?sort=name&dir=ASC&mode=heatmap#xfcee166e229ccb35:1

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

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

Đánh giá

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

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.