Skip to content

Commit 223c85b

Browse files
authored
Add FS-1020 (#92)
1 parent 2247ea9 commit 223c85b

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

spec/inference-procedures.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ Two additional rules apply when checking arguments (see [§](type-definitions.md
865865

866866
For more information on the conversions that are automatically applied to arguments, see
867867
[§](type-definitions.md#optional-arguments-to-method-members).
868-
868+
869869
- If a formal parameter is an `out` parameter of type `byref<ty>`, and an actual argument type is
870870
not a byref type, interpret the actual parameter in the same way as type `ref<ty>`. That is, an F#
871871
reference cell can be passed where a `byref<ty>` is expected.
@@ -1881,11 +1881,20 @@ In addition:
18811881

18821882
As a result, a byref-typed expression can occur only in these situations:
18831883

1884-
- As an argument to a call to a module-defined function or class-defined function.
1885-
1884+
- As an argument to a call to a module-defined function, class-defined function, or member.
18861885
- On the right-hand-side of a value definition for a byref-typed local.
1886+
- As the return value of a method, property, indexer, or delegate.
1887+
1888+
These restrictions also apply to uses of the prefix `&&` operator for generating native pointer values.
1889+
1890+
When a byref-typed expression is used as a return value, it is subject to additional safety rules to ensure that a method does not return a reference to variables from its own stack frame. A byref is considered **safe to return** only if it meets one of the following conditions:
1891+
1892+
- It is a byref to a field in a heap-allocated class or record.
1893+
- It is a byref-valued formal parameter passed into the current method.
1894+
- It is a byref to a field in a struct, provided a byref to that struct itself is safe to return.
1895+
- It is a byref returned from another method, provided all byrefs passed to that method as formal parameters are safe to return.
18871896

1888-
These restrictions also apply to uses of the prefix && operator for generating native pointer values.
1897+
Note that the `this` parameter (the self identifier) is **not** safe to return from struct members, because struct instance members are passed a byref to a potentially stack-allocated copy of the struct.
18891898

18901899
## Promotion of Escaping Mutable Locals to Objects
18911900

@@ -2001,16 +2010,16 @@ module Foo =
20012010
type Bar() =
20022011
// compiles as a static method taking 3 arguments
20032012
static member Test1 (a1: int, a2: float, a3: string) = ()
2004-
2013+
20052014
// compiles as a static method taking 1 tupled argument
20062015
static member Test2 (aTuple : int * float * string) = ()
2007-
2016+
20082017
// compiles as a static method taking 1 tupled argument
20092018
static member Test3 ( (aTuple : int * float * string) ) = ()
2010-
2019+
20112020
// compiles as a static method taking 1 tupled argument
20122021
static member Test4 ( (a1: int, a2: float, a3: string) ) = ()
2013-
2022+
20142023
// compiles as a static method taking 1 tupled argument
20152024
static member Test5 (a1, a2, a3 : int * float * string) = ()
20162025
```

spec/rfc-status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
| F# 4.1 | FS-1017 | [Fix SRTP Constraint Parsing](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1017-fix-srtp-constraint-parsing.md) | [completed](https://github.com/fsharp/fslang-spec/pull/91) |
3030
| F# 4.1 | FS-1018 | [Adjust Extensions Method Scope](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1018-adjust-extensions-method-scope.md) | |
3131
| F# 4.1 | FS-1019 | [Implicitly Add the Module Suffix](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1019-implicitly-add-the-module-suffix.md) | [completed](https://github.com/fsharp/fslang-spec/pull/77) |
32-
| F# 4.1 | FS-1020 | [ByRef Returns](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1020-byref-returns.md) | |
32+
| F# 4.1 | FS-1020 | [ByRef Returns](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1020-byref-returns.md) | [completed](https://github.com/fsharp/fslang-spec/pull/92) |
3333
| F# 4.1 | FS-1025 | [Improve Record Type Inference](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1025-improve-record-type-inference.md) | |
3434
| F# 4.1 | FS-1027 | [Complete Optional DefaultParameterValue](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1027-complete-optional-defaultparametervalue.md) | [completed](https://github.com/fsharp/fslang-spec/pull/75) |
3535
| F# 4.1 | FS-1029 | [Implement IReadOnlyCollection in list](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1029-Implement%20IReadOnlyCollection%20in%20list.md) | |

0 commit comments

Comments
 (0)