Clarify the rules on UnmanagedCallersOnly

This commit is contained in:
Fredric Silberberg 2020-08-25 15:48:55 -07:00
parent 94b0500e97
commit 7ff6cb3bb7
No known key found for this signature in database
GPG key ID: BB6144C8A0CEC8EE

View file

@ -358,9 +358,12 @@ the attribute:
* It is an error to directly call a method annotated with this attribute from C#. Users must obtain a function pointer to * It is an error to directly call a method annotated with this attribute from C#. Users must obtain a function pointer to
the method and then invoke that pointer. the method and then invoke that pointer.
* It is an error to apply the attribute to anything other than a static method. The C# compiler will mark any non-static * It is an error to apply the attribute to anything other than an ordinary static method or ordinary static local function.
methods imported from metadata with this attribute as unsupported by the language. The C# compiler will mark any non-static methods imported from metadata with this attribute as unsupported by the language.
* It is an error to have managed types as parameters or the return type of a method marked with the attribute. * It is an error to have managed types as parameters or the return type of a method marked with the attribute. This includes
types with type parameters, even if those type parameters are constrained to `unmanaged` or substituted with `unmanaged` types.
* It is an error for a method attributed with `UnmanagedCallersOnlyAttribute` to have type parameters, even if those type
parameters are constrained to `unmanaged`.
* It is an error to convert a method marked with the attribute to a delegate type. * It is an error to convert a method marked with the attribute to a delegate type.
* It is an error to specify any types for `UnmanagedCallersOnly.CallConvs` that do not meet the requirements for calling * It is an error to specify any types for `UnmanagedCallersOnly.CallConvs` that do not meet the requirements for calling
convention `modopt`s in metadata. convention `modopt`s in metadata.