Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi Cast Delegate with Struct types cause CLR_E_WRONG_TYPE exception #1829

Merged
merged 4 commits into from
Jan 12, 2021
Merged

Multi Cast Delegate with Struct types cause CLR_E_WRONG_TYPE exception #1829

merged 4 commits into from
Jan 12, 2021

Conversation

AdrianSoundy
Copy link
Member

@AdrianSoundy AdrianSoundy commented Jan 10, 2021

Description

MultiCast delegate for Structure value types( structs, DateTime, TimeSpan) causes a CLR_E_WRONG_TYPE error. Other types work ok. This looks like an edge case inherited from .NetMF.

Single Cast delegates work differently and don't have a problem.

This is due to the code trying to Unbox the valueType argument in CLR_RT_StackFrame::FixCall, but its doesn't need unboxing as its a structure type. The PerformUnboxing causes the error because it tests for valuetype to be boxed.

Adding an extra test for IsBoxed resolves issue.

Spent some time doing a delegate test program with various types , single and multi cast. Included test project with this PR

Motivation and Context

How Has This Been Tested?

Delegate test program (included)

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • 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)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@AdrianSoundy AdrianSoundy added Area: Interpreter Everything related with the interpreter, execution engine and such ⚠️ DO NOT MERGE ⚠️ Status: in progress labels Jan 10, 2021
@nfbot
Copy link
Member

nfbot commented Jan 10, 2021

@AdrianSoundy there are issues with the code style on the source files.
A PR was submitted with the code style fixes. Please review and merge the changes. See https://github.com/AdrianSoundy/nf-interpreter/pull/28.

Make sure you are using the project code style. Check the details here.

AdrianSoundy and others added 2 commits January 10, 2021 16:21
Automated fixes for code style.
@nfbot
Copy link
Member

nfbot commented Jan 10, 2021

@AdrianSoundy there are issues with the code style on the source files.
A PR was submitted with the code style fixes. Please review and merge the changes. See https://github.com/AdrianSoundy/nf-interpreter/pull/29.

Make sure you are using the project code style. Check the details here.

@AdrianSoundy
Copy link
Member Author

@AdrianSoundy
Copy link
Member Author

AdrianSoundy commented Jan 10, 2021

Tests for all types and arrays. Maybe be useful to update to test with generics

…c-ef7f-4cb0-b460-2b4c1f0bbb49' into MultiCast
Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

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

This test for the heapblock containing a boxed value seems to be all it takes to properly deal with this. Well done! 💯 👍🏻

@AdrianSoundy AdrianSoundy merged commit a9c2955 into nanoframework:develop Jan 12, 2021
@AdrianSoundy AdrianSoundy deleted the MultiCast branch January 12, 2021 11:24
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.

Multicast Delegate Invocation causes exception under certain circumstance.
3 participants