Byref-like error message improvements
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
Today, there are two error messages that involve byref-like types that I think can improve. Assuming the following code:
```fsharp
type R =
{ X: ReadOnlySpan
Y: ReadOnlySpan
Z: ReadOnlySpan }
```
This is disallowed because storing a byref-like type in a type is unsound. I get two error messages from this:
Under `R`:
```
A type would store a byref type value. This is not permitted by Common IL.
```
And under `X`, `Y`, and `Z`, I get:
```
A type instantiation involves a byref type. This is not permitted by the rules of Common IL.
```
### Suggestion
Although the error range is accurate in the editor for both cases, the messages state their reason inconsistently and are too general. I also believe that "Common IL" is a bit too specific. The issue is that there is no valid way for code like this to run. Additionally, `IsByRefLike` is a new way to decorate structs, thus bringing the term "byref-like" into the vernacular of F#. Finally, no preventative action is suggested.
To summarize, I believe that error messages that:
* Include the name of the bad symbol
* Introduce byref-like as a term
* Replace the opaque-yet-specific terms "Common IL" and "rules of Common IL"
* Suggest a positive change, if at all possible
Can make these a bit easier to understand.
For the first, I'd suggest something like this:
`
Type 'R' cannot be declared to store a byref-like type. Doing so is disallowed by the .NET runtime.
`
Or perhaps make unsoundness more prominent:
`
Type 'R' cannot be declared to store a byref-like type. Doing so would be unsound because it is disallowed by the .NET runtime.
`
For the second, I'd suggest something like this:
`
Type 'X' cannot be declared as byref-like type 'ReadOnlySpan' in this context because it would involve the instantiation of a byref-like type. Instantiations of byref-like types are not permitted by the .NET runtime.
`
Or this:
`
Type 'X' cannot be declared as byref-like type 'ReadOnlySpan' in this context because it would involve the instantiation of a byref-like type. Instantiations of byref-like types would be unsound because they are not permitted by the .NET runtime.
`
Thoughts @TIHan @dsyme ?
Contributor guide
Assessment
This issue has not been assessed yet.