Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify the rules on UnmanagedCallersOnly #3823

Merged
merged 4 commits into from
Aug 26, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions proposals/csharp-9.0/function-pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,13 @@ the attribute:

* 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.
* It is an error to apply the attribute to anything other than a static method. 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 apply the attribute to anything other than an ordinary static method or ordinary static local function.
333fred marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, but why are operators/properties restricted here? Is it just a language limitation, similar to binding against a signature that takes explicit this for instance methods?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, this is a language limitation.

The C# compiler will mark any non-static or static non-ordinary methods imported from metadata with this attribute as
unsupported by the language.
* It is an error for a method marked with the attribute to have a parameter or return type that is not an `unmanaged_type`.
* It is an error for a method marked with the attribute to have type parameters, even if those type parameters are
constrained to `unmanaged`.
* It is an error for a method in a generic type to be marked with the attribute.
* 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
convention `modopt`s in metadata.
Expand Down