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

Add Nullability annotations to projected API #716

Closed
dotMorten opened this issue Jun 3, 2020 · 12 comments
Closed

Add Nullability annotations to projected API #716

dotMorten opened this issue Jun 3, 2020 · 12 comments

Comments

@dotMorten
Copy link

.NET 3.1/NetStandard2.1 added nullability annotations to .NET Core.

Are there plans to also have the WinRT projections be annotated, so we know which members can return/accept null and which can not, so we can reduce null-checks where they aren't needed, and ensure we add them where they are?
This greatly increases the quality of the code base, as well as the quality for any apps consuming it, and reduces time spent debugging ArgumentNullExceptions and NullReferenceExceptions.

Resources:

@AdamBraden
Copy link
Contributor

WinRT type system doesn't support nullable types.

@manodasanW manodasanW transferred this issue from microsoft/CsWinRT Oct 30, 2020
@dotMorten
Copy link
Author

@AdamBraden while I realize it would be a lot of work, would it be possible to start annotating using some sort of convention though? (even if it was via an external manifest-sort-of-file that is used when generating the C# projections). The nullability feature in C#8 starts falling apart as soon as one referenced component doesn't support it

@kennykerr
Copy link
Contributor

For what its worth, I also proposed this: #708

I think it was deemed impractical to go back and annotate the many existing APIs that are known to be non-null.

@kennykerr
Copy link
Contributor

WinRT type system doesn't support nullable types.

The WinRT type system does support nullable types - most of them are nullable. The issue is that in many cases those values are known to be non-null, but compilers have no way of knowing that.

@dotMorten
Copy link
Author

Is it possible to annotate it instead? (I realize that's a lot of manual labor but so was it with .net source)

@kennykerr
Copy link
Contributor

I'm not sure what you're asking. We couldn't manually annotate the language projections even if we wanted to as they are generated (and often regenerated on demand as part of the build). The language projections are generated from winmd files (binary metadata) - the WinRT attribute I proposed could be used to annotate the definitions of the various APIs that would then feed into the winmd files so that language projections can use that information as appropriate. In the case of C#, it could use that information to apply the NotNullAttribute to appropriate parameters and return types.

@dotMorten
Copy link
Author

dotMorten commented Nov 25, 2020

Yeah that's what I meant: Find a way to annotate prior to generating the winmd. Or perhaps for those that have .idl files, create a way to at least annotate those?
I realize there isn't a good way to do it today but would be a good longer term goal.

@kennykerr
Copy link
Contributor

Yep, that's what my proposal is all about.

@github-actions
Copy link

github-actions bot commented Mar 8, 2023

This issue is stale because it has been open 10 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@dotMorten
Copy link
Author

You want us to add a ping every 10 days now?

@kennykerr
Copy link
Contributor

Realistically this isn't something I see happening. #708 (comment)

@kennykerr
Copy link
Contributor

By the way, I'm working on new tooling for metadata generation over here. I expect that will eventually replace tools like MIDL and MDMERGE and could make it easier to express type system attributes more freely.

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

No branches or pull requests

3 participants