fsharp / fsharp/fslang-suggestions
Deprecate `outref` returns
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
Currently, it's possible to write a function which returns an `outref<'a>`. I propose we deprecate that construct, emitting a new warning whenever it is encountered.
For example:
```fsharp
type SomeType<'a>(value) =
let mutable _value = value
member this.GetValue () : outref<'a> = &_value
```
This is nonsensical and the compiler shouldn't have allowed stuff like this in the first place. I would argue that it's really a compiler bug, but I'm filing this as a language suggestion because removing it would technically be a breaking change. Deprecating it would be a step towards making it a compile error in the future.
It seems to compile the same as `byref<'a>`. I seriously doubt that's in a real codebase, but if it is, users just be able to use that instead: https://sharplab.io/#v2:DYLgZgzgNALiCWwoBMQGoA+BbA9sgrsAKYAEAsgIbwB2AsAFAMwCeADqQMo5ZEAqbRADwByCgD4AFADcKwfEQCUJALwMS6ksRgks+GBQBGxEgH0Zc0spLn5ajTywGiAJxIwAFvAgA6AELNnIjAAJSIYfGdqCSUQEgMAoJFxFRIAMjNZW3oNHSJHFzdPHwBJakCQsIiomJIacqSxFPSbIjt1BydXDy9vAHk9ctDwyOiSWJwBxNFGq2bM1vogA
It's also worth noting that there's also no C# equivalent.
## Pros and Cons
Pros:
* Helps prevent / fix up code that should never have been written in the first place
Cons:
* Opens the door for a breaking change
## Extra information
**Estimated cost (XS, S, M, L, XL, XXL):**
**Related suggestions:** (put links to related suggestions here)
## Affidavit (please submit!)
Please tick this by placing a cross in the box:
* [x] This is not a question (e.g. like one you might ask on [stackoverflow](http://stackoverflow.com)) and I have searched stackoverflow for discussions of this issue
* [x] I have [searched both open and closed suggestions on this site](http://github.com/fsharp/fslang-suggestions/issues) and believe this is not a duplicate
* [x] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.
Please tick all that apply:
* [x] This is not a breaking change to the F# language design
* [x] I or my company would be willing to help implement and/or test this
## For Readers
If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing the issue's outref<'a> example and the linked SharpLab reproduction to understand the current behavior. No implementation files, tests, or compiler entry points are identified in the payload. Done would mean an agreed deprecation behavior, including the new warning and coverage for this construct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100