-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add test and Mono fix for custom attribute with generic enum function pointer array argument #123445
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
base: main
Are you sure you want to change the base?
Conversation
…nction pointer array Co-authored-by: lewing <24063+lewing@users.noreply.github.com>
Co-authored-by: lewing <24063+lewing@users.noreply.github.com>
|
this is meant to land after #123439 as a test for the mono crash. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds both a Mono runtime fix and a regression test for a crash that occurred when loading custom attributes with generic enum constructor arguments involving function pointer arrays.
Changes:
- Fixed Mono runtime crash in custom attribute decoding for generic enum types with function pointer arrays
- Added regression test to prevent future occurrences of this issue
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/mono/mono/metadata/custom-attrs.c | Defers tklass initialization for MONO_TYPE_GENERICINST types and updates assertion to handle generic instance cases, preventing crash during custom attribute value loading |
| src/libraries/System.Runtime/tests/System.Reflection.Tests/CustomAttributeTests.cs | Adds CustomAttributeCtor_WithGenericEnumArgument_DecodesCorrectly test to verify custom attributes with generic enum arguments involving function pointer arrays decode without crashing |
| var arg = attr.ConstructorArguments.Single(); | ||
| Assert.Equal(typeof(CustomAttributeTypedArgument), arg.GetType()); |
Copilot
AI
Jan 31, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding more comprehensive assertions to validate the actual argument value and type, similar to the BoxedEnumAttributes() test pattern on lines 259-277. For example, you could assert that arg.ArgumentType equals the expected generic enum type typeof(GenericClassForEnum<delegate*<void>[]>.E) and verify the value is the default enum value (0). This would provide stronger regression coverage beyond just ensuring the code doesn't crash.
Description
Adds regression test and Mono runtime fix for custom attribute decoding with generic enum arguments involving function pointer arrays. This scenario crashed Mono runtime due to incorrect MonoClass resolution for
MONO_TYPE_GENERICINSTwhen loading custom attribute values (see #123439).Changes Made
Test Addition (
System.Reflection.Tests/CustomAttributeTests.cs):CustomAttributeCtor_WithGenericEnumArgument_DecodesCorrectlytest methodGenericClass<delegate*<void>[]>.Edecodes successfullyCustomAttributesandConstructorArgumentson decorated typesMono Runtime Fix (merged from PR #123439 -
src/mono/mono/metadata/custom-attrs.c):load_cattr_value()to defertklassinitialization forMONO_TYPE_GENERICINSTtypesload_cattr_value_boxed()to properly handle generic instance casesThis PR provides both the fix and comprehensive test coverage for the issue, ensuring the regression is caught in future test runs.
Original prompt
This pull request was created from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.