diff --git a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
index ed6e1a9cc2af0..d2a202b8ddbc7 100644
--- a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
+++ b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
@@ -12634,24 +12634,6 @@ internal static string WRN_AnalyzerCannotBeCreated_Title {
}
}
- ///
- /// Looks up a localized string similar to The 'as' operator may produce a null value when '{0}' is a non-nullable reference type..
- ///
- internal static string WRN_AsOperatorMayReturnNull {
- get {
- return ResourceManager.GetString("WRN_AsOperatorMayReturnNull", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to The 'as' operator may produce a null value for a type parameter..
- ///
- internal static string WRN_AsOperatorMayReturnNull_Title {
- get {
- return ResourceManager.GetString("WRN_AsOperatorMayReturnNull_Title", resourceCulture);
- }
- }
-
///
/// Looks up a localized string similar to Attribute '{0}' from module '{1}' will be ignored in favor of the instance appearing in source.
///
@@ -13795,24 +13777,6 @@ internal static string WRN_ComparisonToSelf_Title {
}
}
- ///
- /// Looks up a localized string similar to Conditional access may produce a null value when '{0}' is a non-nullable reference type..
- ///
- internal static string WRN_ConditionalAccessMayReturnNull {
- get {
- return ResourceManager.GetString("WRN_ConditionalAccessMayReturnNull", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Conditional access may produce a null value for a type parameter..
- ///
- internal static string WRN_ConditionalAccessMayReturnNull_Title {
- get {
- return ResourceManager.GetString("WRN_ConditionalAccessMayReturnNull_Title", resourceCulture);
- }
- }
-
///
/// Looks up a localized string similar to Different checksum values given for '{0}'.
///
@@ -13885,24 +13849,6 @@ internal static string WRN_DebugFullNameTooLong_Title {
}
}
- ///
- /// Looks up a localized string similar to A default expression introduces a null value when '{0}' is a non-nullable reference type..
- ///
- internal static string WRN_DefaultExpressionMayIntroduceNullT {
- get {
- return ResourceManager.GetString("WRN_DefaultExpressionMayIntroduceNullT", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to A default expression introduces a null value for a type parameter..
- ///
- internal static string WRN_DefaultExpressionMayIntroduceNullT_Title {
- get {
- return ResourceManager.GetString("WRN_DefaultExpressionMayIntroduceNullT_Title", resourceCulture);
- }
- }
-
///
/// Looks up a localized string similar to The default value specified for parameter '{0}' will have no effect because it applies to a member that is used in contexts that do not allow optional arguments.
///
@@ -15754,24 +15700,6 @@ internal static string WRN_NullAsNonNullable_Title {
}
}
- ///
- /// Looks up a localized string similar to A null literal introduces a null value when '{0}' is a non-nullable reference type..
- ///
- internal static string WRN_NullLiteralMayIntroduceNullT {
- get {
- return ResourceManager.GetString("WRN_NullLiteralMayIntroduceNullT", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to A null literal introduces a null value for a type parameter..
- ///
- internal static string WRN_NullLiteralMayIntroduceNullT_Title {
- get {
- return ResourceManager.GetString("WRN_NullLiteralMayIntroduceNullT_Title", resourceCulture);
- }
- }
-
///
/// Looks up a localized string similar to Possible null reference argument for parameter '{0}' in '{1}'..
///
diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx
index b06d12164a68f..d4e2755b927cb 100644
--- a/src/Compilers/CSharp/Portable/CSharpResources.resx
+++ b/src/Compilers/CSharp/Portable/CSharpResources.resx
@@ -5396,30 +5396,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
Nullability of reference types in value doesn't match target type.
-
- Conditional access may produce a null value when '{0}' is a non-nullable reference type.
-
-
- Conditional access may produce a null value for a type parameter.
-
-
- The 'as' operator may produce a null value when '{0}' is a non-nullable reference type.
-
-
- The 'as' operator may produce a null value for a type parameter.
-
-
- A default expression introduces a null value when '{0}' is a non-nullable reference type.
-
-
- A default expression introduces a null value for a type parameter.
-
-
- A null literal introduces a null value when '{0}' is a non-nullable reference type.
-
-
- A null literal introduces a null value for a type parameter.
-
Call to non-readonly member '{0}' from a 'readonly' member results in an implicit copy of '{1}'.
diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
index e5d2405fbf9ac..d9f2065d786d4 100644
--- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
+++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
@@ -1660,7 +1660,7 @@ internal enum ErrorCode
ERR_ExplicitNullableAttribute = 8623,
WRN_NullabilityMismatchInArgumentForOutput = 8624,
WRN_NullAsNonNullable = 8625,
- WRN_AsOperatorMayReturnNull = 8626,
+ //WRN_AsOperatorMayReturnNull = 8626,
ERR_NullableUnconstrainedTypeParameter = 8627,
ERR_AnnotationDisallowedInObjectCreation = 8628,
WRN_NullableValueTypeMayBeNull = 8629,
@@ -1672,7 +1672,7 @@ internal enum ErrorCode
ERR_TripleDotNotAllowed = 8635,
ERR_BadNullableContextOption = 8636,
ERR_NullableDirectiveQualifierExpected = 8637,
- WRN_ConditionalAccessMayReturnNull = 8638,
+ //WRN_ConditionalAccessMayReturnNull = 8638,
ERR_BadNullableTypeof = 8639,
ERR_ExpressionTreeCantContainRefStruct = 8640,
ERR_ElseCannotStartStatement = 8641,
@@ -1687,8 +1687,8 @@ internal enum ErrorCode
ERR_IsNullableType = 8650,
ERR_AsNullableType = 8651,
ERR_FeatureInPreview = 8652,
- WRN_DefaultExpressionMayIntroduceNullT = 8653,
- WRN_NullLiteralMayIntroduceNullT = 8654,
+ //WRN_DefaultExpressionMayIntroduceNullT = 8653,
+ //WRN_NullLiteralMayIntroduceNullT = 8654,
WRN_SwitchExpressionNotExhaustiveForNull = 8655,
WRN_ImplicitCopyInReadOnlyMember = 8656,
diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
index f4cf1dcdb2c62..26097f362ff44 100644
--- a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
+++ b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
@@ -39,10 +39,6 @@ static ErrorFacts()
builder.Add(getId(ErrorCode.WRN_NullabilityMismatchInTypeParameterNotNullConstraint));
builder.Add(getId(ErrorCode.WRN_ThrowPossibleNull));
builder.Add(getId(ErrorCode.WRN_UnboxPossibleNull));
- builder.Add(getId(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT));
- builder.Add(getId(ErrorCode.WRN_NullLiteralMayIntroduceNullT));
- builder.Add(getId(ErrorCode.WRN_ConditionalAccessMayReturnNull));
- builder.Add(getId(ErrorCode.WRN_AsOperatorMayReturnNull));
builder.Add(getId(ErrorCode.WRN_SwitchExpressionNotExhaustiveForNull));
builder.Add(getId(ErrorCode.WRN_ConvertingNullableToNonNullable));
@@ -421,10 +417,6 @@ internal static int GetWarningLevel(ErrorCode code)
case ErrorCode.WRN_CaseConstantNamedUnderscore:
case ErrorCode.WRN_ThrowPossibleNull:
case ErrorCode.WRN_UnboxPossibleNull:
- case ErrorCode.WRN_DefaultExpressionMayIntroduceNullT:
- case ErrorCode.WRN_NullLiteralMayIntroduceNullT:
- case ErrorCode.WRN_ConditionalAccessMayReturnNull:
- case ErrorCode.WRN_AsOperatorMayReturnNull:
case ErrorCode.WRN_SwitchExpressionNotExhaustiveForNull:
case ErrorCode.WRN_ImplicitCopyInReadOnlyMember:
case ErrorCode.WRN_UnconsumedEnumeratorCancellationAttributeUsage:
diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
index 53f2d13f0f274..f478332e9a592 100644
--- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
+++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs
@@ -767,7 +767,6 @@ private NullableFlowState GetDefaultState(ref LocalState state, int slot)
{
localType = local.TypeWithAnnotations;
}
-
return localType.ToTypeWithState().State;
}
case SymbolKind.Parameter:
@@ -777,8 +776,7 @@ private NullableFlowState GetDefaultState(ref LocalState state, int slot)
{
parameterType = parameter.TypeWithAnnotations;
}
-
- return parameterType.ToTypeWithState().State;
+ return GetParameterState(parameterType, parameter.FlowAnalysisAnnotations).State;
}
case SymbolKind.Field:
case SymbolKind.Property:
@@ -1032,57 +1030,82 @@ private enum AssignmentKind
///
/// Reports top-level nullability problem in assignment.
+ /// Any conversion of the value should have been applied.
///
- private bool ReportNullableAssignmentIfNecessary(
+ private void ReportNullableAssignmentIfNecessary(
BoundExpression value,
TypeWithAnnotations targetType,
TypeWithState valueType,
bool useLegacyWarnings,
AssignmentKind assignmentKind = AssignmentKind.Assignment,
ParameterSymbol parameterOpt = null,
- Conversion conversion = default,
Location location = null)
{
+ // Callers should apply any conversions before calling this method
+ // (see https://github.com/dotnet/roslyn/issues/39867).
+ if (targetType.HasType &&
+ !targetType.Type.Equals(valueType.Type, TypeCompareKind.AllIgnoreOptions))
+ {
+ return;
+ }
+
if (value == null ||
value.WasCompilerGenerated ||
!targetType.HasType ||
- targetType.Type.IsValueType ||
- targetType.CanBeAssignedNull ||
- valueType.IsNotNull)
+ targetType.Type.IsValueType)
{
- return false;
+ return;
+ }
+
+ switch (targetType.NullableAnnotation)
+ {
+ case NullableAnnotation.Oblivious:
+ case NullableAnnotation.Annotated:
+ return;
+ }
+
+ switch (valueType.State)
+ {
+ case NullableFlowState.NotNull:
+ return;
+ case NullableFlowState.MaybeNull:
+ if (targetType.Type.IsTypeParameterDisallowingAnnotation())
+ {
+ return;
+ }
+ break;
}
location ??= value.Syntax.GetLocation();
var unwrappedValue = SkipReferenceConversions(value);
if (unwrappedValue.IsSuppressed)
{
- return false;
+ return;
}
- if (RequiresSafetyWarningWhenNullIntroduced(targetType))
+ if (useLegacyWarnings &&
+ valueType.Type?.TypeKind == TypeKind.TypeParameter &&
+ valueType.State == NullableFlowState.MaybeDefault)
{
- HashSet useSiteDiagnostics = null;
- if (conversion.Kind == ConversionKind.UnsetConversionKind)
- conversion = this._conversions.ClassifyImplicitConversionFromType(valueType.Type, targetType.Type, ref useSiteDiagnostics);
-
- if (conversion.IsImplicit && !conversion.IsDynamic)
- {
- // For type parameters that cannot be annotated, the analysis must report those
- // places where null values first sneak in, like `default`, `null`, and `GetFirstOrDefault`,
- // as a safety diagnostic. This is NOT one of those places.
- return false;
- }
-
- useLegacyWarnings = false;
+ // No W warning reported assigning or casting [MaybeNull]T value to T
+ // because there is no syntax for declaring the target type as [MaybeNull]T.
+ return;
}
- if (reportNullLiteralAssignmentIfNecessary(value, location, valueType.ToTypeWithAnnotations()))
+ if (value.ConstantValue?.IsNull == true)
{
- return true;
+ // Report warning converting null literal to non-nullable reference type.
+ // target (e.g.: `object x = null;` or calling `void F(object y)` with `F(null)`).
+ if (useLegacyWarnings)
+ {
+ ReportNonSafetyDiagnostic(location);
+ }
+ else
+ {
+ ReportDiagnostic(assignmentKind == AssignmentKind.Return ? ErrorCode.WRN_NullReferenceReturn : ErrorCode.WRN_NullAsNonNullable, location);
+ }
}
-
- if (assignmentKind == AssignmentKind.Argument)
+ else if (assignmentKind == AssignmentKind.Argument)
{
ReportDiagnostic(ErrorCode.WRN_NullReferenceArgument, location,
GetParameterAsDiagnosticArgument(parameterOpt),
@@ -1096,31 +1119,6 @@ private bool ReportNullableAssignmentIfNecessary(
{
ReportDiagnostic(assignmentKind switch { AssignmentKind.Return => ErrorCode.WRN_NullReferenceReturn, AssignmentKind.ForEachIterationVariable => ErrorCode.WRN_NullReferenceIterationVariable, _ => ErrorCode.WRN_NullReferenceAssignment }, location);
}
-
- return true;
-
- // Report warning converting null literal to non-nullable reference type.
- // target (e.g.: `object x = null;` or calling `void F(object y)` with `F(null)`).
- bool reportNullLiteralAssignmentIfNecessary(BoundExpression expr, Location location, TypeWithAnnotations exprType)
- {
- if (expr.ConstantValue?.IsNull != true)
- {
- return false;
- }
-
- // For type parameters that cannot be annotated, the analysis must report those
- // places where null values first sneak in, like `default`, `null`, and `GetFirstOrDefault`,
- // as a safety diagnostic. This is one of those places.
- if (useLegacyWarnings && !RequiresSafetyWarningWhenNullIntroduced(exprType))
- {
- ReportNonSafetyDiagnostic(location);
- }
- else
- {
- ReportDiagnostic(assignmentKind == AssignmentKind.Return ? ErrorCode.WRN_NullReferenceReturn : ErrorCode.WRN_NullAsNonNullable, location);
- }
- return true;
- }
}
private static bool IsDefaultValue(BoundExpression expr)
@@ -1303,17 +1301,17 @@ private void InheritNullableStateOfMember(int targetContainerSlot, int valueCont
///
/// Whenever assigning a variable, and that variable is not declared at the point the state is being set,
- /// and the new state might be , this method should be called to perform the
+ /// and the new state is not , this method should be called to perform the
/// state setting and to ensure the mutation is visible outside the finally block when the mutation occurs in a
/// finally block.
///
private void SetStateAndTrackForFinally(ref LocalState state, int slot, NullableFlowState newState)
{
state[slot] = newState;
- if (newState == NullableFlowState.MaybeNull && NonMonotonicState.HasValue)
+ if (newState != NullableFlowState.NotNull && NonMonotonicState.HasValue)
{
var tryState = NonMonotonicState.Value;
- tryState[slot] = NullableFlowState.MaybeNull;
+ tryState[slot] = newState.Join(tryState[slot]);
NonMonotonicState = tryState;
}
}
@@ -1404,7 +1402,8 @@ private void EnterParameter(ParameterSymbol parameter, TypeWithAnnotations param
Debug.Assert(!IsConditionalState);
if (slot > 0)
{
- this.State[slot] = parameterType.ToTypeWithState().State;
+ var state = GetParameterState(parameterType, parameter.FlowAnalysisAnnotations).State;
+ this.State[slot] = state;
if (EmptyStructTypeCache.IsTrackableStructType(parameterType.Type))
{
InheritNullableStateOfTrackableStruct(
@@ -1416,6 +1415,13 @@ private void EnterParameter(ParameterSymbol parameter, TypeWithAnnotations param
}
}
+ private static TypeWithState GetParameterState(TypeWithAnnotations parameterType, FlowAnalysisAnnotations parameterAnnotations)
+ {
+ return ((parameterAnnotations & FlowAnalysisAnnotations.AllowNull) != 0) ?
+ TypeWithState.Create(parameterType.Type, NullableFlowState.MaybeDefault) :
+ parameterType.ToTypeWithState();
+ }
+
protected override BoundNode VisitReturnStatementNoAdjust(BoundReturnStatement node)
{
Debug.Assert(!IsConditionalState);
@@ -1483,7 +1489,8 @@ private bool TryGetReturnType(out TypeWithAnnotations type)
return false;
}
- var returnType = (_delegateInvokeMethod ?? method).ReturnTypeWithAnnotations;
+ var delegateOrMethod = _delegateInvokeMethod ?? method;
+ var returnType = delegateOrMethod.ReturnTypeWithAnnotations;
Debug.Assert((object)returnType != LambdaSymbol.ReturnTypeIsBeingInferred);
if (returnType.IsVoidType())
@@ -1494,7 +1501,7 @@ private bool TryGetReturnType(out TypeWithAnnotations type)
if (!method.IsAsync)
{
- type = returnType;
+ type = ApplyUnconditionalAnnotations(returnType, delegateOrMethod.ReturnTypeFlowAnalysisAnnotations);
return true;
}
@@ -1508,21 +1515,6 @@ private bool TryGetReturnType(out TypeWithAnnotations type)
return false;
}
- private static bool RequiresSafetyWarningWhenNullIntroduced(TypeWithAnnotations typeWithAnnotations)
- {
- return
- typeWithAnnotations is { Type: TypeSymbol type, NullableAnnotation: NullableAnnotation.NotAnnotated } &&
- type.IsTypeParameterDisallowingAnnotation() &&
- !type.IsNullableTypeOrTypeParameter();
- }
-
- private static bool RequiresSafetyWarningWhenNullIntroduced(TypeSymbol type)
- {
- return
- type.IsTypeParameterDisallowingAnnotation() &&
- !type.IsNullableTypeOrTypeParameter();
- }
-
public override BoundNode VisitLocal(BoundLocal node)
{
var local = node.LocalSymbol;
@@ -1538,7 +1530,7 @@ public override BoundNode VisitLocal(BoundLocal node)
type = TypeWithAnnotations.Create(node.Type, type.NullableAnnotation);
}
- SetResult(node, GetAdjustedResult(type, slot), type);
+ SetResult(node, GetAdjustedResult(type.ToTypeWithState(), slot), type);
return null;
}
@@ -2891,16 +2883,9 @@ public override BoundNode VisitConditionalAccess(BoundConditionalAccess node)
oldType.IsNullableType() && !accessType.IsNullableType() ? MakeNullableOf(accessTypeWithAnnotations) :
accessType;
- // If the result type does not allow annotations, then we produce a warning because
- // the result may be null.
- if (RequiresSafetyWarningWhenNullIntroduced(resultType))
- {
- ReportDiagnostic(ErrorCode.WRN_ConditionalAccessMayReturnNull, node.Syntax, accessType);
- }
-
// Per LDM 2019-02-13 decision, the result of a conditional access "may be null" even if
// both the receiver and right-hand-side are believed not to be null.
- SetResultType(node, TypeWithState.Create(resultType, NullableFlowState.MaybeNull));
+ SetResultType(node, TypeWithState.Create(resultType, NullableFlowState.MaybeDefault));
_currentConditionalReceiverVisitResult = default;
_lastConditionalAccessSlot = previousConditionalAccessSlot;
return null;
@@ -3104,7 +3089,7 @@ TypeWithState convertResult(
}
}
- bool IsReachable()
+ private bool IsReachable()
=> this.IsConditionalState ? (this.StateWhenTrue.Reachable || this.StateWhenFalse.Reachable) : this.State.Reachable;
///
@@ -3400,7 +3385,7 @@ private FlowAnalysisAnnotations GetParameterAnnotations(ParameterSymbol paramete
}
///
- /// Fix a TypeWithAnnotations based on Maybe/NotNull annotations prior to a conversion or assignment.
+ /// Fix a TypeWithAnnotations based on Allow/DisallowNull annotations prior to a conversion or assignment.
/// Note this does not work for nullable value types, so an additional check with may be required.
///
private static TypeWithAnnotations ApplyLValueAnnotations(TypeWithAnnotations declaredType, FlowAnalysisAnnotations flowAnalysisAnnotations)
@@ -3424,7 +3409,7 @@ private static TypeWithState ApplyUnconditionalAnnotations(TypeWithState typeWit
{
if ((annotations & FlowAnalysisAnnotations.MaybeNull) == FlowAnalysisAnnotations.MaybeNull)
{
- return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeNull);
+ return TypeWithState.Create(typeWithState.Type, NullableFlowState.MaybeDefault);
}
if ((annotations & FlowAnalysisAnnotations.NotNull) == FlowAnalysisAnnotations.NotNull)
@@ -3435,6 +3420,16 @@ private static TypeWithState ApplyUnconditionalAnnotations(TypeWithState typeWit
return typeWithState;
}
+ private static TypeWithAnnotations ApplyUnconditionalAnnotations(TypeWithAnnotations declaredType, FlowAnalysisAnnotations annotations)
+ {
+ if ((annotations & FlowAnalysisAnnotations.MaybeNull) == FlowAnalysisAnnotations.MaybeNull)
+ {
+ return declaredType.AsAnnotated();
+ }
+
+ return declaredType;
+ }
+
// https://github.com/dotnet/roslyn/issues/29863 Record in the node whether type
// arguments were implicit, to allow for cases where the syntax is not an
// invocation (such as a synthesized call from a query interpretation).
@@ -4478,11 +4473,6 @@ private static bool UseExpressionForConversion(BoundExpression value)
///
/// Adjust declared type based on inferred nullability at the point of reference.
///
- private TypeWithState GetAdjustedResult(TypeWithAnnotations type, int slot)
- {
- return GetAdjustedResult(type.ToTypeWithState(), slot);
- }
-
private TypeWithState GetAdjustedResult(TypeWithState type, int slot)
{
if (slot > 0 && slot < this.State.Capacity)
@@ -4645,7 +4635,7 @@ public override BoundNode VisitConversion(BoundConversion node)
operandType,
checkConversion: true,
fromExplicitCast: fromExplicitCast,
- useLegacyWarnings: fromExplicitCast && !RequiresSafetyWarningWhenNullIntroduced(explicitType),
+ useLegacyWarnings: fromExplicitCast,
AssignmentKind.Assignment,
reportTopLevelWarnings: fromExplicitCast,
reportRemainingWarnings: true,
@@ -5154,14 +5144,17 @@ private TypeWithState VisitConversion(
case ConversionKind.ExplicitDynamic:
case ConversionKind.ImplicitDynamic:
+ resultState = getConversionResultState(operandType);
+ break;
+
case ConversionKind.Boxing:
- resultState = operandType.State;
+ resultState = getBoxingConversionResultState(operandType);
break;
case ConversionKind.Unboxing:
if (targetType.IsNonNullableValueType())
{
- if (operandType.MayBeNull && reportRemainingWarnings)
+ if (!operandType.IsNotNull && reportRemainingWarnings)
{
ReportDiagnostic(ErrorCode.WRN_UnboxPossibleNull, diagnosticLocationOpt);
}
@@ -5170,7 +5163,7 @@ private TypeWithState VisitConversion(
}
else
{
- resultState = operandType.State;
+ resultState = getUnboxingConversionResultState(operandType);
}
break;
@@ -5179,19 +5172,11 @@ private TypeWithState VisitConversion(
break;
case ConversionKind.NoConversion:
- resultState = operandType.State;
+ resultState = getConversionResultState(operandType);
break;
case ConversionKind.NullLiteral:
case ConversionKind.DefaultLiteral:
- if (checkConversion && RequiresSafetyWarningWhenNullIntroduced(targetTypeWithNullability) && !isSuppressed)
- {
- // For type parameters that cannot be annotated, the analysis must report those
- // places where null values first sneak in, like `default`, `null`, and `GetFirstOrDefault`.
- // This is one of those places.
- ReportDiagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, diagnosticLocationOpt, GetTypeAsDiagnosticArgument(targetTypeWithNullability.Type));
- }
-
checkConversion = false;
goto case ConversionKind.Identity;
@@ -5222,20 +5207,6 @@ private TypeWithState VisitConversion(
goto case ConversionKind.ImplicitReference;
case ConversionKind.ImplicitReference:
- if (reportTopLevelWarnings &&
- conversionOperand?.Kind == BoundKind.Literal &&
- conversionOperand.ConstantValue?.IsNull == true &&
- !conversionOperand.WasCompilerGenerated &&
- !isSuppressed &&
- RequiresSafetyWarningWhenNullIntroduced(targetTypeWithNullability))
- {
- // For type parameters that cannot be annotated, the analysis must report those
- // places where null values first sneak in, like `default`, `null`, and `GetFirstOrDefault`.
- // This is one of those places.
- ReportDiagnostic(ErrorCode.WRN_NullLiteralMayIntroduceNullT, diagnosticLocationOpt, targetType);
- }
- goto case ConversionKind.ExplicitReference;
-
case ConversionKind.ExplicitReference:
// Inherit state from the operand.
if (checkConversion)
@@ -5244,7 +5215,7 @@ private TypeWithState VisitConversion(
canConvertNestedNullability = conversion.Exists;
}
- resultState = operandType.State;
+ resultState = conversion.IsReference ? getReferenceConversionResultState(targetTypeWithNullability, operandType) : operandType.State;
break;
case ConversionKind.ImplicitNullable:
@@ -5345,16 +5316,7 @@ private TypeWithState VisitConversion(
// Need to report all warnings that apply since the warnings can be suppressed individually.
if (reportTopLevelWarnings)
{
- if (RequiresSafetyWarningWhenNullIntroduced(targetTypeWithNullability) && conversion.IsImplicit && !conversion.IsDynamic)
- {
- // For type parameters that cannot be annotated, the analysis must report those
- // places where null values first sneak in, like `default`, `null`, and `GetFirstOrDefault`,
- // as a safety diagnostic. But we do not warn when such values flow through implicit conversion.
- }
- else
- {
- ReportNullableAssignmentIfNecessary(conversionOperand, targetTypeWithNullability, operandType, useLegacyWarnings, assignmentKind, parameterOpt, conversion, diagnosticLocationOpt);
- }
+ ReportNullableAssignmentIfNecessary(conversionOperand, targetTypeWithNullability, resultType, useLegacyWarnings, assignmentKind, parameterOpt, diagnosticLocationOpt);
}
if (reportRemainingWarnings && !canConvertNestedNullability)
{
@@ -5388,6 +5350,63 @@ static TypeWithState calculateResultType(TypeWithAnnotations targetTypeWithNulla
var resultType = TypeWithState.Create(targetType, resultState);
return resultType;
}
+
+ static NullableFlowState getReferenceConversionResultState(TypeWithAnnotations targetType, TypeWithState operandType)
+ {
+ var state = operandType.State;
+ switch (state)
+ {
+ case NullableFlowState.MaybeNull:
+ if (operandType.Type?.IsTypeParameterDisallowingAnnotation() != true &&
+ targetType.Type?.IsTypeParameterDisallowingAnnotation() == true)
+ {
+ return NullableFlowState.MaybeDefault;
+ }
+ break;
+ case NullableFlowState.MaybeDefault:
+ if (targetType.Type?.IsTypeParameterDisallowingAnnotation() == false)
+ {
+ return NullableFlowState.MaybeNull;
+ }
+ break;
+ }
+ return state;
+ }
+
+ // Converting to a less-derived type (object, interface, type parameter).
+ // If the operand is MaybeNull or MaybeDefault, the result should be
+ // MaybeNull (if the target type allows) or MaybeDefault otherwise.
+ static NullableFlowState getBoxingConversionResultState(TypeWithState operandType)
+ {
+ return getConversionResultState(operandType);
+ }
+
+ // Converting to a more-derived type (struct, class, type parameter).
+ // If the operand is MaybeNull or MaybeDefault, the result should be
+ // MaybeDefault.
+ static NullableFlowState getUnboxingConversionResultState(TypeWithState operandType)
+ {
+ var state = operandType.State;
+ if (state == NullableFlowState.MaybeNull)
+ {
+ return NullableFlowState.MaybeDefault;
+ }
+ return state;
+ }
+
+ static NullableFlowState getConversionResultState(TypeWithState operandType)
+ {
+ var state = operandType.State;
+ if (state == NullableFlowState.MaybeNull)
+ {
+ var type = operandType.Type;
+ if (type is null || !type.IsTypeParameterDisallowingAnnotation())
+ {
+ return NullableFlowState.MaybeDefault;
+ }
+ }
+ return state;
+ }
}
private TypeWithState VisitUserDefinedConversion(
@@ -5469,14 +5488,7 @@ private TypeWithState VisitUserDefinedConversion(
// method parameter type -> method return type
var methodReturnType = methodOpt.ReturnTypeWithAnnotations;
operandType = GetLiftedReturnTypeIfNecessary(isLiftedConversion, methodReturnType, operandState);
- if (isLiftedConversion)
- {
- if (RequiresSafetyWarningWhenNullIntroduced(methodReturnType) && operandState == NullableFlowState.MaybeNull)
- {
- ReportNullableAssignmentIfNecessary(conversionOpt, targetTypeWithNullability, operandType, useLegacyWarnings: useLegacyWarnings, assignmentKind, parameterOpt, conversion, diagnosticLocation);
- }
- }
- else
+ if (!isLiftedConversion)
{
// Analyze operator call return value (honoring [Maybe|NotNull] attribute annotations) https://github.com/dotnet/roslyn/issues/32671
}
@@ -5884,8 +5896,9 @@ public override BoundNode VisitParameter(BoundParameter node)
{
var parameter = node.ParameterSymbol;
int slot = GetOrCreateSlot(parameter);
- var type = GetDeclaredParameterResult(parameter);
- SetResult(node, GetAdjustedResult(type, slot), type);
+ var parameterType = GetDeclaredParameterResult(parameter);
+ var typeWithState = GetParameterState(parameterType, parameter.FlowAnalysisAnnotations);
+ SetResult(node, GetAdjustedResult(typeWithState, slot), parameterType);
return null;
}
@@ -6011,10 +6024,10 @@ private static bool UseLegacyWarnings(BoundExpression expr, TypeWithAnnotations
switch (expr.Kind)
{
case BoundKind.Local:
- return expr.GetRefKind() == RefKind.None && !RequiresSafetyWarningWhenNullIntroduced(exprType);
+ return expr.GetRefKind() == RefKind.None;
case BoundKind.Parameter:
RefKind kind = ((BoundParameter)expr).ParameterSymbol.RefKind;
- return kind == RefKind.None && !RequiresSafetyWarningWhenNullIntroduced(exprType);
+ return kind == RefKind.None;
default:
return false;
}
@@ -6663,7 +6676,8 @@ private Symbol VisitMemberAccess(BoundExpression node, BoundExpression receiverO
}
var type = member.GetTypeOrReturnType();
- var resultType = type.ToTypeWithState();
+ var memberAnnotations = GetRValueAnnotations(member);
+ var resultType = ApplyUnconditionalAnnotations(type.ToTypeWithState(), memberAnnotations);
// We are supposed to track information for the node. Use whatever we managed to
// accumulate so far.
@@ -6690,7 +6704,7 @@ private Symbol VisitMemberAccess(BoundExpression node, BoundExpression receiverO
if (_expressionIsRead)
{
- ReportMaybeNullFromTypeParameterValueIfNeeded(node, resultType, GetRValueAnnotations(member));
+ ReportMaybeNullFromTypeParameterValueIfNeeded(node, resultType, memberAnnotations);
}
SetResult(node, resultType, type);
@@ -6835,7 +6849,7 @@ protected override void VisitForEachExpression(BoundForEachStatement node)
var getEnumeratorMethod = (MethodSymbol)AsMemberOfType(convertedResult.Type, node.EnumeratorInfoOpt.GetEnumeratorMethod);
var enumeratorReturnType = getEnumeratorMethod.ReturnTypeWithAnnotations.ToTypeWithState();
- if (enumeratorReturnType.State == NullableFlowState.MaybeNull)
+ if (enumeratorReturnType.State != NullableFlowState.NotNull)
{
ReportDiagnostic(ErrorCode.WRN_NullReferenceReceiver, expr.Syntax.GetLocation());
}
@@ -7277,16 +7291,6 @@ public override BoundNode VisitDefaultExpression(BoundDefaultExpression node)
// https://github.com/dotnet/roslyn/issues/33344: this fails to produce an updated tuple type for a default expression
// (should produce nullable element types for those elements that are of reference types)
SetResultType(node, TypeWithState.ForType(type));
- if (node.TargetType is object && RequiresSafetyWarningWhenNullIntroduced(node.Type) &&
- !node.IsSuppressed)
- {
- // For type parameters that cannot be annotated, the analysis must report those
- // places where null values first sneak in, like `default`, `null`, and `GetFirstOrDefault`.
- // This is one of those places.
- // `default(...)` is handled here to get a better behavior with an oblivious target type, while `default` is handled in VisitConversions.
- ReportDiagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, node.Syntax, GetTypeAsDiagnosticArgument(ResultType.Type));
- }
-
return result;
}
@@ -7330,11 +7334,7 @@ public override BoundNode VisitAsOperator(BoundAsOperator node)
break;
default:
- resultState = NullableFlowState.MaybeNull;
- if (RequiresSafetyWarningWhenNullIntroduced(node.TargetType.TypeWithAnnotations))
- {
- ReportDiagnostic(ErrorCode.WRN_AsOperatorMayReturnNull, node.Syntax, type);
- }
+ resultState = NullableFlowState.MaybeDefault;
break;
}
}
@@ -7373,7 +7373,7 @@ public override BoundNode VisitLiteral(BoundLiteral node)
var result = base.VisitLiteral(node);
Debug.Assert(!IsConditionalState);
- SetResultType(node, TypeWithState.Create(node.Type, node.Type?.CanContainNull() != false && node.ConstantValue?.IsNull == true ? NullableFlowState.MaybeNull : NullableFlowState.NotNull));
+ SetResultType(node, TypeWithState.Create(node.Type, node.Type?.CanContainNull() != false && node.ConstantValue?.IsNull == true ? NullableFlowState.MaybeDefault : NullableFlowState.NotNull));
if (node.ConstantValue?.IsBoolean == true)
{
@@ -7908,7 +7908,8 @@ internal class LocalState : ILocalState
internal struct LocalState : ILocalState
#endif
{
- // The representation of a state is a bit vector. We map false<->NotNull and true<->MayBeNull.
+ // The representation of a state is a bit vector with two bits per slot:
+ // (false, false) => NotNull, (false, true) => MaybeNull, (true, true) => MaybeDefault.
// Slot 0 is used to represent whether the state is reachable (true) or not.
private BitVector _state;
@@ -7921,7 +7922,7 @@ public static LocalState ReachableState(int capacity)
if (capacity < 1)
capacity = 1;
- BitVector state = BitVector.Create(capacity);
+ BitVector state = BitVector.Create(capacity * 2);
state[0] = true;
return new LocalState(state);
}
@@ -7930,22 +7931,41 @@ public static LocalState UnreachableState
{
get
{
- BitVector state = BitVector.Create(1);
+ BitVector state = BitVector.Create(2);
state[0] = false;
return new LocalState(state);
}
}
- public int Capacity => _state.Capacity;
+ public int Capacity => _state.Capacity / 2;
- public void EnsureCapacity(int capacity) => _state.EnsureCapacity(capacity);
+ public void EnsureCapacity(int capacity) => _state.EnsureCapacity(capacity * 2);
public NullableFlowState this[int slot]
{
- get => (slot < Capacity && this.Reachable && _state[slot]) ? NullableFlowState.MaybeNull : NullableFlowState.NotNull;
-
- // No states should be modified in unreachable code, as there is only one unreachable state.
- set => _ = !this.Reachable || (_state[slot] = (value == NullableFlowState.MaybeNull));
+ get
+ {
+ if (slot < Capacity && this.Reachable)
+ {
+ slot *= 2;
+ return (_state[slot + 1], _state[slot]) switch
+ {
+ (false, false) => NullableFlowState.NotNull,
+ (false, true) => NullableFlowState.MaybeNull,
+ (true, false) => throw ExceptionUtilities.UnexpectedValue(slot),
+ (true, true) => NullableFlowState.MaybeDefault
+ };
+ }
+ return NullableFlowState.NotNull;
+ }
+ set
+ {
+ // No states should be modified in unreachable code, as there is only one unreachable state.
+ if (!this.Reachable) return;
+ slot *= 2;
+ _state[slot] = (value != NullableFlowState.NotNull);
+ _state[slot + 1] = (value == NullableFlowState.MaybeDefault);
+ }
}
///
@@ -7963,8 +7983,9 @@ internal string GetDebuggerDisplay()
var pooledBuilder = PooledStringBuilder.GetInstance();
var builder = pooledBuilder.Builder;
builder.Append(" ");
- for (int i = this.Capacity - 1; i >= 0; i--)
- builder.Append(_state[i] ? '?' : '!');
+ int n = Math.Min(Capacity, 8);
+ for (int i = n - 1; i >= 0; i--)
+ builder.Append(_state[i * 2] ? '?' : '!');
return pooledBuilder.ToStringAndFree();
}
diff --git a/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs b/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs
index 7eaa7dc4cde7e..cf0d3c93611a8 100644
--- a/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs
+++ b/src/Compilers/CSharp/Portable/Generated/ErrorFacts.Generated.cs
@@ -213,18 +213,14 @@ public static bool IsWarning(ErrorCode code)
case ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate:
case ErrorCode.WRN_NullabilityMismatchInArgumentForOutput:
case ErrorCode.WRN_NullAsNonNullable:
- case ErrorCode.WRN_AsOperatorMayReturnNull:
case ErrorCode.WRN_NullableValueTypeMayBeNull:
case ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint:
case ErrorCode.WRN_MissingNonNullTypesContextForAnnotation:
case ErrorCode.WRN_NullabilityMismatchInConstraintsOnImplicitImplementation:
case ErrorCode.WRN_NullabilityMismatchInTypeParameterReferenceTypeConstraint:
- case ErrorCode.WRN_ConditionalAccessMayReturnNull:
case ErrorCode.WRN_NullabilityMismatchInExplicitlyImplementedInterface:
case ErrorCode.WRN_NullabilityMismatchInInterfaceImplementedByBase:
case ErrorCode.WRN_DuplicateInterfaceWithNullabilityMismatchInBaseList:
- case ErrorCode.WRN_DefaultExpressionMayIntroduceNullT:
- case ErrorCode.WRN_NullLiteralMayIntroduceNullT:
case ErrorCode.WRN_SwitchExpressionNotExhaustiveForNull:
case ErrorCode.WRN_ImplicitCopyInReadOnlyMember:
case ErrorCode.WRN_NullabilityMismatchInConstraintsOnPartialImplementation:
diff --git a/src/Compilers/CSharp/Portable/Symbols/NullableFlowState.cs b/src/Compilers/CSharp/Portable/Symbols/NullableFlowState.cs
index 3264942efa07d..30e87ee974448 100644
--- a/src/Compilers/CSharp/Portable/Symbols/NullableFlowState.cs
+++ b/src/Compilers/CSharp/Portable/Symbols/NullableFlowState.cs
@@ -9,7 +9,19 @@ namespace Microsoft.CodeAnalysis.CSharp
///
internal enum NullableFlowState : byte
{
- NotNull,
- MaybeNull
+ ///
+ /// Not null.
+ ///
+ NotNull = 0b00,
+
+ ///
+ /// Maybe null (type is nullable).
+ ///
+ MaybeNull = 0b01,
+
+ ///
+ /// Maybe null (type may be not nullable).
+ ///
+ MaybeDefault = 0b11,
}
}
diff --git a/src/Compilers/CSharp/Portable/Symbols/NullableFlowStateExtensions.cs b/src/Compilers/CSharp/Portable/Symbols/NullableFlowStateExtensions.cs
index 00978e7f52f97..8e09b3ab4834a 100644
--- a/src/Compilers/CSharp/Portable/Symbols/NullableFlowStateExtensions.cs
+++ b/src/Compilers/CSharp/Portable/Symbols/NullableFlowStateExtensions.cs
@@ -6,7 +6,7 @@ namespace Microsoft.CodeAnalysis.CSharp
{
internal static class NullableFlowStateExtensions
{
- public static bool MayBeNull(this NullableFlowState state) => state == NullableFlowState.MaybeNull;
+ public static bool MayBeNull(this NullableFlowState state) => state != NullableFlowState.NotNull;
public static bool IsNotNull(this NullableFlowState state) => state == NullableFlowState.NotNull;
@@ -28,6 +28,7 @@ internal static CodeAnalysis.NullableFlowState ToPublicFlowState(this CSharp.Nul
{
CSharp.NullableFlowState.NotNull => CodeAnalysis.NullableFlowState.NotNull,
CSharp.NullableFlowState.MaybeNull => CodeAnalysis.NullableFlowState.MaybeNull,
+ CSharp.NullableFlowState.MaybeDefault => CodeAnalysis.NullableFlowState.MaybeNull,
_ => throw ExceptionUtilities.UnexpectedValue(nullableFlowState)
};
diff --git a/src/Compilers/CSharp/Portable/Symbols/TypeWithState.cs b/src/Compilers/CSharp/Portable/Symbols/TypeWithState.cs
index b3c3916835a31..8cc3b5d9b8f45 100644
--- a/src/Compilers/CSharp/Portable/Symbols/TypeWithState.cs
+++ b/src/Compilers/CSharp/Portable/Symbols/TypeWithState.cs
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
-using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
@@ -19,13 +18,18 @@ internal readonly struct TypeWithState
public static TypeWithState ForType(TypeSymbol type)
{
- var state = type?.CanContainNull() != false ? NullableFlowState.MaybeNull : NullableFlowState.NotNull;
- return new TypeWithState(type, state);
+ return Create(type, NullableFlowState.MaybeDefault);
}
public static TypeWithState Create(TypeSymbol type, NullableFlowState defaultState)
{
- var state = defaultState == NullableFlowState.MaybeNull && type?.CanContainNull() != false ? NullableFlowState.MaybeNull : NullableFlowState.NotNull;
+ if (defaultState == NullableFlowState.MaybeDefault &&
+ (type is null || type.IsTypeParameterDisallowingAnnotation()))
+ {
+ Debug.Assert(type?.IsNullableTypeOrTypeParameter() != true);
+ return new TypeWithState(type, defaultState);
+ }
+ var state = defaultState != NullableFlowState.NotNull && type?.CanContainNull() != false ? NullableFlowState.MaybeNull : NullableFlowState.NotNull;
return new TypeWithState(type, state);
}
@@ -39,7 +43,7 @@ public static TypeWithState Create(TypeWithAnnotations typeWithAnnotations, Flow
{
if ((annotations & FlowAnalysisAnnotations.MaybeNull) == FlowAnalysisAnnotations.MaybeNull)
{
- state = NullableFlowState.MaybeNull;
+ state = NullableFlowState.MaybeDefault;
}
else if ((annotations & FlowAnalysisAnnotations.NotNull) == FlowAnalysisAnnotations.NotNull)
{
@@ -55,12 +59,13 @@ public static TypeWithState Create(TypeWithAnnotations typeWithAnnotations, Flow
state = NullableFlowState.NotNull;
}
- return new TypeWithState(type, state);
+ return Create(type, state);
}
private TypeWithState(TypeSymbol type, NullableFlowState state)
{
Debug.Assert(state == NullableFlowState.NotNull || type?.CanContainNull() != false);
+ Debug.Assert(state != NullableFlowState.MaybeDefault || type is null || type.IsTypeParameterDisallowingAnnotation());
Type = type;
State = state;
}
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
index 301de31075750..2c6c13114d2b8 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
@@ -1334,16 +1334,6 @@
SyntaxTree není součástí kompilace, takže se nedá odebrat.
-
-
- Operátor as může vytvořit hodnotu null, pokud {0} je odkazový typ, který nemůže mít hodnotu null.
-
-
-
-
- Operátor as může pro parametr typu vytvořit hodnotu null.
-
- Název „_“ odkazuje na konstantu, ne na vzor discard. Zadáním „var _“ hodnotu zahodíte a zadáním „@_“ nastavíte pod tímto názvem odkaz na konstantu.
@@ -1354,16 +1344,6 @@
Nepoužívejte „_“ jako konstantu case.
-
-
- Podmíněný přístup může vytvořit hodnotu null, pokud {0} je odkazový typ, který nemůže mít hodnotu null.
-
-
-
-
- Podmíněný přístup může pro parametr typu vytvořit hodnotu null.
-
- Literál s hodnotou null nebo s možnou hodnotou null se převádí na typ bez možnosti hodnoty null.
@@ -1374,16 +1354,6 @@
Literál s hodnotou null nebo s možnou hodnotou null se převádí na typ bez možnosti hodnoty null.
-
-
- Výchozí výraz zavádí hodnotu null, pokud {0} je odkazový typ, který nemůže mít hodnotu null.
-
-
-
-
- Výchozí výraz zavádí pro parametr typu hodnotu null.
-
- Do cíle označeného atributem [DisallowNull] se nedá předat možná hodnota null
@@ -1474,16 +1444,6 @@
Literál null nejde převést na odkazový typ, který nemůže mít hodnotu null.
-
-
- Literál null zavádí hodnotu null, pokud {0} je odkazový typ, který nemůže mít hodnotu null.
-
-
-
-
- Literál null zavádí pro parametr typu hodnotu null.
-
- V parametru {0} v {1} může být argument s odkazem null.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
index efe063d472119..7f84d09a65d76 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
@@ -1334,16 +1334,6 @@
SyntaxTree ist kein Teil der Kompilierung und kann daher nicht entfernt werden.
-
-
- Der as-Operator kann einen NULL-Wert generieren, wenn "{0}" ein Verweistyp ist, der keine NULL-Werte zulässt.
-
-
-
-
- Der as-Operator kann einen NULL-Wert für einen Typparameter generieren.
-
- Der Name "_" verweist auf die Konstante, nicht auf das discard-Muster. Verwenden Sie "var _" zum Verwerfen des Werts oder "@_" zum Verweis auf eine Konstante über diesen Namen.
@@ -1354,16 +1344,6 @@
Verwenden Sie "_" nicht für eine case-Konstante.
-
-
- Der bedingte Zugriff generiert möglicherweise einen NULL-Wert, wenn "{0}" ein Verweistyp ist, der keine NULL-Werte zulässt.
-
-
-
-
- Der bedingte Zugriff generiert möglicherweise einen NULL-Wert für einen Typparameter.
-
- Das NULL-Literal oder ein möglicher NULL-Wert wird in einen Nicht-Nullable-Typ konvertiert.
@@ -1374,16 +1354,6 @@
Das NULL-Literal oder ein möglicher NULL-Wert wird in einen Nicht-Nullable-Typ konvertiert.
-
-
- Ein Standardausdruck führt einen NULL-Wert ein, wenn "{0}" ein Verweistyp ist, der keine NULL-Werte zulässt.
-
-
-
-
- Ein Standardausdruck führt einen NULL-Wert für einen Typparameter ein.
-
- Ein möglicher NULL-Wert darf nicht an ein Ziel übergeben werden, das mit dem [DisallowNull]-Attribut markiert ist.
@@ -1474,16 +1444,6 @@
Ein NULL-Literal kann nicht in einen Verweistyp konvertiert werden, der keine NULL-Werte zulässt.
-
-
- Ein NULL-Literal führt einen NULL-Wert ein, wenn "{0}" ein Verweistyp ist, der keine NULL-Werte zulässt.
-
-
-
-
- Ein NULL-Literal führt einen NULL-Wert für einen Typparameter ein.
-
- Mögliches Nullverweisargument für den Parameter "{0}" in "{1}".
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
index f7c6745971011..ff3c3330f783e 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
@@ -1335,16 +1335,6 @@
SyntaxTree no forma parte de la compilación, así que no se puede quitar
-
-
- El operador "as" puede producir un valor NULL cuando "{0}" es un tipo de referencia que no acepta valores NULL.
-
-
-
-
- El operador "as" puede generar un valor NULL para un parámetro de tipo.
-
- El nombre "_" hace referencia a la constante, no al patrón de descarte. Use "var _" para descartar el valor o "@_" para hacer referencia a una constante con ese nombre.
@@ -1355,16 +1345,6 @@
No use "_" para una constante de caso.
-
-
- El acceso condicional puede producir un valor NULL cuando "{0}" es un tipo de referencia que no acepta valores NULL.
-
-
-
-
- El acceso condicional puede generar un valor NULL para un parámetro de tipo.
-
- Se va a convertir un literal nulo o un posible valor nulo en un tipo que no acepta valores NULL
@@ -1375,16 +1355,6 @@
Se va a convertir un literal nulo o un posible valor nulo en un tipo que no acepta valores NULL
-
-
- Una expresión predeterminada introduce un valor NULL cuando "{0}" es un tipo de referencia que no acepta valores NULL.
-
-
-
-
- Una expresión predeterminada introduce un valor NULL para un parámetro de tipo.
-
- No se puede pasar un posible valor NULL a un destino marcado con el atributo [DisallowNull]
@@ -1475,16 +1445,6 @@
No se puede convertir un literal NULL en un tipo de referencia que no acepta valores NULL.
-
-
- Un literal NULL introduce un valor NULL cuando "{0}" es un tipo de referencia que no acepta valores NULL.
-
-
-
-
- Un literal NULL introduce un valor NULL para un parámetro de tipo.
-
- Posible argumento de referencia nulo para el parámetro "{0}" en "{1}".
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
index 3f0c495358965..9dd39adcbb9fc 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
@@ -1334,16 +1334,6 @@
SyntaxTree ne faisant pas partie de la compilation, il ne peut pas être supprimé
-
-
- L'opérateur 'as' peut produire une valeur null quand '{0}' est un type référence non Nullable.
-
-
-
-
- L'opérateur 'as' peut produire une valeur null pour un paramètre de type.
-
- Le nom '_' fait référence à la constante, pas au modèle d'abandon. Utilisez 'var _' pour abandonner la valeur, ou '@_' pour faire référence à une constante par ce nom.
@@ -1354,16 +1344,6 @@
N'utilisez pas '_' pour une constante case.
-
-
- L'accès conditionnel peut produire une valeur null quand '{0}' est un type référence non Nullable.
-
-
-
-
- L'accès conditionnel peut produire une valeur null pour un paramètre de type.
-
- Conversion de littéral ayant une valeur null ou d'une éventuelle valeur null en type non Nullable.
@@ -1374,16 +1354,6 @@
Conversion de littéral ayant une valeur null ou d'une éventuelle valeur null en type non Nullable.
-
-
- Une expression par défaut introduit une valeur null quand '{0}' est un type référence non Nullable.
-
-
-
-
- Une expression par défaut introduit une valeur null pour un paramètre de type.
-
- Vous ne devez pas passer une possible valeur null à une cible marquée avec l'attribut [DisallowNull]
@@ -1474,16 +1444,6 @@
Impossible de convertir un littéral ayant une valeur null en type référence non Nullable.
-
-
- Un littéral ayant une valeur null introduit une valeur null quand '{0}' est un type référence non Nullable.
-
-
-
-
- Un littéral ayant une valeur null introduit une valeur null pour un paramètre de type.
-
- Existence possible d'un argument de référence null pour le paramètre '{0}' dans '{1}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
index 9ac10140a2bf6..4b03ff97f3e38 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
@@ -1334,16 +1334,6 @@
L'elemento SyntaxTree non fa parte della compilazione, di conseguenza non può essere rimosso
-
-
- L'operatore 'as' può produrre un valore Null quando '{0}' è un tipo riferimento che non ammette i valori Null.
-
-
-
-
- L'operatore 'as' può produrre un valore Null per un parametro di tipo.
-
- Il nome '_' fa riferimento alla costante e non al criterio di eliminazione. Usare 'var _' per eliminare il valore oppure '@_' per fare riferimento a una costante in base a tale nome.
@@ -1354,16 +1344,6 @@
Non usare '_' per una costante di case.
-
-
- L'accesso condizionale può produrre un valore Null quando '{0}' è un tipo riferimento che non ammette i valori Null.
-
-
-
-
- L'accesso condizionale può produrre un valore Null per un parametro di tipo.
-
- Conversione del valore letterale Null o di un possibile valore Null in tipo non nullable.
@@ -1374,16 +1354,6 @@
Conversione del valore letterale Null o di un possibile valore Null in tipo non nullable.
-
-
- Un'espressione predefinita introduce un valore Null quando '{0}' è un tipo riferimento che non ammette i valori Null.
-
-
-
-
- Un'espressione predefinita introduce un valore Null per un parametro di tipo.
-
- Un possibile valore Null non può essere passato a una destinazione contrassegnata con l'attributo [DisallowNull]
@@ -1474,16 +1444,6 @@
Non è possibile convertire il valore letterale Null in tipo riferimento che non ammette i valori Null.
-
-
- Un valore letterale Null introduce un valore Null quando '{0}' è un tipo riferimento che non ammette i valori Null.
-
-
-
-
- Un valore letterale Null introduce un valore Null per un parametro di tipo.
-
- Possibile argomento di riferimento Null per il parametro '{0}' in '{1}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
index 46a89bde0bd71..fc253c3ea8c58 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
@@ -1334,16 +1334,6 @@
SyntaxTree はコンパイルの一部ではないため削除できません
-
-
- '{0}' が NULL 非許容の参照型の場合、'as' 演算子は null 値を生成することがあります。
-
-
-
-
- 'as' 演算子は、型パラメーターに対して null 値を生成することがあります。
-
- 名前 '_' は、破棄パターンではなく定数を参照しています。値を破棄する場合には 'var _' を、そのような名前の定数を参照する場合には '@_' を使用します。
@@ -1354,16 +1344,6 @@
case 定数に '_' を使用しないでください。
-
-
- 条件付きアクセスでは、'{0}' が NULL 非許容の参照型の場合、null 値が生成されることがあります。
-
-
-
-
- 条件付きアクセスでは、型パラメーターに null 値が生成されることがあります。
-
- Null リテラルまたは Null の可能性がある値を Null 非許容型に変換しています。
@@ -1374,16 +1354,6 @@
Null リテラルまたは Null の可能性がある値を Null 非許容型に変換しています。
-
-
- '{0}' が null 非許容参照型である場合、既定の式は null 値を導入します。
-
-
-
-
- 既定の式は、型パラメーターに null 値を導入します。
-
- [DisallowNull] 属性でマークされたターゲットに Null の可能性がある値を渡すことはできません
@@ -1474,16 +1444,6 @@
null リテラルを null 非許容参照型に変換できません。
-
-
- null リテラルは、'{0}' が null 非許容参照型である場合に null 値を導入します。
-
-
-
-
- null リテラルは、型パラメーターに null 値を導入します。
-
- '{1}' 内のパラメーター '{0}' に Null 参照引数がある可能性があります。
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
index fbad2a17b5450..c0a0bca13436b 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
@@ -1334,16 +1334,6 @@
SyntaxTree는 컴파일의 일부가 아니므로 제거할 수 없습니다.
-
-
- '{0}'이(가) nullable이 아닌 참조 형식이면 'as' 연산자가 null 값을 생성할 수 있습니다.
-
-
-
-
- 'as' 연산자가 형식 매개 변수의 null 값을 생성할 수 있습니다.
-
- '_' 이름은 상수를 참조하며, 무시 패턴은 참조하지 않습니다. 'var _'을 사용하여 값을 무시하거나 '@_'을 사용하여 해당 이름별 상수를 참조하세요.
@@ -1354,16 +1344,6 @@
case 상수에 '_'을 사용하지 마세요.
-
-
- '{0}'이(가) nullable이 아닌 참조 형식이면 조건부 액세스가 null 값을 생성할 수 있습니다.
-
-
-
-
- 조건부 액세스가 형식 매개 변수의 null 값을 생성할 수 있습니다.
-
- null 리터럴 또는 가능한 null 값을 nullable이 아닌 형식으로 변환하는 중입니다.
@@ -1374,16 +1354,6 @@
null 리터럴 또는 가능한 null 값을 nullable이 아닌 형식으로 변환하는 중입니다.
-
-
- '{0}'이(가) nullable이 아닌 참조 형식이면 기본 식이 null 값을 지정합니다.
-
-
-
-
- 기본 식이 형식 매개 변수의 null 값을 지정합니다.
-
- 가능한 null 값은 [DisallowNull] 특성으로 표시된 대상에 전달할 수 없음
@@ -1474,16 +1444,6 @@
Null 리터럴을 nullable이 아닌 참조 형식으로 변환할 수 없습니다.
-
-
- '{0}'이(가) nullable이 아닌 참조 형식이면 null 리터럴이 null 값을 지정합니다.
-
-
-
-
- null 리터럴이 형식 매개 변수의 null 값을 지정합니다.
-
- '{1}'의 매개 변수 '{0}'에 대한 가능한 null 참조 인수입니다.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
index 39ffad0032bc7..f73ada97f79d9 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
@@ -1334,16 +1334,6 @@
Element SyntaxTree nie jest częścią kompilacji, więc nie można go usunąć
-
-
- Operator „as” może wygenerować wartość null, jeśli element „{0}” jest typem referencyjnym niedopuszczającym wartości null.
-
-
-
-
- Operator „as” może wygenerować wartość null dla parametru typu.
-
- Nazwa „_” odwołuje się do stałej, a nie do wzorca odrzucania. Użyj elementu „var _”, aby odrzucić wartość, lub użyj elementu „@_”, aby odwołać się do stałej za pomocą tej nazwy.
@@ -1354,16 +1344,6 @@
Nie używaj elementu „_” dla stałej case.
-
-
- Dostęp warunkowy może wygenerować wartość null, jeśli element „{0}” jest typem referencyjnym niedopuszczającym wartości null.
-
-
-
-
- Dostęp warunkowy może wygenerować wartość null dla parametru typu.
-
- Konwertowanie literału o wartości null lub możliwej wartości null na typ niedopuszczający wartości null.
@@ -1374,16 +1354,6 @@
Konwertowanie literału o wartości null lub możliwej wartości null na typ niedopuszczający wartości null.
-
-
- Wyrażenie domyślne wprowadza wartość null, jeśli element „{0}” jest typem referencyjnym niedopuszczającym wartości null.
-
-
-
-
- Wyrażenie domyślne wprowadza wartość null dla parametru typu.
-
- Możliwa wartość null nie może być przekazywana do elementu docelowego oznaczonego atrybutem [DisallowNull]
@@ -1474,16 +1444,6 @@
Nie można przekonwertować literału o wartości null na typ referencyjny niedopuszczający wartości null.
-
-
- Literał o wartości null wprowadza wartość null, jeśli element „{0}” jest typem referencyjnym niedopuszczającym wartości null.
-
-
-
-
- Literał o wartości null wprowadza wartość null dla parametru typu.
-
- Możliwy argument odwołania o wartości null dla parametru „{0}” w „{1}”.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
index 5c0f011ef540b..c82e2a020108b 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
@@ -1334,16 +1334,6 @@
A SyntaxTree não faz parte da compilação, portanto, não pode ser removida
-
-
- O operador 'as' pode produzir um valor nulo quando '{0}' é um tipo de referência que não permite valor nulo.
-
-
-
-
- O operador 'as' pode produzir um valor nulo para um parâmetro de tipo.
-
- O nome '_' refere-se à constante, não ao padrão de descarte. Use 'var _' para descartar o valor ou '@_' para referir-se a uma constante por esse nome.
@@ -1354,16 +1344,6 @@
Não use '_' para uma constante de caso.
-
-
- O acesso condicional pode produzir um valor nulo quando '{0}' é um tipo de referência que não permite valor nulo.
-
-
-
-
- O acesso condicional pode produzir um valor nulo para um parâmetro de tipo.
-
- Conversão de literal nula ou possível valor nulo em tipo não nulo.
@@ -1374,16 +1354,6 @@
Conversão de literal nula ou possível valor nulo em tipo não nulo.
-
-
- Uma expressão padrão introduz um valor nulo quando '{0}' é um tipo de referência que não permite valor nulo.
-
-
-
-
- Uma expressão padrão introduz um valor nulo para um parâmetro de tipo.
-
- Um possível valor nulo não pode ser passado para um destino marcado com o atributo [DisallowNull]
@@ -1474,16 +1444,6 @@
Não é possível converter um literal nulo em um tipo de referência que não permite valor nulo.
-
-
- Um literal nulo introduz um valor nulo quando '{0}' é um tipo de referência que não permite valor nulo.
-
-
-
-
- Um literal nulo introduz um valor nulo para um parâmetro de tipo.
-
- Possível argumento de referência nula para o parâmetro '{0}' em '{1}'.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
index 4c525e8eb3307..c3ce9bcd5abc8 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
@@ -1334,16 +1334,6 @@
SyntaxTree не входит в компиляцию, поэтому его невозможно удалить
-
-
- Оператор as может создавать значение NULL, если "{0}" является ссылочным типом, не допускающим значение NULL.
-
-
-
-
- Оператор as может создавать значение NULL для параметра типа.
-
- Имя "_" ссылается на константу, а не на шаблон отмены. Используйте "var _", чтобы отменить значение, или "@_", чтобы сослаться на константу по этому имени.
@@ -1354,16 +1344,6 @@
Не используйте "_" для константы case.
-
-
- Условный доступ может создавать значение NULL, если "{0}" является ссылочным типом, не допускающим значение NULL.
-
-
-
-
- Условный доступ может создавать значение NULL для параметра типа.
-
- Преобразование литерала, допускающего значение NULL или возможного значения NULL в тип, не допускающий значение NULL.
@@ -1374,16 +1354,6 @@
Преобразование литерала, допускающего значение NULL или возможного значения NULL в тип, не допускающий значение NULL.
-
-
- Выражение по умолчанию вводит значение NULL, если "{0}" является ссылочным типом, не допускающим значение NULL.
-
-
-
-
- Выражение по умолчанию вводит значение NULL для параметра типа.
-
- Возможное значение NULL не может быть передано целевому объекту, помеченному атрибутом [DisallowNull]
@@ -1474,16 +1444,6 @@
Литерал, равный NULL, не может быть преобразован в ссылочный тип, не допускающий значение NULL.
-
-
- Литерал NULL вводит значение NULL, если "{0}" является ссылочным типом, не допускающим значение NULL.
-
-
-
-
- Литерал NULL вводит значение NULL для параметра типа.
-
- Возможно, аргумент-ссылка, допускающий значение NULL, для параметра "{0}" в "{1}".
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
index 2b88c024f68fe..2200dcbca1223 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
@@ -1334,16 +1334,6 @@
SyntaxTree derlemenin bir parçası olmadığından kaldırılamaz
-
-
- '{0}' boş değer atanamayan bir başvuru türü olduğunda 'as' işleci null bir değer üretebilir.
-
-
-
-
- 'as' işleci bir tür parametresi için null bir değer üretebilir.
-
- '_' adı atma desenine değil sabite başvuruyor. Değeri atmak için 'var _' adını ya da bu ada sahip bir sabite başvurmak için '@_' adını kullanın.
@@ -1354,16 +1344,6 @@
Bir case sabiti için '_' adını kullanmayın.
-
-
- '{0}' boş değer atanamayan bir başvuru türü olduğunda koşullu erişim null bir değer üretebilir.
-
-
-
-
- Koşullu erişim, tür parametresi için null bir değer üretebilir.
-
- Null sabit değeri veya olası null değeri, boş değer atanamaz türe dönüştürülüyor.
@@ -1374,16 +1354,6 @@
Null sabit değeri veya olası null değeri, boş değer atanamaz türe dönüştürülüyor.
-
-
- '{0}' boş değer atanamayan bir başvuru türü olduğunda varsayılan bir ifade null değer sağlar.
-
-
-
-
- Varsayılan bir ifade, bir tür parametresi için null değer sağlar.
-
- Olası bir null değer, [DisallowNull] özniteliğiyle işaretlenmiş bir hedefe geçirilemez
@@ -1474,16 +1444,6 @@
Null sabit değer, boş değer atanamayan başvuru türüne dönüştürülemiyor.
-
-
- '{0}' boş değer atanamayan bir başvuru türü olduğunda null sabit değer, bir null değer sağlar.
-
-
-
-
- Null sabit değer, tür parametresi için bir null değer sağlar.
-
- '{1}' içindeki '{0}' parametresi için olası null başvuru bağımsız değişkeni.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
index 7503df260c04e..04d14156810ea 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
@@ -1334,16 +1334,6 @@
编译中不包含 SyntaxTree,因此无法将其删除
-
-
- 当 "{0}" 是不可以为 null 的引用类型时,"as" 运算符可能会生成 null 值。
-
-
-
-
- "as" 运算符可能会为类型参数生成 null 值。
-
- 名称 "_" 引用常量,而不引用放弃模式。请使用 "var _" 放弃该值,或使用 "@_" 来引用该名称的常量。
@@ -1354,16 +1344,6 @@
不要对大小写常量使用 "_"。
-
-
- 当 "{0}" 是不可以为 null 的引用类型时,条件访问可能会生成 null 值。
-
-
-
-
- 条件访问可能会为类型参数生成 null 值。
-
- 将 null 文本或可能的 null 值转换为非 null 类型。
@@ -1374,16 +1354,6 @@
将 null 文本或可能的 null 值转换为非 null 类型。
-
-
- 当 "{0}" 是不可以为 null 的引用类型时,默认表达式就会引入 null 值。
-
-
-
-
- 默认表达式为类型参数引入了 null 值。
-
- 可能的 null 值可能不会传递到用 [DisallowNull] 属性标记的目标
@@ -1474,16 +1444,6 @@
无法将 null 文本转换为不可为 null 的引用类型。
-
-
- 当 "{0}" 是不可以为 null 的引用类型时, null 文本就会引入 null 值。
-
-
-
-
- null 文本为类型参数引入了 null 值。
-
- “{1}”中“{0}”形参的可能的 null 引用实参。
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
index 31be7fab29761..7d126ccb9c88b 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
@@ -1334,16 +1334,6 @@
因為 SyntaxTree 不屬於編譯的一部份,所以無法將其移除
-
-
- 當 '{0}' 是不可為 null 的參考型別時,'as' 運算子可能會產生 null 值。
-
-
-
-
- 對於型別參數,'as' 運算子可能會產生 null 值。
-
- 名稱 '_' 參考常數而非捨棄模式。請使用 'var _' 來捨棄值,或使用 '@_' 來依該名稱參考常數。
@@ -1354,16 +1344,6 @@
不可對 case 常數使用 '_'。
-
-
- 當 '{0}' 為不可為 null 的參考型別時,條件式存取可能會產生 null 值。
-
-
-
-
- 條件式存取可能會針對型別參數產生 null 值。
-
- 正在將 Null 常值或可能的 Null 值轉換為不可為 Null 的型別。
@@ -1374,16 +1354,6 @@
正在將 Null 常值或可能的 Null 值轉換為不可為 Null 的型別。
-
-
- 當 '{0}' 為不可為 null 的參考型別時,預設運算式會引入 null 值。
-
-
-
-
- 預設運算式會針對型別參數引入 null 值。
-
- 可能為 null 的值,不能傳遞到標記了 [DisallowNull] 屬性的目標
@@ -1474,16 +1444,6 @@
無法將 null 常值轉換成不可為 Null 的參考型別。
-
-
- 當 '{0}' 為不可為 null 的參考型別時,null 常值會引入 null 值。
-
-
-
-
- null 常值會針對型別參數引入 null 值。
-
- '{1}' 中的參數 '{0}' 可能有 Null 參考引數。
diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
index b06486354a380..428a65a682234 100644
--- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
+++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
@@ -91,7 +91,7 @@ private CSharpCompilation CreateNullableCompilation(CSharpTestSource source, IEn
return CreateCompilation(source, options: WithNonNullTypesTrue(), references: references);
}
- [Fact, WorkItem(37362, "https://github.com/dotnet/roslyn/issues/37362")]
+ [Fact]
public void DefaultLiteralInConditional()
{
var comp = CreateNullableCompilation(@"
@@ -99,18 +99,13 @@ class C
{
public void M(bool condition, T t)
{
- t = default; // 1
- _ = condition ? t : default; // 2
- _ = condition ? default : t; // 3
+ t = default;
+ _ = condition ? t : default;
+ _ = condition ? default : t;
}
}");
- // Missing warnings 2 and 3. https://github.com/dotnet/roslyn/issues/37362
- comp.VerifyDiagnostics(
- // (6,13): warning CS8653: A default expression introduces a null value when 'T' is a non-nullable reference type.
- // t = default; // 1
- Diagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, "default").WithArguments("T").WithLocation(6, 13)
- );
+ comp.VerifyDiagnostics();
}
[Fact, WorkItem(33982, "https://github.com/dotnet/roslyn/issues/33982")]
@@ -2685,17 +2680,14 @@ static void M(ref T t, dynamic? d)
}
static void M2(T t, dynamic? d)
{
- t = d; // 2
+ t = d;
}
}";
var comp = CreateCompilation(source, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
// (6,13): warning CS8601: Possible null reference assignment.
// t = d; // 1
- Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "d").WithLocation(6, 13),
- // (10,13): warning CS8601: Possible null reference assignment.
- // t = d; // 2
- Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "d").WithLocation(10, 13)
+ Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "d").WithLocation(6, 13)
);
}
@@ -4231,9 +4223,9 @@ void M(T t) where T : class?
}";
var comp = CreateCompilationWithIndexAndRange(source, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
- // (7,29): warning CS8654: A null literal introduces a null value when 'T' is a non-nullable reference type.
+ // (7,29): warning CS8625: Cannot convert null literal to non-nullable reference type.
// var t2 = new[] { t, null }; // 1
- Diagnostic(ErrorCode.WRN_NullLiteralMayIntroduceNullT, "null").WithArguments("T").WithLocation(7, 29),
+ Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(7, 29),
// (8,9): warning CS8602: Dereference of a possibly null reference.
// t2[0].ToString(); // warn // 2
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t2[0]").WithLocation(8, 9)
@@ -4521,15 +4513,9 @@ void M4(string x4, object? y4)
";
CreateCompilation(source, options: WithNonNullTypesTrue()).VerifyDiagnostics(
- // (6,14): warning CS8601: Possible null reference assignment.
- // x1 = (T)y1;
- Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "(T)y1").WithLocation(6, 14),
// (11,14): error CS0266: Cannot implicitly convert type 'object' to 'T'. An explicit conversion exists (are you missing a cast?)
// x2 = y2;
Diagnostic(ErrorCode.ERR_NoImplicitConvCast, "y2").WithArguments("object", "T").WithLocation(11, 14),
- // (11,14): warning CS8601: Possible null reference assignment.
- // x2 = y2;
- Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "y2").WithLocation(11, 14),
// (16,14): warning CS8600: Converting null literal or possible null value to non-nullable type.
// x3 = (string)y3;
Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "(string)y3").WithLocation(16, 14),
@@ -13096,7 +13082,6 @@ class B : IA
var ia = compilation.GetTypeByMetadataName("IA");
var b = compilation.GetTypeByMetadataName("B");
-
var member = ia.GetMember("M1");
var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member);
var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(t => TypeWithAnnotations.Create(t)));
@@ -17489,7 +17474,6 @@ void I.M(T value)
Assert.False(tp.IsNullableType());
}
-
[Fact]
public void PartialMethods_01()
{
@@ -21430,19 +21414,14 @@ static void M(C c, Base b)
[Fact]
public void MaybeNull_Indexer_Implementation()
{
- // Should we enforce nullability annotation attributes inside method bodies? https://github.com/dotnet/roslyn/issues/36039
var source =
@"using System.Diagnostics.CodeAnalysis;
public class CClass where TClass : class
{
- [MaybeNull]public TClass this[int i] { get => null; } // 1, maybe we shouldn't warn here
+ [MaybeNull]public TClass this[int i] { get => null; }
}";
var comp = CreateNullableCompilation(new[] { MaybeNullAttributeDefinition, source });
- comp.VerifyDiagnostics(
- // (4,51): warning CS8603: Possible null reference return.
- // [MaybeNull]public TClass this[int i] { get => null; } // 1, maybe we shouldn't warn here
- Diagnostic(ErrorCode.WRN_NullReferenceReturn, "null").WithLocation(4, 51)
- );
+ comp.VerifyDiagnostics();
}
[Fact]
@@ -29480,10 +29459,9 @@ static void M7([System.Diagnostics.CodeAnalysis.NotNull]T? t7) where T : clas
}
static void M8([System.Diagnostics.CodeAnalysis.AllowNull]T t8) where T : class
{
- new CClass().f2 = t8; // no warning, we currently don't honor the attribute on t6 within the method body
+ new CClass().f2 = t8; // 11
}
}";
- // we currently don't honor the attribute on t6 within the method body https://github.com/dotnet/roslyn/issues/36039
var expected = new[]
{
@@ -29516,7 +29494,10 @@ static void M8([System.Diagnostics.CodeAnalysis.AllowNull]T t8) where T : cla
Diagnostic(ErrorCode.WRN_DisallowNullAttributeForbidsMaybeNullAssignment, "t5").WithLocation(36, 31),
// (47,30): warning CS8601: Possible null reference assignment.
// new CClass().f2 = t7; // 10
- Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "t7").WithLocation(47, 30)
+ Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "t7").WithLocation(47, 30),
+ // (51,30): warning CS8601: Possible null reference assignment.
+ // new CClass().f2 = t8; // 11
+ Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "t8").WithLocation(51, 30)
};
var comp = CreateNullableCompilation(new[] { source, AllowNullAttributeDefinition, MaybeNullAttributeDefinition, NotNullAttributeDefinition },
@@ -38384,12 +38365,12 @@ static void F3() where T : struct
}";
var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
- // (6,24): warning CS8653: A default expression introduces a null value when 'T' is a non-nullable reference type.
+ // (6,24): warning CS8601: Possible null reference assignment.
// a1 = new T[] { default }; // 1
- Diagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, "default").WithArguments("T").WithLocation(6, 24),
- // (7,24): warning CS8653: A default expression introduces a null value when 'T' is a non-nullable reference type.
+ Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "default").WithLocation(6, 24),
+ // (7,24): warning CS8601: Possible null reference assignment.
// a1 = new T[] { default(T) }; // 2
- Diagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, "default(T)").WithArguments("T").WithLocation(7, 24),
+ Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "default(T)").WithLocation(7, 24),
// (12,24): warning CS8625: Cannot convert null literal to non-nullable reference type.
// a2 = new T[] { null }; // 3
Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(12, 24),
@@ -43788,10 +43769,9 @@ public long this[long x]
" }, options: WithNonNullTypesTrue());
c.VerifyDiagnostics(
- // (22,22): warning CS8652: A default expression introduces a null value when 'T' is a non-nullable reference type.
+ // (22,22): warning CS8603: Possible null reference return.
// get { return default(T); }
- Diagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, "default(T)").WithArguments("T").WithLocation(22, 22)
- );
+ Diagnostic(ErrorCode.WRN_NullReferenceReturn, "default(T)").WithLocation(22, 22));
}
[Fact]
@@ -44177,10 +44157,9 @@ public long M1(long x)
" }, options: WithNonNullTypesTrue());
c.VerifyDiagnostics(
- // (22,16): warning CS8652: A default expression introduces a null value when 'T' is a non-nullable reference type.
+ // (22,16): warning CS8603: Possible null reference return.
// return default(T);
- Diagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, "default(T)").WithArguments("T").WithLocation(22, 16)
- );
+ Diagnostic(ErrorCode.WRN_NullReferenceReturn, "default(T)").WithLocation(22, 16));
}
[Fact]
@@ -45793,15 +45772,9 @@ static void F()
new[] { source }, options: WithNonNullTypesTrue(),
parseOptions: TestOptions.Regular8);
comp.VerifyDiagnostics(
- // (5,17): warning CS8653: A default expression introduces a null value when 'T' is a non-nullable reference type.
- // var s = default(T);
- Diagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, "default(T)").WithArguments("T").WithLocation(5, 17),
// (6,9): warning CS8602: Dereference of a possibly null reference.
// s.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "s").WithLocation(6, 9),
- // (7,17): warning CS8653: A default expression introduces a null value when 'T' is a non-nullable reference type.
- // var t = default(T?);
- Diagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, "default(T?)").WithArguments("T").WithLocation(7, 17),
// (7,25): error CS8627: A nullable type parameter must be known to be a value type or non-nullable reference type. Consider adding a 'class', 'struct', or type constraint.
// var t = default(T?);
Diagnostic(ErrorCode.ERR_NullableUnconstrainedTypeParameter, "T?").WithLocation(7, 25),
@@ -45946,11 +45919,7 @@ static void F()
var comp = CreateCompilation(
new[] { source }, options: WithNonNullTypesTrue(),
parseOptions: TestOptions.Regular8);
- // https://github.com/dotnet/roslyn/issues/29895: Improve this diagnostic. default is the cause of the error, but is not mentioned in the diagnostic.
comp.VerifyDiagnostics(
- // (5,15): warning CS8652: A default expression introduces a null value when 'T' is a non-nullable reference type.
- // T s = default;
- Diagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, "default").WithArguments("T").WithLocation(5, 15),
// (6,9): warning CS8602: Dereference of a possibly null reference.
// s.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "s").WithLocation(6, 9)
@@ -50014,15 +49983,15 @@ System.Collections.Generic.IEnumerable M2() where T : class?
}
}";
CreateCompilation(new[] { source }, options: WithNonNullTypesTrue()).VerifyDiagnostics(
- // (6,22): warning CS8652: A default expression introduces a null value when 'T' is a non-nullable reference type.
+ // (6,22): warning CS8603: Possible null reference return.
// yield return default; // 1
- Diagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, "default").WithArguments("T").WithLocation(6, 22),
+ Diagnostic(ErrorCode.WRN_NullReferenceReturn, "default").WithLocation(6, 22),
// (10,22): warning CS8603: Possible null reference return.
// yield return default; // 2
Diagnostic(ErrorCode.WRN_NullReferenceReturn, "default").WithLocation(10, 22),
- // (14,22): warning CS8652: A default expression introduces a null value when 'T' is a non-nullable reference type.
+ // (14,22): warning CS8603: Possible null reference return.
// yield return default; // 3
- Diagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, "default").WithArguments("T").WithLocation(14, 22)
+ Diagnostic(ErrorCode.WRN_NullReferenceReturn, "default").WithLocation(14, 22)
);
}
@@ -55345,7 +55314,6 @@ static bool G(out object o)
comp.VerifyDiagnostics();
}
-
[Fact, WorkItem(31370, "https://github.com/dotnet/roslyn/issues/31370")]
public void SuppressNullableWarning_Deconstruction()
{
@@ -55585,7 +55553,6 @@ static void M((string, C) t, C c)
CompileAndVerify(comp);
}
-
[Fact]
public void SuppressNullableWarning_ValueType_01()
{
@@ -55760,9 +55727,6 @@ static void F3(T3 t3) where T3 : struct
}";
var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics(
- // (5,9): warning CS8653: A default expression introduces a null value when 'T1' is a non-nullable reference type.
- // default(T1).ToString(); // 1
- Diagnostic(ErrorCode.WRN_DefaultExpressionMayIntroduceNullT, "default(T1)").WithArguments("T1").WithLocation(5, 9),
// (5,9): warning CS8602: Dereference of a possibly null reference.
// default(T1).ToString(); // 1
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "default(T1)").WithLocation(5, 9),
@@ -56650,12 +56614,12 @@ static void G6() where T : U
// (33,28): warning CS8625: Cannot convert null literal to non-nullable reference type.
// F6