Add initial support for 'notnull' generic type constraint.#36109
Add initial support for 'notnull' generic type constraint.#36109AlekseyTs merged 7 commits intodotnet:masterfrom
Conversation
|
@dotnet/roslyn-compiler Please review. |
| NullableAttribute(1) should be placed on a type parameter definition that has a `class!` constraint. | ||
| NullableAttribute(2) should be placed on a type parameter definition that has a `class?` constraint. | ||
| NullableAttribute(2) should be placed on a type parameter definition that has no type constraints, `class`, `struct` and `unmanaged` constraints and | ||
| NullableAttribute(2) should be placed on a type parameter definition that has no type constraints, `notnull`, `class`, `struct` and `unmanaged` constraints and |
There was a problem hiding this comment.
constraints [](start = 86, length = 11)
nit: I had trouble parsing this sentence, so was confused. Consider removing the word "constraints" here ("... that has no type, notnull, class ... constraints"). Also typo on next line (equivalent). #Resolved
| internal override bool? IsNotNullableIfReferenceType | ||
| { | ||
| get | ||
| { |
There was a problem hiding this comment.
{ [](start = 12, length = 1)
Could we do if (HasNotnullConstraint) { return true; }? #Resolved
There was a problem hiding this comment.
Could we do if (HasNotnullConstraint) { return true; }?
We could (as in other implementations of IsNotNullableIfReferenceType), but I decided against duplicating the logic around that and keep it in CalculateIsNotNullableIfReferenceType.
In reply to: 289953856 [](ancestors = 289953856)
Consider consolidating the error messages CS8713 and CS0449 together. "The Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:61204 in e463d06. [](commit_id = e463d06, deletion_comment = False) |
We already have a specialized error for unmanaged. I'll open an issue to suggest to consolidate them all. In reply to: 498373294 [](ancestors = 498373294) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:61204 in e463d06. [](commit_id = e463d06, deletion_comment = False) |
|
|
||
| public bool IsUnmanaged => ((InternalSyntax.TypeSyntax)this.Green).IsUnmanaged; | ||
|
|
||
| public bool IsNotnull => ((InternalSyntax.TypeSyntax)this.Green).IsNotnull; |
There was a problem hiding this comment.
IsNotnull [](start = 20, length = 9)
Should this be "IsNotNull" (uppercase "N")? It looks like other members of the public API use uppercase for compound keywords ("IsReadOnly", "NameOf", "OrderBy", etc.). #Resolved
| /// </summary> | ||
| internal abstract bool? ReferenceTypeConstraintIsNullable { get; } | ||
|
|
||
| public abstract bool HasNotnullConstraint { get; } |
There was a problem hiding this comment.
Notnull [](start = 32, length = 7)
Consider using "NotNull" (uppercase "N") throughout. #Resolved
| } | ||
|
|
||
| // "Constraint cannot be special class '{0}'" | ||
| Error(diagnostics, ErrorCode.WRN_SpecialTypeAsBound, syntax, typeWithAnnotations); |
There was a problem hiding this comment.
WRN_SpecialTypeAsBound [](start = 49, length = 22)
Should an object constraint be reported as an error rather than a warning, as in C#7? #Resolved
There was a problem hiding this comment.
I thought we were going to keep this as for the moment, and disallow it later to allow corefx to migrate.
In reply to: 289997980 [](ancestors = 289997980)
There was a problem hiding this comment.
Should an object constraint be reported as an error rather than a warning, as in C#7?
If I remember correctly, removal of support for object constraint is in the second phase. The reason is to avoid breaking CoreFx right from the first compiler upgrade.
In reply to: 290001495 [](ancestors = 290001495,289997980)
Comments are stale. #Resolved Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:62001 in e463d06. [](commit_id = e463d06, deletion_comment = False) |
Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:65653 in e463d06. [](commit_id = e463d06, deletion_comment = False) |
Consider testing the current constraints with Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:66945 in e463d06. [](commit_id = e463d06, deletion_comment = False) |
Are we testing cases where the Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:68742 in e463d06. [](commit_id = e463d06, deletion_comment = False) |
To the same degree as we tested that for In reply to: 498404345 [](ancestors = 498404345) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:68742 in e463d06. [](commit_id = e463d06, deletion_comment = False) |
I do not think so, they test APIs that those changes use. In reply to: 498413865 [](ancestors = 498413865,498410871,498404345) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:68742 in e463d06. [](commit_id = e463d06, deletion_comment = False) |
In short, what is the error reported for the following? Does it refer to public interface I<T> where T : notnull { }b.cs: class Program
{
static void M<T>()
{
I<T> i;
}
}In reply to: 498414534 [](ancestors = 498414534,498413865,498410871,498404345) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:68742 in e463d06. [](commit_id = e463d06, deletion_comment = False) |
Yes, there is an example several lines above: In reply to: 498417252 [](ancestors = 498417252,498414534,498413865,498410871,498404345) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:68742 in e463d06. [](commit_id = e463d06, deletion_comment = False) |
|
|
||
| namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Recommendations | ||
| { | ||
| public class NotnullKeywordRecommenderTests : RecommenderTests |
There was a problem hiding this comment.
Notnull [](start = 17, length = 7)
Consider using "NotNull". #Resolved
|
|
||
| namespace Microsoft.CodeAnalysis.CSharp.Completion.KeywordRecommenders | ||
| { | ||
| internal class NotnullKeywordRecommender : IKeywordRecommender<CSharpSyntaxContext> |
There was a problem hiding this comment.
Notnull [](start = 19, length = 7)
Consider using "NotNull". #Resolved
Opened #36160 In reply to: 498375369 [](ancestors = 498375369,498373294) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:61204 in e463d06. [](commit_id = e463d06, deletion_comment = False) |
See https://github.com/dotnet/csharplang/blob/master/meetings/2019/LDM-2019-05-15.md
Also fixes #36005.