Skip to content

Commit a5c1f17

Browse files
committed
Use modopt for function pointers
1 parent fcacbf1 commit a5c1f17

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

proposals/ref-readonly-parameters.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ Specifying the attribute in source will be an error, similarly to `ParamArrayAtt
103103
[funcptrs]: #function-pointers
104104

105105
In function pointers, `in` parameters are emitted with `modreq(System.Runtime.InteropServices.InAttribute)` (see [function pointers proposal](https://github.com/dotnet/csharplang/blob/0376b4cc500b1370da86d26be634c9acf9d60b71/proposals/csharp-9.0/function-pointers.md#metadata-representation-of-in-out-and-ref-readonly-parameters-and-return-types)).
106-
`ref readonly` parameters will be emitted in the same way to ensure binary compatibility.
106+
`ref readonly` parameters will be emitted in the same but with additional `modopt(System.Runtime.CompilerServices.RequiresLocationAttribute)`.
107+
This ensures that older compiler versions will see `ref readonly` parameters as `in` parameters without any errors or warnings
108+
and new compiler versions will be able to recognize `ref readonly` parameters to emit warnings during [conversions][interchangeability] and [invocations][overload-resolution].
107109

108110
### Default parameter values
109111
[default-params]: #default-parameter-values
@@ -151,10 +153,11 @@ Default parameter values could be an error for `ref readonly` parameters.
151153

152154
Specifying the `RequiresLocationAttribute` in source could be allowed, similarly to `In` and `Out` attributes.
153155

156+
Function pointer `ref readonly` parameters could be emitted without `modopt` or with `modreq`.
157+
154158
## Unresolved questions
155159
[unresolved]: #unresolved-questions
156160

157-
- Emit function pointers `ref readonly` parameters differently from `in` parameters to avoid freely casting between them? Use `modreq`,`modopt`?
158161
- Emit errors for rvalues passed into `in`/`ref readonly` parameters of methods that could capture them? See https://github.com/dotnet/roslyn/pull/67955#discussion_r1178138561.
159162

160163
## Design meetings

0 commit comments

Comments
 (0)