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

[mono] Lack of generic parameter constraint checks for override methods #99967

Open
fanyang-mono opened this issue Mar 19, 2024 · 3 comments
Open

Comments

@fanyang-mono
Copy link
Member

fanyang-mono commented Mar 19, 2024

This issue was discovered when trying to add GENERIC_PARAMETER_ATTRIBUTE_ACCEPT_BYREFLIKE_CONSTRAINTS check for override methods. Other generic parameter checks are probably not in place either.

One possible place to add this check is mono_class_setup_vtable_general - where it calls mono_metadata_signature_equal (cmsig, m1sig).

Should also consider methods of interfaces too.

@fanyang-mono
Copy link
Member Author

cc/ @lambdageek

@lambdageek
Copy link
Member

lambdageek commented Mar 20, 2024

So the general issue is that if you have some parent class or an interface with a generic method M<T>(...) where T : ConstraintClass (or a special constraint like new,struct, etc) and a subclass also implements M<T>(...) but leaves out the constraint (or uses a constraint that doesn't match), mono will just accept that.
(Note you need to write the code in IL - Roslyn rejects unsatisfied constraints in C#). The correct behavior is to fail the class.

There are three cases (possibly more):

  1. a subclass tries to override an ancestor class's method but doesn't have the right constraints
  2. a class or interface implicitly implements an interface's method but doesn't have the right constraints
  3. a class or interface explicitly implements an interface's method but doesn't have the right constraints.

It's all in mono_class_setup_vtable_general but in different loops

@steveisok steveisok modified the milestones: 9.0.0, Future Aug 5, 2024
@steveisok
Copy link
Member

Moving to future and we should revisit if C# expands usage of ref structs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants