Skip to content

Add generic reflection tests - #293

Merged
josesimoes merged 2 commits into
nanoframework:developfrom
josesimoes:add-generic-reflection-t-tests
Nov 10, 2026
Merged

josesimoes merged 2 commits into
nanoframework:developfrom
josesimoes:add-generic-reflection-t-tests

Conversation

@josesimoes

@josesimoes josesimoes commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Description

  • Cover GetType, return, field and parameter types of T.
  • Cover SetValue, statics and Invoke on closed generic types.
  • Update tests that expected T to be unresolved.
  • Add more tests to cover T bound to nested generics and arrays

Motivation and Context

How Has This Been Tested?

  • [tested against nanoclr BuildId 67940]

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (add new Unit Test(s) or improved existing one(s), has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).
  • I have added new tests to cover my changes.

- Cover GetType, return, field and parameter types of T.
- Cover SetValue, statics and Invoke on closed generic types.
- Update tests that expected T to be unresolved.

Assisted by: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

Summary

Summary by CodeRabbit

  • Tests
    • Expanded coverage for reflection on closed generic types, including type identity, resolved parameter and return types, fields, static fields, constructors, and method invocation.
    • Added checks for handling mismatched generic arguments and values, including expected exceptions.
    • Updated invocation tests to verify that type parameters resolve from a constructed generic type and that incompatible arguments are rejected.

The project adds generic reflection tests for closed-type metadata, fields, static storage, construction, and method invocation. Existing invocation and parameter metadata tests now expect type parameters on closed generic types to resolve from the closed type.

Changes: Generic Reflection

Layer / File(s) Summary
Closed generic metadata and invocation expectations
Tests/NFUnitTestSystemLibReflection/NFUnitTestSystemLibReflection.nfproj, Tests/NFUnitTestSystemLibReflection/UnitTestGenericReflectionTests.cs, Tests/NFUnitTestSystemLibReflection/UnitTestReflectionInvokeTests.cs, Tests/NFUnitTestSystemLibReflection/UnitTestGenericArgumentTests.cs
New tests cover closed generic identity and reflected property types. Updated tests expect closed-type parameter metadata and invocation to resolve from the type argument, and check rejection of mismatched arguments.
Generic field access and static storage
Tests/NFUnitTestSystemLibReflection/UnitTestGenericReflectionTests.cs
New tests cover generic field types and access, mismatched field values, per-instantiation static values, static initialization, and reads through a generic type definition.
Reflective construction and method calls
Tests/NFUnitTestSystemLibReflection/UnitTestGenericReflectionTests.cs
New tests cover constructor invocation, closed-type creation, setter and getter invocation, and mismatched arguments or methods. The project compiles the new test file.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Possibly related PRs

  • nanoframework/CoreLibrary#291: Covers invocation of a parameter typed as T; this PR updates the corresponding test expectations for a closed generic type.
  • nanoframework/CoreLibrary#285: Covers generic parameters in reflection invocation and parameter metadata; this PR updates expectations for closed generic types.

Suggested labels: Area: Config-and-Build

Merge Risk: Minimal · up to 6c984

No actionable issue remains that should delay merging these reflection tests after normal checks.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly summarizes the changes: adding generic reflection tests. It is concise and does not end with a period.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description matches the changes. It identifies the new generic reflection tests, the updated expectations for closed generic types, and the reported test coverage.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@josesimoes

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Additional comments: 1

Tests/NFUnitTestSystemLibReflection/UnitTestReflectionInvokeTests.cs-390-390: 1

390-390: Trivial · Maintainability & Code Quality · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Rename the tests to match their new behavior.

Invoke_UnresolvedMethodTypeParameter_IsNotSupported still has the old name. The test now asserts that G<int>.TakesT works. It also asserts the NotSupportedException case for the method-level TakesMethodT. GetParameters_UnresolvedMethodTypeParameter_HasNullType now mostly asserts resolved types. The names give a wrong description of the intended behavior. Use names that state both outcomes, for example Invoke_TypeParameterOnClosedType_IsResolved_MethodTypeParameter_IsNotSupported.

Also applies to: 530-530

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML; Path: .coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: d8327ca1-11fa-4ec9-a0e5-2c8f80d9398e
Commits

Reviewing files that changed from the base of the PR and between f9a6ba8 and 6c98496.

Files selected for processing: 4

  • Tests/NFUnitTestSystemLibReflection/NFUnitTestSystemLibReflection.nfproj
  • Tests/NFUnitTestSystemLibReflection/UnitTestGenericArgumentTests.cs
  • Tests/NFUnitTestSystemLibReflection/UnitTestGenericReflectionTests.cs
  • Tests/NFUnitTestSystemLibReflection/UnitTestReflectionInvokeTests.cs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@josesimoes
josesimoes force-pushed the add-generic-reflection-t-tests branch from 196dd55 to 2067f49 Compare November 10, 2026 17:52
@josesimoes

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@josesimoes

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@sonarqubecloud

Copy link
Copy Markdown

@josesimoes
josesimoes merged commit 702e92a into nanoframework:develop Nov 10, 2026
7 checks passed
@josesimoes
josesimoes deleted the add-generic-reflection-t-tests branch November 10, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants