You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- If a formal parameter is an `out` parameter of type `byref<ty>`, and an actual argument type is
870
870
not a byref type, interpret the actual parameter in the same way as type `ref<ty>`. That is, an F#
871
871
reference cell can be passed where a `byref<ty>` is expected.
@@ -1881,11 +1881,20 @@ In addition:
1881
1881
1882
1882
As a result, a byref-typed expression can occur only in these situations:
1883
1883
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.
1886
1885
- 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.
1887
1896
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.
1889
1898
1890
1899
## Promotion of Escaping Mutable Locals to Objects
| 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)||
0 commit comments