dotnet / dotnet/fsharp

Calling a generic method during object construction incorrectly constrains the generic to a type

Open
#18,967 2 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Checking Bug
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

When calling a generic method directly during object construction I get a warning that my code is causing my method to be less generic than the type annotation.

**Repro steps**

``` fsharp
type Test() as self =
do
self.PrintString 12
member this.PrintString<'a> (x : 'a) = Console.WriteLine(x.ToString())
```

**Expected behavior**

The above compiles without warnings.

**Actual behavior**

I get the warning `FS0064: This construct causes code to be less generic than indicated by the type annotations. The type variable 'a has been constrained to be type 'int'`

**Related information**

.NET 9.0

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.