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

Unit test for invalid cast of Guid passes #757

Closed
edleno2 opened this issue May 26, 2021 · 1 comment · Fixed by nanoframework/nf-interpreter#1956
Closed

Unit test for invalid cast of Guid passes #757

edleno2 opened this issue May 26, 2021 · 1 comment · Fixed by nanoframework/nf-interpreter#1956

Comments

@edleno2
Copy link

edleno2 commented May 26, 2021

Details about Problem

Unit test that is part of UnitTestParseTests where a runtime cast of a Guid to an int is passing, it should fail and does in a .net core test.

nanoFramework area: (C# code)
nf-Interpreter

VS version: (2017 | 2019 )

VS extension version:

Target:

Device capabilities output:

Description

Cast to int works because the current implementation of Guid uses uint8 as it's base type, and not a unique data type.

Detailed repro steps so we can see the same problem

  1. Run NFUnitTestSystemLib/UnitTestParseTests/box_unbox_Test_1

Other suggested things

Need to do the work to make Guid an actual data type.

Expected behaviour

You should not be able to cast at runtime from a Guid to an int (or any other type). Normally this behavior is caught at compile time, but as in the test case you can use object types as intermediates to allow a runtime (late) cast of the objects.

Sample Project

Screenshot

Additional context

I've made an effort to fix the bug

Have tried this but ran into a number of problems, so backed out to complete other issue. This issue is to document the special case of Guid.

@josesimoes
Copy link
Member

@edleno2 I've fixed this is the interpreter by adding a new know type for GUID and adding a new check when executing unbox.any to make sure the cast from GUID is not possible.

@josesimoes josesimoes self-assigned this Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants