github / github/codeql

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

Abierto
#22,032 1 comentario 0 reacciones 1 asignado Reclamado por @hvitved Ver en GitHub
false-positive
Lenguaje dominante
CodeQL
Estrellas
10.1k
Forks
2.1k
Merge medio
2 d 15 h
PR fusionados (30 d)
141

Descripción

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

```csharp

```

The following is helper code to configure a AspNetCore `WebApplication`:

```csharp
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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.