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

Unconstrained type parameter annotation proposal #3035

Closed
wants to merge 2 commits into from

Conversation

cston
Copy link
Member

@cston cston commented Dec 17, 2019

No description provided.


`ITypeParameterSymbol.NullableAnnotation` will return `NullableAnnotation.Annotated` for `T??`, indistinquisable from `T?`.
To determine if that type parameter annotation would be represented in source as `??` would require checking the
constraints of the `ITypeParameterSymbol` which might involve checking constraints inherited from base types.
Copy link
Member

Choose a reason for hiding this comment

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

seems painful fwiw.

}
```

`T??` may be used interchangably with `[MaybeNull]T` in cases where `T` is not constrained to a value type or reference type.
Copy link
Member

Choose a reason for hiding this comment

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

I really hope this lands as T? at the end - for the same reasons that the team were avoiding introducing T!.

Furthermore, the fact that you need to change annotations T?? -> T? if you add a constraint is a pain point.

Choose a reason for hiding this comment

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

I really hope unconstrained T? will sooner or later end up as an unconstrained T? that is T? for reference types or T? for value types.

Copy link
Member

@alrz alrz Dec 18, 2019

Choose a reason for hiding this comment

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

I really hope unconstrained T? will sooner or later end up as an unconstrained T? that is T? for reference types or T? for value types.

That would probably require runtime changes but it's the ideal outcome. Personally I'm ok with [MaybeNull] for the time being. T?? would be just an oddball that I don't want to have to deal with.

@mikernet
Copy link

mikernet commented Jan 22, 2020

Sorry for posting here but I can't for the life of me find the discussion where @gafter and others are discussing unconstrained T nullable syntax.

Would T?? also be possible when T : notnull or only when T is strictly unconstrained? Please tell me it's the former.

@cston
Copy link
Member Author

cston commented Jan 22, 2020

@mikernet, T?? would be allowed where T : notnull and in other cases where T is not constrained to a value type or reference type.

@cston cston force-pushed the QuestionQuestion branch from a404f1e to 0227681 Compare April 25, 2020 04:08
@alrz
Copy link
Member

alrz commented Sep 28, 2020

Looks like this finally implemented as T??

BTW it's not documented in language feature status or https://github.com/dotnet/csharplang/tree/master/proposals/csharp-9.0

@cston
Copy link
Member Author

cston commented Sep 28, 2020

Replaced by support for T? for unconstrained T (see LDM-2020-06-17, dotnet/roslyn#45993).

@cston cston closed this Sep 28, 2020
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.

5 participants