Include nullability in CheckConstraints#28959
Include nullability in CheckConstraints#28959cston merged 8 commits intodotnet:features/NullableReferenceTypesfrom
Conversation
…s' into check-constraints
|
@dotnet/roslyn-compiler please review. |
|
@cston test failure appears legitimate |
| { | ||
| public class AttributeTests_Nullable : CSharpTestBase | ||
| { | ||
| private const string NonNullTypesAttributesDefinition = @" |
There was a problem hiding this comment.
NonNullTypesAttributesDefinition [](start = 29, length = 32)
We should consider making this available on CSharpTestBase, it's likely that many more tests will need the attribute.
There was a problem hiding this comment.
| Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(x, y)").WithLocation(7, 9)); | ||
| Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(x, y)").WithLocation(7, 9), | ||
| // (8,9): warning CS8631: The type 'C?' cannot be used as type parameter 'U' in the generic type or method 'C.F<T, U>(T, U)'. Nullability of type argument 'C?' doesn't match constraint type 'C'. | ||
| // F(y, x).ToString(); |
There was a problem hiding this comment.
Consider adding some comments to the test to help read the errors. #Resolved
| protected ConversionsBase(AssemblySymbol corLibrary, int currentRecursionDepth, bool includeNullability, ConversionsBase otherNullabilityOpt) | ||
| { | ||
| Debug.Assert((object)corLibrary != null); | ||
| Debug.Assert(otherNullabilityOpt == null || includeNullability == !otherNullabilityOpt.IncludeNullability); |
|
@jcouv, @dotnet/roslyn-compiler, please review. |
…s' into check-constraints
| { | ||
| type.CheckConstraintsForNonTuple(this.Conversions, typeSyntax, typeArgumentsSyntax, this.Compilation, basesBeingResolved, diagnostics); | ||
| bool includeNullability = Compilation.IsFeatureEnabled(MessageID.IDS_FeatureStaticNullChecking); | ||
| type.CheckConstraintsForNonTuple(this.Conversions.WithNullability(includeNullability), typeSyntax, typeArgumentsSyntax, this.Compilation, basesBeingResolved, diagnostics); |
There was a problem hiding this comment.
CheckConstraintsForNonTuple [](start = 21, length = 27)
Why are tuples vs. non-tuples relevant here?
Do we need to test a ValueTuple type with constraints?
There was a problem hiding this comment.
This is not specific to nullable - this call is in master. And it looks like the transform to TupleTypeSymbol occurs below, after constraints are checked.
In reply to: 207374410 [](ancestors = 207374410)
| protected ConversionsBase(AssemblySymbol corLibrary, int currentRecursionDepth, bool includeNullability) | ||
| private ConversionsBase _lazyOtherNullability; | ||
|
|
||
| protected ConversionsBase(AssemblySymbol corLibrary, int currentRecursionDepth, bool includeNullability, ConversionsBase otherNullabilityOpt) |
There was a problem hiding this comment.
ConversionsBase [](start = 18, length = 15)
xml doc would be useful
There was a problem hiding this comment.
| _lazyOtherNullability = otherNullabilityOpt; | ||
| } | ||
|
|
||
| internal ConversionsBase WithNullability(bool includeNullability) |
There was a problem hiding this comment.
WithNullability [](start = 33, length = 15)
doc on this would be useful too, since there is some trickery to minimize allocations.
Maybe also on the _lazyOtherNullability field. #Resolved
| /// <param name="typeArguments">Containing symbol type arguments.</param> | ||
| /// <param name="currentCompilation">Improves error message detail.</param> | ||
| /// <param name="diagnosticsBuilder">Diagnostics.</param> | ||
| /// <param name="warningsBuilderOpt">Nullability warnings.</param> |
There was a problem hiding this comment.
warningsBuilderOpt [](start = 25, length = 18)
Why do we need to keep warnings separate from the rest of diagnostics?
There was a problem hiding this comment.
To allow NullableWalker to drop all but the nullability diagnostics.
In reply to: 207376397 [](ancestors = 207376397)
| comp.VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact(Skip = "PROTOTYPE(NullableReferenceTypes): hits an assertion in AsObliviousReferenceType")] |
There was a problem hiding this comment.
Skip [](start = 14, length = 4)
Thanks! It looks like I'd forgotten to unskip a bunch of NNT tests.
Do we have tests where the nullability warning occurs within the constraints declaration itself? class C<TBase, TDerived> where TDerived : TBase { }
class D<U> where U : C<U, U?> { } // warnRefers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:33961 in 1206b86. [](commit_id = 1206b86, deletion_comment = False) |
| Debug.Assert(conversions.IncludeNullability); | ||
| if (!SatisfiesConstraintType(conversions, typeArgument, constraintType, ref useSiteDiagnostics)) | ||
| { | ||
| warningsBuilderOpt.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint, containingSymbol.ConstructedFrom(), constraintType, typeParameter, typeArgument))); |
There was a problem hiding this comment.
warningsBuilderOpt [](start = 28, length = 18)
nit: Consider breaking long line #Resolved
| // "An identity conversion (6.1.1). | ||
| // An implicit reference conversion (6.1.6). ..." | ||
| if (conversions.HasIdentityOrImplicitReferenceConversion(typeArgument.TypeSymbol, constraintType.TypeSymbol, ref useSiteDiagnostics)) | ||
| if ((!conversions.IncludeNullability || ConversionsBase.HasTopLevelNullabilityImplicitConversion(typeArgument, constraintType)) && |
There was a problem hiding this comment.
if [](start = 12, length = 2)
Could you add a comment? #Resolved
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (iteration 7). Mostly some documentation requests. Thanks
… into unconstrained-type-parameter-nullability * dotnet/features/NullableReferenceTypes: Include nullability in CheckConstraints (dotnet#28959) Use struct for TypeSymbolWithAnnotations (dotnet#28943) Publish Linux Test Results Force retest Migrate Linux tests to VSTS Port determinism fixes Make sure TLS 1.2 is used to fetch from https://dot.net Move to language version 8 Make mutex creation more robust Disable icacls use on Helix Disable leak detection tests on x64 VSTS YAML file
No description provided.