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

Collection expression arguments: support [CollectionBuilder] factory methods #76998

Draft
wants to merge 1 commit into
base: features/dictionary-expressions
Choose a base branch
from

Conversation

cston
Copy link
Member

@cston cston commented Feb 1, 2025

Binding and lowering of collection expression arguments for target types that are constructed using [CollectionBuilder] factory methods.

See proposals/collection-expression-arguments.md

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 1, 2025
@cston cston force-pushed the collection-builder-args branch from da3c3e3 to 6c4fc7e Compare February 2, 2025 01:13
Diagnostic(ErrorCode.WRN_NullabilityMismatchInTypeParameterNotNullConstraint, "[null]").WithArguments("MyCollectionBuilder.Create<T>(System.ReadOnlySpan<T>)", "T", "string?").WithLocation(7, 28),
//// (7,28): warning CS8714: The type 'string?' cannot be used as type parameter 'T' in the generic type or method 'MyCollectionBuilder.Create<T>(ReadOnlySpan<T>)'. Nullability of type argument 'string?' doesn't match 'notnull' constraint.
//// MyCollection<string?> x1 = [null]; // 1
//Diagnostic(ErrorCode.WRN_NullabilityMismatchInTypeParameterNotNullConstraint, "[null]").WithArguments("MyCollectionBuilder.Create<T>(System.ReadOnlySpan<T>)", "T", "string?").WithLocation(7, 28),
Copy link
Member Author

@cston cston Feb 2, 2025

Choose a reason for hiding this comment

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

WRN_NullabilityMismatchInTypeParameterNotNullConstraint

This case was previously handled in Binder.GetAndValidateCollectionBuilderMethod() in the call to collectionBuilderMethod.CheckConstraints(). That was unintentional, because initial binding should check type constraints but not nullability constraints. Nullability constraints should be checked in NullableWalker, and the existing work item in #68786 covers that.

@cston cston force-pushed the collection-builder-args branch from 242f3ea to 399140a Compare February 4, 2025 17:41
@cston cston force-pushed the collection-builder-args branch from 399140a to f826cdb Compare February 4, 2025 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant