Repository navigation
Fix FieldInfo.GetValue for enum literals on open generic types on NativeAOT and add test - #138474
Manish-1kumar wants to merge 4 commits into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the test-only change adding regression coverage for enum literals in open generic types.
No open issues 🎉
What changed in this PR
Adds regression coverage for #7976 to the reflection test suite, verifying the existing behavior established by #129424 without changing runtime code.
Changes:
- Tests that
FieldInfo.GetValueon an enum literal nested in an open generic type returns the underlying value. - Adds a byte-backed enum fixture and asserts both the exact returned type and value, preventing an
intresult from passing accidentally.
| File | Description |
|---|---|
src/libraries/System.Runtime/tests/System.Reflection.Tests/FieldInfoTests.cs |
Adds the open-generic enum literal regression test and its byte-backed enum fixture. |
Review effort: Balanced
|
The test fails with NAOT. Can NAOT be fixed to make the test pass? |
NativeAOT throws PlatformNotSupportedException for field access on types with ContainsGenericParameters.
e48d3fe to
7322e78
Compare
…tiveAOT The literal field accessor was created with the field type's RuntimeTypeHandle, which throws PlatformNotSupportedException for types with ContainsGenericParameters. The handle isn't used for literal fields, so stop passing it, and run the regression test on NativeAOT again.
|
Fixed NativeAOT in 4f67519 instead of disabling the test. The literal field accessor was created with The test is a plain |
|
Thanks! It looks like the trigger for bf4c053 was lost during the outage. Could you run |
I haven't forgotten about this, but the CI is still offline. |
Fixes #7976
FieldInfo.GetValueon a literal field of an enum nested in an open generic type (for exampletypeof(Generic<>.GenericEnum)) must not produce an instance of an open generic type. On CoreCLR it returns the underlying value since #129424. On NativeAOT it threwPlatformNotSupportedException("TypeHandles are not supported for types that return true for ContainsGenericParameters").NativeAOT fix: the literal field accessor was created with
FieldType.TypeHandle, which throws for types withContainsGenericParameters.LiteralFieldAccessornever uses the handle (it returns the stored constant and its setters throw), soCreateLiteralFieldAccessorno longer takes one. The constant itself is already returned as the underlying value byDefaultValueParser(#129424).Test: adds
FieldInfoTests.GetValue_EnumLiteralFieldOnOpenGenericType_ReturnsUnderlyingValue. #129424 added coverage forParameterInfo.DefaultValueand the enum APIs, but nothing exercisedFieldInfo.GetValueon the enum's literal field. The test uses abyte-backed enum, so it checks that the value comes back as the underlying type rather than anintby coincidence.Verification:
ParameterInfo.DefaultValueand enum reflection APIs for nested enums on open generic types #129424./p:TestNativeAot=truepasses locally (2071 run, 0 failures, 47 skipped).