Improve error message about necessary type annotations when generic class member calls the same member on an instance with a concrete class
Open
Area-Diagnostics
Feature Improvement
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 144
Description
Consider the following code:
```f#
type Foo<'a>(x: Foo) =
member __.Do() =
x.Do()
()
```
It doesn't compile; it produces one error (on `'a`, "the explicit type variable could not be generalized") and two warnings (on `this` and `x.Do()`, "causes code to be less generic than indicated by the type annotations").
For some reason (I'd appreciate an explanation why), adding the return type annotation `: unit` to `Do()` makes the error and warnings go away.
I suggest to improve the error message in cases like these; it was only by chance that I came across the correct fix.
(Originally reported in https://github.com/fsharp/fsharp/issues/869)
Contributor guide
Assessment
This issue has not been assessed yet.