Strange behavior in runtime
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 144
Description
According to this https://github.com/dotnet/fsharp/issues/15135
```
type MyType<^T when ^T: (member o: int)> (t:^T) =
member inline this.T = t
```
Looks good in editor (no syntax error), but results
```
error FS1113: The value 'T' was marked inline but its implementation makes use of an internal or private function which is not sufficiently accessible
```
Is normal.
However
```
type MyType1<^T when ^T: (member o:int)> = {
t: ^T
}
with
member inline this.T = this.t
```
Provides very similar functionality, but working...
```
type MyType1<^T when ^T: (member o: int)> =
{ t: ^T }
member inline T: ^T
>
```
Excuse me, is anyone kind to tell what's the difference? Since according to the past investigation,
```
I found the underlying reason. The CLR that handles generics recognizes a number of [constraints](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/constraints-on-type-parameters), including type/interface constraints, but not explicit member constraints. The latter is a pure [F# thing](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/constraints). This means (now I am speculating) the compiler has to express it in IL by an interface constraint, and that can be done only if MyType is a "head type", i.e. statically known at compile time. These complications are also the reason why the F# Language Reference says that explicit member constraints are "not intended for common use".
```
Contributor guide
Assessment
This issue has not been assessed yet.