Add parameter reflection regression tests - #134025
MichalStrehovsky wants to merge 1 commit into
Conversation
Cover missing defaults, unnamed parameter formatting, modified types for indexers and synthetic array members, and runtime parameter reconstruction. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b689a562-006b-4ec0-8607-f5a91479388e
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 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 |
|
I expect these to fail on native AOT until #134027 is merged. |
There was a problem hiding this comment.
🟡 Changes recommended
Unconditional tests are incompatible with NativeAOT behavior and need platform-specific handling or implementation updates.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds reflection regression tests for parameter defaults, formatting, modified types, and runtime reconstruction.
Changes:
- Covers missing defaults and unnamed parameters.
- Tests indexer and synthetic array parameter types.
- Verifies runtime parameter reconstruction.
File summaries
| File | Summary |
|---|---|
src/libraries/System.Runtime/tests/System.Reflection.Tests/ParameterInfoTests.cs |
Adds reflection regression tests and supporting fixtures. |
Review details
Suppressed comments (4)
src/libraries/System.Runtime/tests/System.Reflection.Tests/ParameterInfoTests.cs:583
- NativeAOT will fail this new test before reaching the assertions:
RuntimePropertyIndexParameterInfodoes not overrideGetModifiedParameterType, so it inheritsParameterInfo.GetModifiedParameterType()and throwsNotSupportedException. Since this project is included in NativeAOT library tests, either add the forwarding implementation there or exclude this case until that support exists.
public void GetModifiedParameterType_IndexParameter(Type indexType)
{
PropertyInfo property = typeof(ParameterInfoMetadata).GetProperty("Item", new[] { indexType });
ParameterInfo parameter = Assert.Single(property.GetIndexParameters());
src/libraries/System.Runtime/tests/System.Reflection.Tests/ParameterInfoTests.cs:605
- NativeAOT's
RuntimeSyntheticParameterInfohas noGetModifiedParameterTypeoverride, so each array constructor parameter here throwsNotSupportedException(as do the later array method and return parameters). This test is unconditionally run in NativeAOT library tests; either implement the missing NativeAOT behavior or gate these cases until it is supported.
public void GetModifiedParameterType_SyntheticArrayParameters(Type arrayType)
{
foreach (ConstructorInfo constructor in arrayType.GetConstructors())
{
foreach (ParameterInfo parameter in constructor.GetParameters())
Verify(parameter.ParameterType, parameter.GetModifiedParameterType());
src/libraries/System.Runtime/tests/System.Reflection.Tests/ParameterInfoTests.cs:660
- This extra round-trip fails on NativeAOT: its runtime
ParameterInfostores the member and position in private fields but leaves the baseMemberImplunset, so the inheritedParameterInfo.GetRealObjectthrowsSerializationExceptionfor insufficient state. Because this test runs in the NativeAOT library matrix, either populate the base serialization state/fix the implementation or gate this assertion with the appropriate platform issue.
ParameterInfo resolved = (ParameterInfo)result.GetRealObject(sc);
Assert.Equal(result.Member, resolved.Member);
Assert.Equal(result.Position, resolved.Position);
Assert.Equal(result.ParameterType, resolved.ParameterType);
src/libraries/System.Runtime/tests/System.Reflection.Tests/ParameterInfoTests.cs:137
- This formatting assertion is not portable to NativeAOT:
RuntimeParameterInfo.ToString()there unconditionally appends" " + Name, so the null name on these return/synthetic parameters produces a trailing space. The theory therefore fails on NativeAOT; update that implementation or gate the affected cases.
public void ToString_UnnamedParameter_OmitsTrailingSpace(MethodBase member, int position)
{
ParameterInfo parameter = GetParameterInfo(member, position);
Assert.Null(parameter.Name);
Assert.Equal(parameter.ParameterType.Name, parameter.ToString());
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
| public static IEnumerable<object[]> ParametersWithoutMetadata_TestData() | ||
| { | ||
| yield return new object[] { typeof(ParameterInfoMetadata).GetMethod(nameof(ParameterInfoMetadata.Method1)), -1 }; | ||
|
|
||
| Type arrayType = typeof(int[,]); |
Cover missing defaults, unnamed parameter formatting, modified types for indexers and synthetic array members, and runtime parameter reconstruction.