Skip to content

Fix nested generic constructor - #3501

Merged
josesimoes merged 4 commits into
nanoframework:developfrom
josesimoes:fix-nested-generic-ctor
Jul 24, 2026
Merged

Fix nested generic constructor#3501
josesimoes merged 4 commits into
nanoframework:developfrom
josesimoes:fix-nested-generic-ctor

Conversation

@josesimoes

@josesimoes josesimoes commented Jul 24, 2026

Copy link
Copy Markdown
Member

Description

  • Now properly resolving nested types in CEE_NEWOBJ.
  • Update CLAUDE with reasoning and new findings.

Motivation and Context

How Has This Been Tested?

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)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, 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).

- Now properly resolving nested types in CEE_NEWOBJ.
- Update CLAUDE with reasoning and new finding.

Assisted by Claude Opus 4.8.
@josesimoes josesimoes added the Area: Interpreter Everything related with the interpreter, execution engine and such label Jul 24, 2026
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 42452ce0-9c82-4a1d-bd02-1655ff7e3533

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

CEE_NEWOBJ now resolves nested generic constructor contexts by substituting caller type arguments, finding closed TypeSpec metadata, or using arrayElementType for single-VAR cases. Instantiation prioritizes the nested result, while documentation records the frame invariant and guarded implementation strategy.

Changes

Nested generic construction

Layer / File(s) Summary
Nested TypeSpec resolution
src/CLR/Core/Interpreter.cpp, src/CLR/Core/CLAUDE.md
CEE_NEWOBJ resolves nested generic arguments, selects a closed TypeSpec or arrayElementType, and documents the constructor-frame invariant.
Generic context selection and guarding
src/CLR/Core/Interpreter.cpp, src/CLR/Core/CLAUDE.md
Nested generic context is preferred during instantiation, with handling restricted to the guarded CEE_NEWOBJ path.

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

Sequence Diagram(s)

sequenceDiagram
  participant CEE_NEWOBJ
  participant CallerGenericContext
  participant MetadataAssemblies
  CEE_NEWOBJ->>CallerGenericContext: resolve callee generic arguments
  CEE_NEWOBJ->>MetadataAssemblies: search for matching closed TypeSpec
  MetadataAssemblies-->>CEE_NEWOBJ: return TypeSpec or no match
  CEE_NEWOBJ->>CEE_NEWOBJ: select nested generic context
Loading

Possibly related PRs

Suggested labels: Type: documentation

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: fixing nested generic constructor handling.
Description check ✅ Passed The description matches the code changes and clearly explains the nested generic resolution fix and documentation update.
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.

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

Comment @coderabbitai help to get the list of available commands.

@josesimoes

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor
✅ 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 and others added 2 commits July 24, 2026 11:34
Automated fixes for code style.
…142c8-194a-42fa-a1f7-0da833b3ce89

Code style fixes for nanoframework/nf-interpreter PR#3501

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/CLR/Core/Interpreter.cpp (1)

3019-3027: 🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick win

genericType/arrayElementType invariant violated when a nested closed TypeSpec is found.

calleeInst.arrayElementType is pre-set to propagatedArrayElementType at line 3027, before nested-generic resolution runs. When closedMatch != nullptr (line 3179), only calleeInst.genericType is updated — arrayElementType is never cleared. If the caller frame had a valid propagated arrayElementType (e.g. from an SZArrayHelper/array-dispatch context), both fields end up simultaneously valid on the same constructor frame, exactly the corruption case CLAUDE.md documents: "corrupts newarr's element-type resolution (native AccessViolation)."

🐛 Proposed fix
                                    if (closedMatch != nullptr)
                                    {
                                        calleeInst.genericType = closedMatch;
                                        nestedGenericTag = closedMatch;
+                                       // Invariant: never set both genericType and arrayElementType — see CLAUDE.md §9.
+                                       calleeInst.arrayElementType = CLR_RT_TypeDef_Index{};
                                    }
                                    else if (argCount == 1)
                                    {
                                        // Never set alongside genericType above — see CLAUDE.md §9.
                                        calleeInst.arrayElementType = resolvedArgs[0];
                                    }

Also applies to: 3179-3192

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/CLR/Core/Interpreter.cpp` around lines 3019 - 3027, When nested closed
TypeSpec resolution finds a non-null closedMatch, update the constructor frame
so calleeInst.genericType is set and calleeInst.arrayElementType is cleared,
preserving the invariant that both fields are never simultaneously valid. Adjust
the logic around calleeInst initialization and the closedMatch handling near
ResolveToken to ensure the clear occurs only for this nested closed-TypeSpec
path.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/CLR/Core/Interpreter.cpp`:
- Around line 3086-3127: Update the generic-argument loop in the
owner-resolution block to fully consume each argument subtree before processing
the next argument: repeatedly advance the signature parser until the current
argument’s Available() count reaches zero. Preserve resolution for concrete
class arguments, but mark resolution failed for arrays or open generic
parameters, matching the behavior of the analogous type-signature closure
helpers.

---

Outside diff comments:
In `@src/CLR/Core/Interpreter.cpp`:
- Around line 3019-3027: When nested closed TypeSpec resolution finds a non-null
closedMatch, update the constructor frame so calleeInst.genericType is set and
calleeInst.arrayElementType is cleared, preserving the invariant that both
fields are never simultaneously valid. Adjust the logic around calleeInst
initialization and the closedMatch handling near ResolveToken to ensure the
clear occurs only for this nested closed-TypeSpec path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c735981c-71b5-49b6-81ea-53d80ec77635

📥 Commits

Reviewing files that changed from the base of the PR and between 78d91c9 and 8680d6f.

📒 Files selected for processing (2)
  • src/CLR/Core/CLAUDE.md
  • src/CLR/Core/Interpreter.cpp

Comment thread src/CLR/Core/Interpreter.cpp
@josesimoes
josesimoes merged commit aa909d2 into nanoframework:develop Jul 24, 2026
29 checks passed
@josesimoes
josesimoes deleted the fix-nested-generic-ctor branch July 24, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Interpreter Everything related with the interpreter, execution engine and such Type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants