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

Preserve type metadata for casts to WinRT runtime classes. #1873

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dongle-the-gadget
Copy link
Contributor

Fixes #1860.

Note

You should disable whitespaces before looking at the changes.

Verified

This commit was signed with the committer’s verified signature.
ychin Yee Cheng Chin
Copy link
Member

@Sergio0694 Sergio0694 left a comment

Choose a reason for hiding this comment

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

We should definitely add some functional tests (at least) for this change.

Verified

This commit was signed with the committer’s verified signature.
ychin Yee Cheng Chin
@dongle-the-gadget
Copy link
Contributor Author

I added a test in, though I didn't actually check it no further than making sure the C++ generates the correct WinMD (since my machine is very limited in spec and I don't want to slam it).
I did manage to test the source generator using another project by casting a XAML resource into a Style using cast expressions and that did work.

@hez2010
Copy link
Contributor

hez2010 commented Nov 21, 2024

I don't think this can be easily handled in a source generator.
The type cast can happen in anywhere especially now we have pattern matching, for example,

if (obj is { A: Foo { B: Bar(_, Baz { C: [WinRTType x, ..] }) })
{
    // use x here
}

switch (obj)
{
    case  { A: Foo { B: Bar(_, Baz { C: [WinRTType x, var y] }) } when y is AnotherWinRTType:
        // use x and y here
        break;
}

We should instead doing this at IL level so that we only need to look for isinst.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Cannot cast some of the UWP activation arguments using dotnet as operator
3 participants