dotnet / dotnet/fsharp

RequiresExplicitTypeArguments always results in warnings when applied to functions with no explicit type arguments

Open
#7,415 1 comment 2 reactions 0 assignees View on GitHub
Area-Diagnostics Feature Improvement
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Consider the following F# code:

```fsharp
[]
let f x = x

f 12 |> ignore
```

This gives an error:

```
The generic function 'f' must be given explicit type argument(s)
```

So I can give it a type argument, like `int` or `_`:

```fsharp
[]
let f x = x

f 12 |> ignore
f<_> "hello" |> ignore
```

But I get a new warning:

```
The method or function 'f' should not be given explicit type argument(s) because it does not
declare its type parameters explicitly
```

Giving it a type argument satisfies that warning (but I can't do the last line anymore since it's now been specialized to `int`).

I think it should instead give a warning on the attribute application if there isn't an explicit type parameters.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.