github / github/codeql

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

オープン
#6,785 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る
C# false-positive not security
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

**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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。