Skip to content

Add generic variance and array assignability tests - #307

Merged
josesimoes merged 1 commit into
nanoframework:developfrom
josesimoes:generics-fixes-and-variance
Nov 19, 2026
Merged

josesimoes merged 1 commit into
nanoframework:developfrom
josesimoes:generics-fixes-and-variance

Conversation

@josesimoes

@josesimoes josesimoes commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Description

  • Add variance, array view, stelem, Array.Copy, Invoke and SetValue tests.
  • Update tests that expected NotSupportedException or InvalidCastException for now valid casts.

Motivation and Context

How Has This Been Tested?

  • [tested against nanoclr BuildId 68427]

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.

- Add variance, array view, `stelem`, `Array.Copy`, `Invoke` and `SetValue` tests.
- Update tests that expected `NotSupportedException` or `InvalidCastException` for now valid casts.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Reflection assignability checks now account for generic interface and delegate variance, including covariance and contravariance.
    • Array compatibility checks now recognize supported conversions between same-size integral and enum element types, including jagged arrays.
  • Tests
    • Expanded coverage for variance, array casts and copies, collection views, and expected failures.

The pull request adds tests for generic variance, reflection operations, and array compatibility. It updates existing assignability expectations and includes the new variance test file in the test project.

Changes: Generic variance and array reflection tests

Layer / File(s) Summary
Variance test fixtures
Tests/NFUnitTestSystemLibReflection2/UnitTestGenericVarianceTests.cs, Tests/NFUnitTestSystemLibReflection2/NFUnitTestSystemLibReflection2.nfproj
Adds public test interfaces, types, and implementations. The project now compiles the new test file.
Generic variance and reflection checks
Tests/NFUnitTestSystemLibReflection2/UnitTestGenericVarianceTests.cs, Tests/NFUnitTestSystemLibReflection2/UnitTestGenericParameterConstraintTests.cs, Tests/NFUnitTestSystemLibReflection2/UnitTestGenericTypeIdentityTests.cs
Adds tests for generic variance and reflection operations. Existing assignability tests now expect supported covariance cases to succeed.
Array compatibility checks
Tests/NFUnitTestSystemLibReflection2/UnitTestGenericVarianceTests.cs, Tests/NFUnitTestSystemLibReflection/UnitTestGenericArgumentTests.cs, Tests/NFUnitTestSystemLibReflection2/UnitTestGenericTypeIdentityTests.cs
Adds tests for array compatibility, copying, rank, and collection views. Existing array assignability tests now expect the listed integral, enum, and jagged-array cases to succeed.

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

Change: Other

Possibly related PRs

Merge Risk: Minimal · up to 492df

This PR only adds and updates unit tests for generic variance and array assignability. It does not change runtime code, so the risk of merging is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Add generic variance and array assignability tests" (50 characters) matches the changeset, which adds UnitTestGenericVarianceTests and updates assignability expectations for covariant inter…
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 lists the changeset's contents: adds variance, array view, stelem, Array.Copy, Invoke and SetValue tests, and updates tests that expected NotSupportedException or InvalidCastException …
Full details: Title check

Explanation

The title "Add generic variance and array assignability tests" (50 characters) matches the changeset, which adds UnitTestGenericVarianceTests and updates assignability expectations for covariant interfaces, delegates, and integral/enum array conversions. It has no PR or issue references and no terminal full stop, and it fits the under-50-character guideline at exactly 50 characters.

Full details: Description check

Explanation

The description lists the changeset's contents: adds variance, array view, stelem, Array.Copy, Invoke and SetValue tests, and updates tests that expected NotSupportedException or InvalidCastException for casts that are now valid. This matches the summarized changes in the generic variance and generic type identity test files, so the description is related to the changeset.

Finishing Touches

Fix failing CI checks

  • Create a new PR
  • 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

Recent 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: 7680b50c-c0d8-4e7c-8275-6d6ab8b5d268
Commits

Reviewing files that changed from the base of the PR and between 43d14c2 and 492df5f.

Files selected for processing: 5

  • Tests/NFUnitTestSystemLibReflection/UnitTestGenericArgumentTests.cs
  • Tests/NFUnitTestSystemLibReflection2/NFUnitTestSystemLibReflection2.nfproj
  • Tests/NFUnitTestSystemLibReflection2/UnitTestGenericParameterConstraintTests.cs
  • Tests/NFUnitTestSystemLibReflection2/UnitTestGenericTypeIdentityTests.cs
  • Tests/NFUnitTestSystemLibReflection2/UnitTestGenericVarianceTests.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

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 19, 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.

@nfbot

nfbot commented Nov 19, 2026

Copy link
Copy Markdown
Member

⚠️ Native declaration update required!

The native contract hash of nanoFramework.CoreLibrary has changed. The native declaration in nf-interpreter must be updated before this package can be released.

Previously published This build
Native contract hash 0x532E6934 0x824177B9

👉 Tracking issue: nanoframework/Home#1954

The issue contains a link to the stubs artifact from this build and instructions for GitHub Copilot to perform the update.

@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 d3b3131 into nanoframework:develop Nov 19, 2026
7 checks passed
@josesimoes
josesimoes deleted the generics-fixes-and-variance branch November 19, 2026 11:36
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