Skip to content

Add parameter reflection regression tests - #134025

Open
MichalStrehovsky wants to merge 1 commit into
dotnet:mainfrom
MichalStrehovsky:nativeaot-parameterinfo-tests
Open

MichalStrehovsky wants to merge 1 commit into
dotnet:mainfrom
MichalStrehovsky:nativeaot-parameterinfo-tests

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Cover missing defaults, unnamed parameter formatting, modified types for indexers and synthetic array members, and runtime parameter reconstruction.

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

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky MichalStrehovsky added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Sep 16, 2026
@MichalStrehovsky

Copy link
Copy Markdown
Member Author

I expect these to fail on native AOT until #134027 is merged.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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: RuntimePropertyIndexParameterInfo does not override GetModifiedParameterType, so it inherits ParameterInfo.GetModifiedParameterType() and throws NotSupportedException. 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 RuntimeSyntheticParameterInfo has no GetModifiedParameterType override, so each array constructor parameter here throws NotSupportedException (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 ParameterInfo stores the member and position in private fields but leaves the base MemberImpl unset, so the inherited ParameterInfo.GetRealObject throws SerializationException for 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

Comment on lines +91 to +95
public static IEnumerable<object[]> ParametersWithoutMetadata_TestData()
{
yield return new object[] { typeof(ParameterInfoMetadata).GetMethod(nameof(ParameterInfoMetadata.Method1)), -1 };

Type arrayType = typeof(int[,]);

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Reflection NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants