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

Roslyn allows additional *primary_constraints* when the notnull primary constraint is used #75892

Open
BillWagner opened this issue Nov 13, 2024 · 2 comments

Comments

@BillWagner
Copy link
Member

Version Used:

C# 12 and C# 13, with LangVersion set from C# 8 through C# 13.

Use the following code:

using System.IO;

public class C1<T> where T : notnull, Stream {}
public class C2<T> where T : notnull, Stream? {}

See sharplab

Expected Behavior:

According to 15.2.5 only one primary_constraint can be specified. The Nullable reference types specification - 9.0 classifies the notnull constraint as a primary constraint. Therefore, both the above declarations should be prohibited.

Actual Behavior:

Both declarations are allowed.

See dotnet/csharpstandard#1178 (comment)

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 13, 2024
@BillWagner BillWagner changed the title Roslyn allows additional *primary_constraints* when the notnull primary constraing is used Roslyn allows additional *primary_constraints* when the notnull primary constraint is used Nov 13, 2024
@jaredpar
Copy link
Member

@jcouv, @RikkiGibson is this a spec or impl bug?

@RikkiGibson
Copy link
Contributor

This appears to be an impl bug as the csharplang spec works by adding notnull as a new production of primary_constraint.

However, as mentioned on the csharpstandard PR, I wouldn't expect us to make a breaking change here, except perhaps adding a warning in the where T : notnull, Class or similar cases to indicate that notnull is notnecessary.

@jaredpar jaredpar added Feature - Nullable Reference Types Nullable Reference Types Feature - Warning Waves Warning Waves and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 20, 2024
@jaredpar jaredpar added this to the Backlog milestone Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants