未验证 提交 49bb0b90 编写于 作者: J Julien Couvreur 提交者: GitHub

Warn for using ? in executable code but outside NonNullTypes(true) context (#28842)

上级 dfb0c1f9
......@@ -329,6 +329,9 @@ internal virtual Imports GetImports(ConsList<Symbol> basesBeingResolved)
return _next.GetImports(basesBeingResolved);
}
protected virtual bool InExecutableBinder
=> _next.InExecutableBinder;
/// <summary>
/// The type containing the binding context
/// </summary>
......
......@@ -338,11 +338,23 @@ internal NamespaceOrTypeOrAliasSymbolWithAnnotations BindNamespaceOrTypeOrAliasS
{
case SyntaxKind.NullableType:
{
TypeSyntax typeArgumentSyntax = ((NullableTypeSyntax)syntax).ElementType;
var nullableSyntax = (NullableTypeSyntax)syntax;
TypeSyntax typeArgumentSyntax = nullableSyntax.ElementType;
TypeSymbolWithAnnotations typeArgument = BindType(typeArgumentSyntax, diagnostics, basesBeingResolved);
TypeSymbolWithAnnotations constructedType;
if (Compilation.IsFeatureEnabled(MessageID.IDS_FeatureStaticNullChecking))
{
if (InExecutableBinder)
{
// Inside a method body or other executable code, we can afford to pull on NonNullTypes symbol or question IsValueType without causing cycles.
// Types created outside executable context should be checked by the responsible symbol (the method symbol checks its return type, for instance).
if (!typeArgument.IsValueType && NonNullTypesContext.NonNullTypes != true)
{
diagnostics.Add(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, nullableSyntax.QuestionToken.GetLocation());
}
}
constructedType = typeArgument.SetIsAnnotated(Compilation);
if (!ShouldCheckConstraints)
{
......
......@@ -56,6 +56,8 @@ protected override LocalFunctionSymbol LookupLocalFunction(SyntaxToken nameToken
internal override uint LocalScopeDepth => Binder.ExternalScope;
protected override bool InExecutableBinder => false;
internal override bool IsAccessibleHelper(Symbol symbol, TypeSymbol accessThroughType, out bool failedThroughTypeCheck, ref HashSet<DiagnosticInfo> useSiteDiagnostics, ConsList<Symbol> basesBeingResolved)
{
failedThroughTypeCheck = false;
......
......@@ -46,6 +46,9 @@ internal override Symbol ContainingMemberOrLambda
get { return _memberSymbol ?? Next.ContainingMemberOrLambda; }
}
protected override bool InExecutableBinder
=> true;
internal Symbol MemberSymbol { get { return _memberSymbol; } }
internal override Binder GetBinder(SyntaxNode node)
......
......@@ -66,6 +66,8 @@ protected override LocalFunctionSymbol LookupLocalFunction(SyntaxToken nameToken
internal override uint LocalScopeDepth => Binder.TopLevelScope;
protected override bool InExecutableBinder => true;
internal override Symbol ContainingMemberOrLambda
{
get
......
......@@ -20,6 +20,8 @@ internal WithMethodTypeParametersBinder(MethodSymbol methodSymbol, Binder next)
_methodSymbol = methodSymbol;
}
protected override bool InExecutableBinder => false;
internal override Symbol ContainingMemberOrLambda
{
get
......
......@@ -13970,7 +13970,7 @@ internal class CSharpResources {
}
/// <summary>
/// Looks up a localized string similar to The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context..
/// Looks up a localized string similar to The suppression operator (!) should be used in code with a &apos;[NonNullTypes(true/false)]&apos; context..
/// </summary>
internal static string WRN_MissingNonNullTypesContext {
get {
......@@ -13979,7 +13979,7 @@ internal class CSharpResources {
}
/// <summary>
/// Looks up a localized string similar to The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context..
/// Looks up a localized string similar to The suppression operator (!) should be used in code with a &apos;[NonNullTypes(true/false)]&apos; context..
/// </summary>
internal static string WRN_MissingNonNullTypesContext_Title {
get {
......@@ -13987,6 +13987,24 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to The annotation for nullable reference types should only be used in code within a &apos;[NonNullTypes(true)]&apos; context..
/// </summary>
internal static string WRN_MissingNonNullTypesContextForAnnotation {
get {
return ResourceManager.GetString("WRN_MissingNonNullTypesContextForAnnotation", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The annotation for nullable reference types should only be used in code within a &apos;[NonNullTypes(true)]&apos; context..
/// </summary>
internal static string WRN_MissingNonNullTypesContextForAnnotation_Title {
get {
return ResourceManager.GetString("WRN_MissingNonNullTypesContextForAnnotation_Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Parameter &apos;{0}&apos; has no matching param tag in the XML comment for &apos;{1}&apos; (but other parameters do).
/// </summary>
......
......@@ -5369,6 +5369,12 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="WRN_NullabilityMismatchInTypeParameterConstraint_Title" xml:space="preserve">
<value>The type cannot be used as type parameter in the generic type or method. Nullability of type argument doesn't match constraint type.</value>
</data>
<data name="WRN_MissingNonNullTypesContextForAnnotation" xml:space="preserve">
<value>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</value>
</data>
<data name="WRN_MissingNonNullTypesContextForAnnotation_Title" xml:space="preserve">
<value>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</value>
</data>
<data name="ERR_ExplicitNullableAttribute" xml:space="preserve">
<value>Explicit application of 'System.Runtime.CompilerServices.NullableAttribute' is not allowed.</value>
</data>
......@@ -5382,10 +5388,10 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<value>Please use language version {0} or greater to use the NonNullTypes attribute.</value>
</data>
<data name="WRN_MissingNonNullTypesContext" xml:space="preserve">
<value>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</value>
<value>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</value>
</data>
<data name="WRN_MissingNonNullTypesContext_Title" xml:space="preserve">
<value>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</value>
<value>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</value>
</data>
<data name="ERR_NonTaskMainCantBeAsync" xml:space="preserve">
<value>A void or int returning entry point cannot be async</value>
......@@ -5522,4 +5528,4 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_OutVariableCannotBeByRef" xml:space="preserve">
<value>An out variable cannot be declared as a ref local</value>
</data>
</root>
\ No newline at end of file
</root>
......@@ -1616,6 +1616,7 @@ internal enum ErrorCode
WRN_MissingNonNullTypesContext = 8629,
ERR_NonNullTypesNotAvailable = 8630,
WRN_NullabilityMismatchInTypeParameterConstraint = 8631,
WRN_MissingNonNullTypesContextForAnnotation = 8632,
}
// Note: you will need to re-generate compiler code after adding warnings (build\scripts\generate-compiler-code.cmd)
}
......@@ -348,6 +348,7 @@ internal static int GetWarningLevel(ErrorCode code)
case ErrorCode.WRN_TupleBinopLiteralNameMismatch:
case ErrorCode.WRN_TypeParameterSameAsOuterMethodTypeParameter:
case ErrorCode.WRN_MissingNonNullTypesContext:
case ErrorCode.WRN_MissingNonNullTypesContextForAnnotation:
return 1;
default:
return 0;
......
......@@ -204,6 +204,7 @@ public static bool IsWarning(ErrorCode code)
case ErrorCode.WRN_NoBestNullabilityConditionalExpression:
case ErrorCode.WRN_MissingNonNullTypesContext:
case ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint:
case ErrorCode.WRN_MissingNonNullTypesContextForAnnotation:
return true;
default:
return false;
......
......@@ -964,7 +964,7 @@ internal virtual bool SynthesizesLoweredBoundBody
{
get
{
return (AssociatedSymbol ?? ContainingType)?.NonNullTypes;
return (AssociatedSymbol ?? ContainingSymbol)?.NonNullTypes;
}
}
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -403,13 +403,23 @@
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContextForAnnotation_Title">
<source>The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</source>
<target state="new">The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_MissingNonNullTypesContext_Title">
<source>The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</source>
<target state="new">The suppression operator (!) should be used in code with a `[NonNullTypes(true/false)]` context.</target>
<source>The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</source>
<target state="new">The suppression operator (!) should be used in code with a '[NonNullTypes(true/false)]' context.</target>
<note />
</trans-unit>
<trans-unit id="WRN_TypeParameterSameAsOuterMethodTypeParameter">
......
......@@ -579,7 +579,7 @@ static void Main()
new C<B2?>();
}
}";
var comp2 = CreateCompilation(source2, parseOptions: TestOptions.Regular8, references: new[] { comp.EmitToImageReference() });
var comp2 = CreateCompilation(new[] { source2, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { comp.EmitToImageReference() });
comp2.VerifyDiagnostics();
var type = comp2.GetMember<NamedTypeSymbol>("C");
......@@ -681,10 +681,10 @@ static void Main()
new C<object, string>();
}
}";
var comp2 = CreateCompilation(new[] { source, source2 }, parseOptions: TestOptions.Regular8);
var comp2 = CreateCompilation(new[] { source, source2, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8);
comp2.VerifyEmitDiagnostics();
comp2 = CreateCompilation(source2, parseOptions: TestOptions.Regular8, references: new[] { comp.EmitToImageReference() });
comp2 = CreateCompilation(new[] { source2, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { comp.EmitToImageReference() });
comp2.VerifyEmitDiagnostics();
var type = comp2.GetMember<NamedTypeSymbol>("C");
......@@ -1292,7 +1292,7 @@ static void G()
F((object? o) => { });
}
}";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular8, options: TestOptions.ReleaseModule);
var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, options: TestOptions.ReleaseModule);
comp.VerifyEmitDiagnostics(
// (9,12): error CS0518: Predefined type 'System.Runtime.CompilerServices.NullableAttribute' is not defined or imported
// F((object? o) => { });
......@@ -1311,7 +1311,7 @@ static void M()
L();
}
}";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular8, options: TestOptions.ReleaseModule);
var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, options: TestOptions.ReleaseModule);
comp.VerifyEmitDiagnostics(
// (5,9): error CS0518: Predefined type 'System.Runtime.CompilerServices.NullableAttribute' is not defined or imported
// object?[] L() => throw new System.NotImplementedException();
......@@ -1330,7 +1330,7 @@ static void M()
L(null, 2);
}
}";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular8, options: TestOptions.ReleaseModule);
var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, options: TestOptions.ReleaseModule);
comp.VerifyEmitDiagnostics(
// (5,16): error CS0518: Predefined type 'System.Runtime.CompilerServices.NullableAttribute' is not defined or imported
// void L(object? x, object y) { }
......
......@@ -385,7 +385,7 @@ internal C(object o)
P2 = new object?[] { o };
}
}";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular8);
var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8);
comp.VerifyDiagnostics();
}
......
......@@ -281,6 +281,7 @@ public void WarningLevel_2()
case ErrorCode.WRN_NoBestNullabilityConditionalExpression:
case ErrorCode.WRN_MissingNonNullTypesContext:
case ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint:
case ErrorCode.WRN_MissingNonNullTypesContextForAnnotation:
Assert.Equal(1, ErrorFacts.GetWarningLevel(errorCode));
break;
case ErrorCode.WRN_InvalidVersionFormat:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册