From 2df938643e0fa2c080dfedc7be10e9d055d61792 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Mon, 13 Aug 2018 15:28:38 -0700 Subject: [PATCH] Update default test options to C# 8.0 (#29225) --- .../CSharp/Portable/Binder/Binder_Symbols.cs | 24 +- .../Portable/Compilation/CSharpCompilation.cs | 38 - .../Portable/Emitter/Model/PEModuleBuilder.cs | 13 +- ...issingNonNullTypesContextDiagnosticInfo.cs | 6 +- .../CSharp/Portable/Errors/MessageID.cs | 2 +- .../Lowering/LocalRewriter/LocalRewriter.cs | 5 +- .../Portable/Symbols/ConstraintsHelper.cs | 2 +- .../Symbols/Metadata/PE/PEModuleSymbol.cs | 13 +- .../Metadata/PE/PETypeParameterSymbol.cs | 11 +- .../Portable/Symbols/MissingModuleSymbol.cs | 5 - .../CSharp/Portable/Symbols/ModuleSymbol.cs | 12 - .../Retargeting/RetargetingModuleSymbol.cs | 9 - .../Symbols/Source/ParameterHelpers.cs | 4 +- .../Symbols/Source/SourceAssemblySymbol.cs | 2 +- .../Symbols/Source/SourceConstructorSymbol.cs | 2 +- .../Source/SourceDelegateMethodSymbol.cs | 4 +- .../Symbols/Source/SourceEventSymbol.cs | 2 +- .../Symbols/Source/SourceFieldSymbol.cs | 2 +- .../Source/SourceMemberContainerSymbol.cs | 2 +- .../Symbols/Source/SourceModuleSymbol.cs | 16 - .../Source/SourceOrdinaryMethodSymbol.cs | 4 +- .../Symbols/Source/SourcePropertySymbol.cs | 4 +- .../SourceUserDefinedOperatorSymbolBase.cs | 4 +- .../CSharp/Portable/Symbols/Symbol.cs | 32 +- .../Portable/Symbols/SymbolWithAnnotations.cs | 3 +- .../Attributes/AttributeTests_Nullable.cs | 44 +- ...Tests_IAnonymousObjectCreationOperation.cs | 8 +- .../IOperationTests_IForLoopStatement.cs | 8 +- ...tionTests_IParameterReferenceExpression.cs | 2 +- .../Test/Semantic/Semantics/ForEachTests.cs | 51 +- .../Semantics/NullableReferenceTypesTests.cs | 1721 +++++++++-------- .../Test/Semantic/Semantics/NullableTests.cs | 39 +- .../Test/Semantic/Semantics/QueryTests.cs | 26 +- .../SemanticModelGetDeclaredSymbolAPITests.cs | 6 +- .../Symbols/AnonymousTypesSemanticsTests.cs | 79 +- .../Symbol/Symbols/GenericConstraintTests.cs | 30 +- .../Core/Portable/MetadataReader/PEModule.cs | 31 - .../Test/Utilities/CSharp/TestOptions.cs | 4 +- .../Compilation/OperationTreeVerifier.cs | 2 + .../ObjectBrowser/CSharp/ObjectBrowerTests.vb | 2 +- 40 files changed, 1124 insertions(+), 1150 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs index 88bff5f82a1..323dd645b03 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Symbols.cs @@ -342,41 +342,41 @@ internal NamespaceOrTypeOrAliasSymbolWithAnnotations BindNamespaceOrTypeOrAliasS TypeSyntax typeArgumentSyntax = nullableSyntax.ElementType; TypeSymbolWithAnnotations typeArgument = BindType(typeArgumentSyntax, diagnostics, basesBeingResolved); TypeSymbolWithAnnotations constructedType; - bool includeNullability = Compilation.IsFeatureEnabled(MessageID.IDS_FeatureStaticNullChecking); - if (includeNullability) + if (typeArgument.TypeKind != TypeKind.TypeParameter && (typeArgument.IsValueType || typeArgument.IsErrorType())) + { + NamedTypeSymbol nullableT = GetSpecialType(SpecialType.System_Nullable_T, diagnostics, syntax); + constructedType = TypeSymbolWithAnnotations.Create(nullableT.Construct(ImmutableArray.Create(typeArgument))); + } + else { if (InExecutableBinder) { // Inside a method body or other executable code, we can 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). + // We still need to delay that check when binding in an attribute argument if (!ShouldCheckConstraintsNullability) { - diagnostics.Add(new LazyMissingNonNullTypesContextDiagnosticInfo(NonNullTypesContext, typeArgument), nullableSyntax.QuestionToken.GetLocation()); + diagnostics.Add(new LazyMissingNonNullTypesContextDiagnosticInfo(Compilation, NonNullTypesContext, typeArgument), nullableSyntax.QuestionToken.GetLocation()); } else if (!typeArgument.IsValueType) { - Symbol.ReportMissingNonNullTypesContextForAnnotation(NonNullTypesContext, diagnostics, nullableSyntax.QuestionToken.GetLocation()); + Symbol.ReportNullableReferenceTypesIfNeeded(Compilation, NonNullTypesContext, diagnostics, nullableSyntax.QuestionToken.GetLocation()); } } - constructedType = typeArgument.SetIsAnnotated(Compilation); if (!ShouldCheckConstraints) { diagnostics.Add(new LazyUseSiteDiagnosticsInfoForNullableType(constructedType), syntax.GetLocation()); } } - else - { - NamedTypeSymbol nullableT = GetSpecialType(SpecialType.System_Nullable_T, diagnostics, syntax); - constructedType = TypeSymbolWithAnnotations.Create(nullableT.Construct(ImmutableArray.Create(typeArgument))); - } + if (ShouldCheckConstraints && constructedType.IsNullableType()) { ReportUseSiteDiagnostics(constructedType.TypeSymbol.OriginalDefinition, diagnostics, syntax); var type = (NamedTypeSymbol)constructedType.TypeSymbol; var location = syntax.Location; - var conversions = this.Conversions.WithNullability(includeNullability); - if (includeNullability && !ShouldCheckConstraintsNullability) + var conversions = this.Conversions.WithNullability(includeNullability: true); + if (!ShouldCheckConstraintsNullability) { diagnostics.Add(new LazyNullableContraintChecksDiagnosticInfo(type, conversions, this.Compilation), location); conversions = conversions.WithNullability(includeNullability: false); diff --git a/src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs b/src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs index 23b710690d0..c16776a9016 100644 --- a/src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs +++ b/src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs @@ -3204,44 +3204,6 @@ internal bool EnableEnumArrayBlockInitialization } } - internal bool ShouldSuppressNullableAnnotations(Symbol definition) - { - Debug.Assert(definition.IsDefinition); - var symbolContainingModule = definition.ContainingModule; - - if ((object)symbolContainingModule != null && symbolContainingModule.UtilizesNullableReferenceTypes) - { - var symbolContainingAssembly = symbolContainingModule.ContainingAssembly; - - if ((object)symbolContainingAssembly != null && !HaveNullableOptOutForAssembly(symbolContainingAssembly) && - !HaveNullableOptOutForDefinition(definition)) - { - // All annotations should be accepted as is - return false; - } - } - - return true; - } - - // PROTOTYPE(NullableReferenceTypes): Checking [NullableOptOutForAssembly] can result - // in cycle decoding attributes. See NullableReferenceTypesTests.AllowAssemblyOptOut. - private bool HaveNullableOptOutForAssembly(AssemblySymbol assembly) - { - //return ((SourceModuleSymbol)SourceModule).IsNullableOptOutForAssembly(assembly) && - // (this.GetNullableReferenceFlags() & NullableReferenceFlags.AllowAssemblyOptOut) != 0; - return false; - } - - // PROTOTYPE(NullableReferenceTypes): Checking [NullableOptOut] can result in cycle - // decoding attributes. See NullableReferenceTypesTests.NullableOptOut_DecodeAttributeCycle_02. - private bool HaveNullableOptOutForDefinition(Symbol definition) - { - //return definition.NullableOptOut && - // (this.GetNullableReferenceFlags() & NullableReferenceFlags.AllowMemberOptOut) != 0; - return false; - } - private abstract class AbstractSymbolSearcher { private readonly PooledDictionary _cache; diff --git a/src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs b/src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs index 63db069f97b..5aaf8dd7de1 100644 --- a/src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs +++ b/src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs @@ -85,18 +85,7 @@ protected bool NeedsGeneratedNullableAttribute get { _needsGeneratedAttributes_IsFrozen = true; - if (Compilation.NeedsGeneratedNullableAttribute || _needsGeneratedNullableAttribute_Value) - { - return true; - } - // PROTOTYPE(NullableReferenceTypes): The call to `SourceModule.UtilizesNullableReferenceTypes` - // seems incorrect. `Compilation.NeedsGeneratedNullableAttribute` should be sufficient. - if (SourceModule.UtilizesNullableReferenceTypes) - { - // Don't report any errors. They should be reported during binding. - return Compilation.CheckIfNullableAttributeShouldBeEmbedded(diagnosticsOpt: null, locationOpt: null); - } - return false; + return Compilation.NeedsGeneratedNullableAttribute || _needsGeneratedNullableAttribute_Value; } } diff --git a/src/Compilers/CSharp/Portable/Errors/LazyMissingNonNullTypesContextDiagnosticInfo.cs b/src/Compilers/CSharp/Portable/Errors/LazyMissingNonNullTypesContextDiagnosticInfo.cs index 48bd11fca79..16e13b3ccf6 100644 --- a/src/Compilers/CSharp/Portable/Errors/LazyMissingNonNullTypesContextDiagnosticInfo.cs +++ b/src/Compilers/CSharp/Portable/Errors/LazyMissingNonNullTypesContextDiagnosticInfo.cs @@ -9,18 +9,20 @@ namespace Microsoft.CodeAnalysis.CSharp /// internal sealed class LazyMissingNonNullTypesContextDiagnosticInfo : LazyDiagnosticInfo { + private readonly CSharpCompilation _compilation; private readonly INonNullTypesContext _context; private readonly TypeSymbolWithAnnotations _type; - internal LazyMissingNonNullTypesContextDiagnosticInfo(INonNullTypesContext context, TypeSymbolWithAnnotations type) + internal LazyMissingNonNullTypesContextDiagnosticInfo(CSharpCompilation compilation, INonNullTypesContext context, TypeSymbolWithAnnotations type) { + _compilation = compilation; _context = context; _type = type; } protected override DiagnosticInfo ResolveInfo() { - return _type.IsValueType ? null : Symbol.ReportMissingNonNullTypesContextForAnnotation(_context); + return _type.IsValueType ? null : Symbol.ReportNullableReferenceTypesIfNeeded(_compilation, _context); } } } diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs index 33a4681d653..4097687fb7c 100644 --- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs +++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs @@ -201,7 +201,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature) switch (feature) { // C# 8 features. - case MessageID.IDS_FeatureStaticNullChecking: + case MessageID.IDS_FeatureStaticNullChecking: // syntax and semantic check return LanguageVersion.CSharp8; // C# 7.3 features. diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs index b6fb7a52b10..cca2c63ea8b 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter.cs @@ -243,7 +243,10 @@ public override BoundNode VisitLocalFunctionStatement(BoundLocalFunctionStatemen bool hasConstraintsWithNullableReferenceTypes = typeParameters.Any( typeParameter => typeParameter.ConstraintTypesNoUseSiteDiagnostics.Any( typeConstraint => typeConstraint.ContainsNullableReferenceTypes())); - if (hasConstraintsWithNullableReferenceTypes) + bool hasReturnTypeWithNullableReferenceTypes = node.Symbol.ReturnType.ContainsNullableReferenceTypes(); + bool hasParametersWithNullableReferenceTypes = node.Symbol.ParameterTypes.Any(parameter => parameter.ContainsNullableReferenceTypes()); + + if (hasConstraintsWithNullableReferenceTypes || hasReturnTypeWithNullableReferenceTypes || hasParametersWithNullableReferenceTypes) { _factory.CompilationState.ModuleBuilderOpt?.EnsureNullableAttributeExists(); } diff --git a/src/Compilers/CSharp/Portable/Symbols/ConstraintsHelper.cs b/src/Compilers/CSharp/Portable/Symbols/ConstraintsHelper.cs index 0302b078c88..e0038710279 100644 --- a/src/Compilers/CSharp/Portable/Symbols/ConstraintsHelper.cs +++ b/src/Compilers/CSharp/Portable/Symbols/ConstraintsHelper.cs @@ -422,7 +422,7 @@ internal static class ConstraintsHelper if (!onLocalFunction) { // Note: Misuse of ? annotation on declarations of local functions is reported when binding their types (since in executable context) - containingSymbol.ReportMissingNonNullTypesContextForAnnotation(diagnostics, syntax.Location); + containingSymbol.ReportNullableReferenceTypesIfNeeded(diagnostics, syntax.Location); } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEModuleSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEModuleSymbol.cs index 632d5585e7b..a8992cb349e 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEModuleSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEModuleSymbol.cs @@ -697,22 +697,11 @@ internal IEnumerable GetForwardedTypes() public override ModuleMetadata GetMetadata() => _module.GetNonDisposableMetadata(); - internal override bool UtilizesNullableReferenceTypes - { - get - { - return _module.UtilizesNullableReferenceTypes(); - } - } - public override bool? NonNullTypes { get { - // PROTOTYPE(NullableReferenceTypes): We don't need to use UtilizesNullableReferenceTypes and should instead default to false - // The default for PE modules is [NonNullTypes(false)] - bool nonNullTypes; - return _module.HasNonNullTypesAttribute(EntityHandle.ModuleDefinition, out nonNullTypes) ? nonNullTypes : this.UtilizesNullableReferenceTypes; + return _module.HasNonNullTypesAttribute(EntityHandle.ModuleDefinition, out bool nonNullTypes) ? (bool?)nonNullTypes : null; } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.cs index ae8e31ae54b..152a1d12629 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.cs @@ -214,10 +214,7 @@ private ImmutableArray GetDeclaredConstraintTypes() // PROTOTYPE(NullableReferenceTypes): Test different [NonNullTypes] on method and containing type. var type = TypeSymbolWithAnnotations.Create(_containingSymbol, typeSymbol); - if (moduleSymbol.UtilizesNullableReferenceTypes) - { - type = NullableTypeDecoder.TransformType(type, constraintHandle, moduleSymbol); - } + type = NullableTypeDecoder.TransformType(type, constraintHandle, moduleSymbol); type = TupleTypeDecoder.DecodeTupleTypesIfApplicable(type, constraintHandle, moduleSymbol); symbolsBuilder.Add(type); @@ -376,12 +373,6 @@ private TypeParameterBounds GetBounds(ConsList inProgress, if (!currentBounds.IsSet(early)) { var constraintTypes = currentBounds.ConstraintTypes; - // PROTOTYPE(NullableReferenceTypes): Update to consider [NonNullTypes]. - if (!ContainingModule.UtilizesNullableReferenceTypes) - { - constraintTypes = constraintTypes.SelectAsArray(t => t.SetUnknownNullabilityForReferenceTypes()); - } - var diagnostics = ArrayBuilder.GetInstance(); ArrayBuilder useSiteDiagnosticsBuilder = null; bool inherited = (_containingSymbol.Kind == SymbolKind.Method) && ((MethodSymbol)_containingSymbol).IsOverride; diff --git a/src/Compilers/CSharp/Portable/Symbols/MissingModuleSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/MissingModuleSymbol.cs index 94c35d5a27c..c6e75d93070 100644 --- a/src/Compilers/CSharp/Portable/Symbols/MissingModuleSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/MissingModuleSymbol.cs @@ -179,11 +179,6 @@ internal override bool HasAssemblyRuntimeCompatibilityAttribute get { return false; } } - internal override bool UtilizesNullableReferenceTypes - { - get { return false; } - } - internal override CharSet? DefaultMarshallingCharSet { get { return null; } diff --git a/src/Compilers/CSharp/Portable/Symbols/ModuleSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/ModuleSymbol.cs index 1a616ce6955..b81a7c4af7c 100644 --- a/src/Compilers/CSharp/Portable/Symbols/ModuleSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/ModuleSymbol.cs @@ -197,14 +197,6 @@ public override ImmutableArray DeclaringSyntaxReferences } } - public override bool? NonNullTypes - { - get - { - return this.UtilizesNullableReferenceTypes; - } - } - /// /// Returns an array of assembly identities for assemblies referenced by this module. /// Items at the same position from ReferencedAssemblies and from ReferencedAssemblySymbols @@ -328,10 +320,6 @@ internal AssemblySymbol GetReferencedAssemblySymbol(int referencedAssemblyIndex) /// internal abstract bool HasAssemblyRuntimeCompatibilityAttribute { get; } - // PROTOTYPE(NullableReferenceTypes): Remove property if all implementations return true. - // PROTOTYPE(NullableReferenceTypes): Consider consolidating property into NonNullTypes - internal abstract bool UtilizesNullableReferenceTypes { get; } - /// /// Default char set for contained types, or null if not specified. /// diff --git a/src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingModuleSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingModuleSymbol.cs index bd75cb0e8ef..01b588f0924 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingModuleSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingModuleSymbol.cs @@ -271,15 +271,6 @@ internal override bool HasAssemblyRuntimeCompatibilityAttribute } } - - internal override bool UtilizesNullableReferenceTypes - { - get - { - return _underlyingModule.UtilizesNullableReferenceTypes; - } - } - internal override CharSet? DefaultMarshallingCharSet { get diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs b/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs index cf3b7711fae..1e64af9fad8 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs @@ -144,13 +144,13 @@ internal static void EnsureNullableAttributeExists(ImmutableArray parameters, DiagnosticBag diagnostics) + internal static void ReportNullableReferenceTypesIfNeeded(ImmutableArray parameters, DiagnosticBag diagnostics) { foreach (var parameter in parameters) { if (parameter.Type.ContainsNullableReferenceTypes()) { - parameter.ReportMissingNonNullTypesContextForAnnotation(diagnostics, parameter.GetNonNullSyntaxNode().Location); + parameter.ReportNullableReferenceTypesIfNeeded(diagnostics, parameter.GetNonNullSyntaxNode().Location); } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs index 7b3bf188107..21805aed910 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs @@ -875,7 +875,7 @@ internal SourceModuleSymbol SourceModule { get { - return SourceModule.UtilizesNullableReferenceTypes; + return SourceModule.NonNullTypes; } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs index 23ec43439b5..db59aa11bbb 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs @@ -116,7 +116,7 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, ParameterHelpers.EnsureIsReadOnlyAttributeExists(Parameters, diagnostics, modifyCompilation: true); ParameterHelpers.ReportAnnotatedUnconstrainedTypeParameters(Parameters, diagnostics); ParameterHelpers.EnsureNullableAttributeExists(Parameters, diagnostics, modifyCompilation: true); - ParameterHelpers.ReportMissingNonNullTypesContextForAnnotation(Parameters, diagnostics); + ParameterHelpers.ReportNullableReferenceTypesIfNeeded(Parameters, diagnostics); } internal ConstructorDeclarationSyntax GetSyntax() diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs index fa1b31c7005..8a3e0d1b8a1 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs @@ -321,12 +321,12 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, if (ReturnType.ContainsNullableReferenceTypes()) { this.DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, location, modifyCompilation: true); - ReportMissingNonNullTypesContextForAnnotation(diagnostics, location); + ReportNullableReferenceTypesIfNeeded(diagnostics, location); } ParameterHelpers.ReportAnnotatedUnconstrainedTypeParameters(Parameters, diagnostics); ParameterHelpers.EnsureNullableAttributeExists(Parameters, diagnostics, modifyCompilation: true); - ParameterHelpers.ReportMissingNonNullTypesContextForAnnotation(Parameters, diagnostics); + ParameterHelpers.ReportNullableReferenceTypesIfNeeded(Parameters, diagnostics); } public override ImmutableArray RefCustomModifiers => _refCustomModifiers; diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventSymbol.cs index 1ac529d1207..34168970471 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventSymbol.cs @@ -693,7 +693,7 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, if (this.Type.ContainsNullableReferenceTypes()) { this.DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, location, modifyCompilation: true); - ReportMissingNonNullTypesContextForAnnotation(diagnostics, location); + ReportNullableReferenceTypesIfNeeded(diagnostics, location); } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldSymbol.cs index 46559ea4006..d02b4df387d 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldSymbol.cs @@ -132,7 +132,7 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, if (this.Type.ContainsNullableReferenceTypes()) { DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, location, modifyCompilation: true); - ReportMissingNonNullTypesContextForAnnotation(diagnostics, location); + ReportNullableReferenceTypesIfNeeded(diagnostics, location); } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs index 85717ab633d..6eef7f90894 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol.cs @@ -1432,7 +1432,7 @@ protected void AfterMembersChecks(DiagnosticBag diagnostics) interfaces.Any(t => t.ContainsNullableReferenceTypes())) { this.DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, location, modifyCompilation: true); - ReportMissingNonNullTypesContextForAnnotation(diagnostics, location); + ReportNullableReferenceTypesIfNeeded(diagnostics, location); } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceModuleSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceModuleSymbol.cs index c4c8b2abcd0..ce2778a8140 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceModuleSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceModuleSymbol.cs @@ -611,22 +611,6 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r WellKnownMember.System_Security_UnverifiableCodeAttribute__ctor)); } } - - if (UtilizesNullableReferenceTypes) - { - // PROTOTYPE(NullableReferenceTypes): Ensure Compilation.NeedsGeneratedNullableAttribute is set. - AddSynthesizedAttribute( - ref attributes, - moduleBuilder.SynthesizeNullableAttribute(WellKnownMember.System_Runtime_CompilerServices_NullableAttribute__ctor, ImmutableArray.Empty)); - } - } - - internal override bool UtilizesNullableReferenceTypes - { - get - { - return _assemblySymbol.DeclaringCompilation.IsFeatureEnabled(MessageID.IDS_FeatureStaticNullChecking); - } } internal override bool HasAssemblyCompilationRelaxationsAttribute diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs index dcdef079acc..cb708a37e03 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs @@ -1054,12 +1054,12 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, if (ReturnType.ContainsNullableReferenceTypes()) { this.DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, location, modifyCompilation: true); - ReportMissingNonNullTypesContextForAnnotation(diagnostics, location); + ReportNullableReferenceTypesIfNeeded(diagnostics, location); } ParameterHelpers.ReportAnnotatedUnconstrainedTypeParameters(Parameters, diagnostics); ParameterHelpers.EnsureNullableAttributeExists(Parameters, diagnostics, modifyCompilation: true); - ParameterHelpers.ReportMissingNonNullTypesContextForAnnotation(Parameters, diagnostics); + ParameterHelpers.ReportNullableReferenceTypesIfNeeded(Parameters, diagnostics); } /// diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs index 42bba29fdee..c44c093ce5c 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbol.cs @@ -773,12 +773,12 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, if (this.Type.ContainsNullableReferenceTypes()) { DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, location, modifyCompilation: true); - ReportMissingNonNullTypesContextForAnnotation(diagnostics, location); + ReportNullableReferenceTypesIfNeeded(diagnostics, location); } ParameterHelpers.ReportAnnotatedUnconstrainedTypeParameters(this.Parameters, diagnostics); ParameterHelpers.EnsureNullableAttributeExists(this.Parameters, diagnostics, modifyCompilation: true); - ParameterHelpers.ReportMissingNonNullTypesContextForAnnotation(this.Parameters, diagnostics); + ParameterHelpers.ReportNullableReferenceTypesIfNeeded(this.Parameters, diagnostics); } private void CheckAccessibility(Location location, DiagnosticBag diagnostics) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs index 60bd8edde27..062fcbb525d 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs @@ -654,11 +654,11 @@ internal sealed override void AfterAddingTypeMembersChecks(ConversionsBase conve if (ReturnType.ContainsNullableReferenceTypes()) { this.DeclaringCompilation.EnsureNullableAttributeExists(diagnostics, location, modifyCompilation: true); - ReportMissingNonNullTypesContextForAnnotation(diagnostics, location); + ReportNullableReferenceTypesIfNeeded(diagnostics, location); } ParameterHelpers.ReportAnnotatedUnconstrainedTypeParameters(Parameters, diagnostics); ParameterHelpers.EnsureNullableAttributeExists(Parameters, diagnostics, modifyCompilation: true); - ParameterHelpers.ReportMissingNonNullTypesContextForAnnotation(Parameters, diagnostics); + ParameterHelpers.ReportNullableReferenceTypesIfNeeded(Parameters, diagnostics); } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Symbol.cs b/src/Compilers/CSharp/Portable/Symbols/Symbol.cs index d1e9aefc5d8..34be15e8764 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Symbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Symbol.cs @@ -856,25 +856,41 @@ public virtual bool HasUnsupportedMetadata } } - internal void ReportMissingNonNullTypesContextForAnnotation(DiagnosticBag diagnostics, Location location) + internal void ReportNullableReferenceTypesIfNeeded(DiagnosticBag diagnostics, Location location) { - ReportMissingNonNullTypesContextForAnnotation(this, diagnostics, location); + ReportNullableReferenceTypesIfNeeded(this.DeclaringCompilation, nonNullTypesContext: this, diagnostics, location); } - internal static void ReportMissingNonNullTypesContextForAnnotation(INonNullTypesContext context, DiagnosticBag diagnostics, Location location) + /// + /// A `?` annotation on a type that isn't a value type causes: + /// - an error before C# 8.0 + /// - a warning outside of a NonNullTypes context + /// + internal static void ReportNullableReferenceTypesIfNeeded(CSharpCompilation compilation, INonNullTypesContext nonNullTypesContext, DiagnosticBag diagnostics, Location location) { - var diagnostic = ReportMissingNonNullTypesContextForAnnotation(context); + var diagnostic = ReportNullableReferenceTypesIfNeeded(compilation, nonNullTypesContext); if (diagnostic != null) { diagnostics.Add(diagnostic, location); } } - internal static DiagnosticInfo ReportMissingNonNullTypesContextForAnnotation(INonNullTypesContext context) + internal static DiagnosticInfo ReportNullableReferenceTypesIfNeeded(CSharpCompilation compilation, INonNullTypesContext nonNullTypesContext) { - return context.NonNullTypes == true ? - null : - new CSDiagnosticInfo(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation); + var featureID = MessageID.IDS_FeatureStaticNullChecking; + if (!compilation.IsFeatureEnabled(featureID)) + { + LanguageVersion availableVersion = compilation.LanguageVersion; + LanguageVersion requiredVersion = featureID.RequiredVersion(); + + return new CSDiagnosticInfo(availableVersion.GetErrorCode(), featureID.Localize(), new CSharpRequiredLanguageVersion(requiredVersion)); + } + else if (nonNullTypesContext.NonNullTypes != true) + { + return new CSDiagnosticInfo(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation); + } + + return null; } internal DiagnosticInfo GetUseSiteDiagnosticForSymbolOrContainingType() diff --git a/src/Compilers/CSharp/Portable/Symbols/SymbolWithAnnotations.cs b/src/Compilers/CSharp/Portable/Symbols/SymbolWithAnnotations.cs index 1c8a0b0e634..127e7763f98 100644 --- a/src/Compilers/CSharp/Portable/Symbols/SymbolWithAnnotations.cs +++ b/src/Compilers/CSharp/Portable/Symbols/SymbolWithAnnotations.cs @@ -238,7 +238,6 @@ private static TypeSymbolWithAnnotations CreateLazyNullableType(CSharpCompilatio public TypeSymbolWithAnnotations SetIsAnnotated(CSharpCompilation compilation) { - Debug.Assert(compilation.IsFeatureEnabled(MessageID.IDS_FeatureStaticNullChecking)); Debug.Assert(CustomModifiers.IsEmpty); var typeSymbol = this.TypeSymbol; @@ -253,6 +252,7 @@ public TypeSymbolWithAnnotations SetIsAnnotated(CSharpCompilation compilation) } else { + // PROTOTYPE(NullableReferenceTypes): what if the Nullable type is missing? (are we missing diagnostics?) return Create(compilation.GetSpecialType(SpecialType.System_Nullable_T).Construct(ImmutableArray.Create(typeSymbol), NonNullTypesContext)); } } @@ -902,7 +902,6 @@ private sealed class LazyNullableTypeParameter : Extensions public LazyNullableTypeParameter(CSharpCompilation compilation, TypeSymbolWithAnnotations underlying) { - Debug.Assert(compilation.IsFeatureEnabled(MessageID.IDS_FeatureStaticNullChecking)); Debug.Assert(!underlying.IsAnnotated); Debug.Assert(underlying.TypeKind == TypeKind.TypeParameter); Debug.Assert(underlying.CustomModifiers.IsEmpty); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Nullable.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Nullable.cs index b5be62388cf..586b3eace12 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Nullable.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Nullable.cs @@ -20,17 +20,10 @@ public void EmptyProject_MissingAttribute() { var source = ""; var comp = CreateEmptyCompilation(source, parseOptions: TestOptions.Regular8); - // PROTOTYPE(NullableReferenceTypes): Do not emit [module: NullableAttribute] if no nullable types, - // or change the missing System.Attribute error to a warning in this case. comp.VerifyEmitDiagnostics( // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. - Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1), - // error CS0518: Predefined type 'System.Attribute' is not defined or imported - Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound).WithArguments("System.Attribute").WithLocation(1, 1), - // error CS0518: Predefined type 'System.Attribute' is not defined or imported - Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound).WithArguments("System.Attribute").WithLocation(1, 1), - // error CS0518: Predefined type 'System.Boolean' is not defined or imported - Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound).WithArguments("System.Boolean").WithLocation(1, 1)); + Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1) + ); } [Fact] @@ -256,7 +249,7 @@ public void EmitAttribute_NoNullable() "System.Runtime.CompilerServices.RuntimeCompatibilityAttribute", "System.Diagnostics.DebuggableAttribute"); }); - // C# 8.0: NullableAttribute included always. + // C# 8.0: NullableAttribute not included if no ? annotation. comp = CreateCompilation(source, parseOptions: TestOptions.Regular8); CompileAndVerify(comp, symbolValidator: module => { @@ -264,7 +257,7 @@ public void EmitAttribute_NoNullable() var type = assembly.GetTypeByMetadataName("C"); var field = (FieldSymbol)type.GetMembers("F").Single(); AssertNoNullableAttribute(field.GetAttributes()); - AssertNullableAttribute(module.GetAttributes()); + AssertNoNullableAttribute(module.GetAttributes()); AssertAttributes(assembly.GetAttributes(), "System.Runtime.CompilerServices.CompilationRelaxationsAttribute", "System.Runtime.CompilerServices.RuntimeCompatibilityAttribute", @@ -337,8 +330,7 @@ void M1() CompileAndVerify(comp, symbolValidator: module => { var assembly = module.ContainingAssembly; - // PROTOTYPE(NullableReferenceTypes): The Nullable attribute shouldn't be synthesized - Assert.NotNull(assembly.GetTypeByMetadataName("System.Runtime.CompilerServices.NullableAttribute")); + Assert.Null(assembly.GetTypeByMetadataName("System.Runtime.CompilerServices.NullableAttribute")); }); } @@ -357,7 +349,7 @@ public void EmitAttribute_Module() var type = assembly.GetTypeByMetadataName("C"); var field = (FieldSymbol)type.GetMembers("F").Single(); AssertNullableAttribute(field.GetAttributes()); - AssertNullableAttribute(module.GetAttributes()); + AssertNoNullableAttribute(module.GetAttributes()); AssertAttributes(assembly.GetAttributes(), "System.Runtime.CompilerServices.CompilationRelaxationsAttribute", "System.Runtime.CompilerServices.RuntimeCompatibilityAttribute", @@ -404,7 +396,7 @@ public class B1 : A public class B2 : A { }"; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); CompileAndVerify(comp, symbolValidator: module => { var type = module.ContainingAssembly.GetTypeByMetadataName("A`1"); @@ -428,7 +420,7 @@ static void G(B1 x, B2 y) F(y, y); } }"; - var comp2 = CreateCompilation(new[] { source2, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { comp.EmitToImageReference() }); + var comp2 = CreateCompilation(new[] { source2, NonNullTypesTrue }, parseOptions: TestOptions.Regular8, references: new[] { comp.EmitToImageReference() }); comp2.VerifyDiagnostics( // (8,14): warning CS8620: Nullability of reference types in argument of type 'B1' doesn't match target type 'A' for parameter 'y' in 'void C.F(A x, A y)'. // F(x, x); @@ -533,9 +525,6 @@ static void G(A a, B b) }"; var comp2 = CreateCompilation(new[] { source2, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { comp.EmitToImageReference() }); comp2.VerifyDiagnostics( - // (8,14): warning CS8620: Nullability of reference types in argument of type 'A' doesn't match target type 'I<(object, object?)>' for parameter 'b' in 'void C.F(I<(object, object)> a, I<(object, object?)> b)'. - // F(a, a); - Diagnostic(ErrorCode.WRN_NullabilityMismatchInArgument, "a").WithArguments("A", "I<(object, object?)>", "b", "void C.F(I<(object, object)> a, I<(object, object?)> b)").WithLocation(8, 14), // (9,11): warning CS8620: Nullability of reference types in argument of type 'B' doesn't match target type 'I<(object, object)>' for parameter 'a' in 'void C.F(I<(object, object)> a, I<(object, object?)> b)'. // F(b, b); Diagnostic(ErrorCode.WRN_NullabilityMismatchInArgument, "b").WithArguments("B", "I<(object, object)>", "a", "void C.F(I<(object, object)> a, I<(object, object?)> b)").WithLocation(9, 11)); @@ -935,7 +924,7 @@ static void G(object o) }"; var comp = CreateCompilation(source, parseOptions: TestOptions.Regular8); // PROTOTYPE(NullableReferenceTypes): Use AssertNullableAttribute(method.GetReturnTypeAttributes()). - AssertAttribute(comp); + AssertNoNullableAttribute(comp); } [Fact] @@ -955,7 +944,7 @@ static void G() }"; var comp = CreateCompilation(source, parseOptions: TestOptions.Regular8); // PROTOTYPE(NullableReferenceTypes): Use AssertNullableAttribute(method.Parameters[0].GetAttributes()). - AssertAttribute(comp); + AssertNoNullableAttribute(comp); } // See https://github.com/dotnet/roslyn/issues/28862. @@ -983,7 +972,7 @@ static void M(object[] c) } }"; var comp = CreateCompilation(source, parseOptions: TestOptions.Regular8, references: new[] { ref0 }); - AssertAttribute(comp); + AssertNoNullableAttribute(comp); } [Fact] @@ -1155,11 +1144,7 @@ static void G(object o) source, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); - comp.VerifyEmitDiagnostics( - // error CS0518: Predefined type 'System.Attribute' is not defined or imported - Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound).WithArguments("System.Attribute").WithLocation(1, 1), - // error CS0518: Predefined type 'System.Attribute' is not defined or imported - Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound).WithArguments("System.Attribute").WithLocation(1, 1)); + comp.VerifyEmitDiagnostics(); } [Fact] @@ -1652,14 +1637,15 @@ private static void AssertAttributes(ImmutableArray attribu AssertEx.SetEqual(actualNames, expectedNames); } - private static void AssertAttribute(CSharpCompilation comp, string attributeName = "NullableAttribute") + private static void AssertNoNullableAttribute(CSharpCompilation comp) { + string attributeName = "NullableAttribute"; var image = comp.EmitToArray(); using (var reader = new PEReader(image)) { var metadataReader = reader.GetMetadataReader(); var attributes = metadataReader.GetCustomAttributeRows().Select(metadataReader.GetCustomAttributeName).ToArray(); - Assert.True(attributes.Contains(attributeName)); + Assert.False(attributes.Contains(attributeName)); } } diff --git a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IAnonymousObjectCreationOperation.cs b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IAnonymousObjectCreationOperation.cs index 32957716b87..b77d4da2132 100644 --- a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IAnonymousObjectCreationOperation.cs +++ b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IAnonymousObjectCreationOperation.cs @@ -379,7 +379,7 @@ void M(object p, List a, List b) IFlowCaptureReferenceOperation: 0 (OperationKind.FlowCaptureReference, Type: System.Int32, IsImplicit) (Syntax: 'from y in b') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, IsImplicit) (Syntax: 'from y in b ... select 0') Left: - IPropertyReferenceOperation: System.String .y { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'from y in b') + IPropertyReferenceOperation: System.String? .y { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'from y in b') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'from y in b') Right: @@ -848,7 +848,7 @@ void M(object p, int i1, int i2, int i3) IFlowCaptureReferenceOperation: 1 (OperationKind.FlowCaptureReference, Type: System.Int32, IsImplicit) (Syntax: 'i1') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ) (Syntax: 'b = new { a ... 2, b = i3 }') Left: - IPropertyReferenceOperation: b>.b { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'b') + IPropertyReferenceOperation: ? b>.b { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'b') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: b>, IsImplicit) (Syntax: 'new { a = i ... , b = i3 }}') Right: @@ -1048,7 +1048,7 @@ void M(object p) Initializers(1): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ?, IsInvalid) (Syntax: 'a = ') Left: - IPropertyReferenceOperation: ? .a { get; } (OperationKind.PropertyReference, Type: ?) (Syntax: 'a') + IPropertyReferenceOperation: ?? .a { get; } (OperationKind.PropertyReference, Type: ?) (Syntax: 'a') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsInvalid, IsImplicit) (Syntax: 'new { a = }') Right: @@ -1216,7 +1216,7 @@ void M(object p, int i, int j) Initializers(1): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ?, IsInvalid, IsImplicit) (Syntax: 'a[i] = j') Left: - IPropertyReferenceOperation: ? .$0 { get; } (OperationKind.PropertyReference, Type: ?, IsInvalid, IsImplicit) (Syntax: 'a[i] = j') + IPropertyReferenceOperation: ?? .$0 { get; } (OperationKind.PropertyReference, Type: ?, IsInvalid, IsImplicit) (Syntax: 'a[i] = j') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsInvalid, IsImplicit) (Syntax: 'new { a[i] = j }') Right: diff --git a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IForLoopStatement.cs b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IForLoopStatement.cs index 138eff26f5f..b9c897c4e5c 100644 --- a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IForLoopStatement.cs +++ b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IForLoopStatement.cs @@ -1931,7 +1931,7 @@ static void Main(string[] args) IParameterReferenceOperation: x (OperationKind.ParameterReference, Type: System.Char, IsImplicit) (Syntax: 'let z = x.ToString()') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, IsImplicit) (Syntax: 'let z = x.ToString()') Left: - IPropertyReferenceOperation: System.String .z { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'x.ToString()') + IPropertyReferenceOperation: System.String? .z { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'x.ToString()') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'let z = x.ToString()') Right: @@ -1950,7 +1950,7 @@ static void Main(string[] args) IBlockOperation (1 statements) (OperationKind.Block, Type: null, IsImplicit) (Syntax: 'z') IReturnOperation (OperationKind.Return, Type: null, IsImplicit) (Syntax: 'z') ReturnedValue: - IPropertyReferenceOperation: System.String .z { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'z') + IPropertyReferenceOperation: System.String? .z { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'z') Instance Receiver: IParameterReferenceOperation: <>h__TransparentIdentifier0 (OperationKind.ParameterReference, Type: , IsImplicit) (Syntax: 'z') InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) @@ -2099,7 +2099,7 @@ private static IEnumerable fun() IParameterReferenceOperation: x (OperationKind.ParameterReference, Type: System.Char, IsImplicit) (Syntax: 'let z = x.ToString()') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, IsImplicit) (Syntax: 'let z = x.ToString()') Left: - IPropertyReferenceOperation: System.String .z { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'x.ToString()') + IPropertyReferenceOperation: System.String? .z { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'x.ToString()') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'let z = x.ToString()') Right: @@ -2118,7 +2118,7 @@ private static IEnumerable fun() IBlockOperation (1 statements) (OperationKind.Block, Type: null, IsImplicit) (Syntax: 'z') IReturnOperation (OperationKind.Return, Type: null, IsImplicit) (Syntax: 'z') ReturnedValue: - IPropertyReferenceOperation: System.String .z { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'z') + IPropertyReferenceOperation: System.String? .z { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'z') Instance Receiver: IParameterReferenceOperation: <>h__TransparentIdentifier0 (OperationKind.ParameterReference, Type: , IsImplicit) (Syntax: 'z') InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) diff --git a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IParameterReferenceExpression.cs b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IParameterReferenceExpression.cs index 15b080494bf..8a5c33ef091 100644 --- a/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IParameterReferenceExpression.cs +++ b/src/Compilers/CSharp/Test/Semantic/IOperation/IOperationTests_IParameterReferenceExpression.cs @@ -116,7 +116,7 @@ public void M(int x, string y) IParameterReferenceOperation: x (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'x') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String) (Syntax: 'Message = ""Hello"" + y') Left: - IPropertyReferenceOperation: System.String .Message { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'Message') + IPropertyReferenceOperation: System.String? .Message { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'Message') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'new { Amoun ... ello"" + y }') Right: diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs index f3ea9878f47..b18b2a2d0f5 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ForEachTests.cs @@ -2241,9 +2241,54 @@ void Goo(System.Collections.Generic.IEnumerable? e) "; var comp = CreateEmptyCompilation(text); comp.VerifyDiagnostics( - // (30,27): error CS0656: Missing compiler required member 'System.Nullable`1.get_Value' - // foreach (var c in e) { } - Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "e").WithArguments("System.Nullable`1", "get_Value")); + // (28,14): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. + // void Goo(System.Collections.Generic.IEnumerable? e) + Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "System.Collections.Generic.IEnumerable? e").WithLocation(28, 14)); + } + + [WorkItem(798000, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/798000")] + [Fact] + public void MissingNullableValue_CSharp7() + { + var text = @" +namespace System +{ + public class Object { } + + public class ValueType {} + public struct Void { } + public struct Nullable { } + public struct Boolean { } +} + +namespace System.Collections.Generic +{ + public interface IEnumerable + { + IEnumerator GetEnumerator(); + } + + public interface IEnumerator + { + T Current { get; } + bool MoveNext(); + } +} + +class C +{ + void Goo(System.Collections.Generic.IEnumerable? e) + { + foreach (var c in e) { } + } +} +"; + var comp = CreateEmptyCompilation(text, parseOptions: TestOptions.Regular7_3, skipUsesIsNullable: true); + comp.VerifyDiagnostics( + // (28,14): error CS8370: Feature 'static null checking' is not available in C# 7.3. Please use language version 8.0 or greater. + // void Goo(System.Collections.Generic.IEnumerable? e) + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_3, "System.Collections.Generic.IEnumerable? e").WithArguments("static null checking", "8.0").WithLocation(28, 14) + ); } [WorkItem(798000, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/798000")] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 8bf3b5014e1..cfe786b10df 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -19,7 +19,7 @@ public class NullableReferenceTypesTests : CSharpTestBase [Fact] public void Test0() { - CSharpCompilation c = CreateCompilation(@" + var source = @" class C { static void Main() @@ -27,15 +27,25 @@ static void Main() string? x = null; } } -", parseOptions: TestOptions.Regular7); - +"; + var c = CreateCompilation(source, parseOptions: TestOptions.Regular7); c.VerifyDiagnostics( - // (6,9): error CS0453: The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable' - // string? x = null; - Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "string?").WithArguments("System.Nullable", "T", "string").WithLocation(6, 9), - // (6,17): warning CS0219: The variable 'x' is assigned but its value is never used - // string? x = null; - Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "x").WithArguments("x").WithLocation(6, 17) + // (6,15): error CS8107: Feature 'static null checking' is not available in C# 7.0. Please use language version 8.0 or greater. + // string? x = null; + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "?").WithArguments("static null checking", "8.0").WithLocation(6, 15), + // (6,17): warning CS0219: The variable 'x' is assigned but its value is never used + // string? x = null; + Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "x").WithArguments("x").WithLocation(6, 17) + ); + + var c2 = CreateCompilation(source, parseOptions: TestOptions.Regular8); + c2.VerifyDiagnostics( + // (6,15): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. + // string? x = null; + Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(6, 15), + // (6,17): warning CS0219: The variable 'x' is assigned but its value is never used + // string? x = null; + Diagnostic(ErrorCode.WRN_UnreferencedVarAssg, "x").WithArguments("x").WithLocation(6, 17) ); } @@ -51,7 +61,7 @@ void M(string z) z.ToString(); } } -", parseOptions: TestOptions.Regular8); +"); c.VerifyDiagnostics(); } @@ -68,7 +78,7 @@ static void Main(string z = null!) string y = null!; // 2 } } -", parseOptions: TestOptions.Regular8); +"); // PROTOTYPE(NullableReferenceTypes): should warn, but the check is implemented in NullableWalker which is skipped... c.VerifyDiagnostics( @@ -99,7 +109,7 @@ static void Main() WriteLine(y.Length); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -117,7 +127,7 @@ public void M() uint y = true ? 1 : a; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): should not warn c.VerifyDiagnostics( // (7,18): warning CS8626: No best nullability for operands of conditional expression 'uint' and 'int'. @@ -143,7 +153,7 @@ public void M() } public static implicit operator C?(int i) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): should be warning c.VerifyDiagnostics(); } @@ -166,7 +176,7 @@ public void M() } public static implicit operator int(C i) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): should be warning c.VerifyDiagnostics(); } @@ -311,17 +321,17 @@ class D3 // PROTOTYPE(NullableReferenceTypes): are annotations on events meaningful/allowed? // PROTOTYPE(NullableReferenceTypes): locations aren't great - var c = CreateCompilation(source, parseOptions: TestOptions.Regular8); + var c = CreateCompilation(source); c.VerifyDiagnostics(expectedDiagnostics); - var c2 = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var c2 = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c2.VerifyDiagnostics( // (37,17): warning CS8602: Possible dereference of a null reference. // void M4() { Event(new C()); } // warn 21 and 22 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "Event").WithLocation(37, 17) ); - var c3 = CreateCompilation(new[] { source, NonNullTypesFalse, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var c3 = CreateCompilation(new[] { source, NonNullTypesFalse, NonNullTypesAttributesDefinition }); c3.VerifyDiagnostics(expectedDiagnostics .Concat(new[] { // (37,17): warning CS8602: Possible dereference of a null reference. @@ -350,7 +360,7 @@ public class E where T : struct return y2; } } -", parseOptions: TestOptions.Regular8); +"); c.VerifyDiagnostics( // (4,12): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. @@ -373,7 +383,7 @@ void M(C c) } } "; - var comp2 = CreateCompilation(new[] { client, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { c.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + var comp2 = CreateCompilation(new[] { client, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { c.EmitToImageReference() }); comp2.VerifyDiagnostics( // (6,9): warning CS8602: Possible dereference of a null reference. // c.M("").ToString(); @@ -399,7 +409,7 @@ class C3 { } [A(typeof(B))] class C4 { }"; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(source); comp.VerifyDiagnostics( // (6,17): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // [A(typeof(object?))] // 1 @@ -408,7 +418,7 @@ class C4 { }"; // [A(typeof(B))] // 2 Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(10, 19)); - comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -467,7 +477,7 @@ public class C return null!; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -515,7 +525,7 @@ class C public void UnannotatedAssemblies_WithSomeExtraAnnotations() { // PROTOTYPE(NullableReferenceTypes): external annotations should be removed or fully designed/productized - var comp = CreateCompilation("", parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(""); comp.VerifyDiagnostics(); var systemNamespace = comp.GetMember("System.Object").ContainingNamespace; @@ -554,20 +564,17 @@ public class String } } "; - var comp = CreateEmptyCompilation(lib, parseOptions: TestOptions.Regular8); + var comp = CreateEmptyCompilation(lib); comp.VerifyDiagnostics( // (11,16): warning CS8632: The annotation for nullable reference types can only be used in code within a '[NonNullTypes(true)]' context. // public String? Concat(String a, String b) => throw null; Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "String?").WithLocation(11, 16) ); - var comp2 = CreateEmptyCompilation("", references: new[] { comp.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + var comp2 = CreateEmptyCompilation("", references: new[] { comp.EmitToImageReference() }); comp2.VerifyDiagnostics(); - var expected = ImmutableArray.Create( -"System.String! System.String.Concat(System.String?, System.String?)", -"System.Runtime.CompilerServices.NullableAttribute.NullableAttribute(System.Boolean[]!)" - ); + var expected = ImmutableArray.Create("System.String! System.String.Concat(System.String?, System.String?)"); var systemNamespace = comp2.GetMember("System.String").ContainingNamespace; VerifyUsesOfNullability(systemNamespace, expected); } @@ -607,15 +614,15 @@ static void Main() Assert.Equal(null, getParameterType(comp1).IsNullable); // ... used in 8.0. - comp1 = CreateCompilation(source1, references: compRefs0, parseOptions: TestOptions.Regular8); + comp1 = CreateCompilation(source1, references: compRefs0); comp1.VerifyDiagnostics(); Assert.Equal(null, getParameterType(comp1).IsNullable); - comp1 = CreateCompilation(source1, references: metadataRefs0, parseOptions: TestOptions.Regular8); + comp1 = CreateCompilation(source1, references: metadataRefs0); comp1.VerifyDiagnostics(); Assert.Equal(null, getParameterType(comp1).IsNullable); // 8.0 library - comp0 = CreateCompilation(source0, parseOptions: TestOptions.Regular8); + comp0 = CreateCompilation(source0); comp0.VerifyDiagnostics(); compRefs0 = new MetadataReference[] { new CSharpCompilationReference(comp0) }; metadataRefs0 = new[] { comp0.EmitToImageReference() }; @@ -630,13 +637,13 @@ static void Main() Assert.Equal(false, getParameterType(comp1).IsNullable); // ... used in 8.0. - comp1 = CreateCompilation(source1, references: compRefs0, parseOptions: TestOptions.Regular8); + comp1 = CreateCompilation(source1, references: compRefs0); comp1.VerifyDiagnostics( // (6,13): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. // A.F(null); Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(6, 13)); Assert.Equal(false, getParameterType(comp1).IsNullable); - comp1 = CreateCompilation(source1, references: metadataRefs0, parseOptions: TestOptions.Regular8); + comp1 = CreateCompilation(source1, references: metadataRefs0); comp1.VerifyDiagnostics( // (6,13): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. // A.F(null); @@ -689,10 +696,10 @@ void verify(Compilation c) Assert.Equal(null, method.Parameters[0].Type.IsNullable); } - var comp1A = CreateCompilation(source1, references: new MetadataReference[] { new CSharpCompilationReference(comp0) }, parseOptions: TestOptions.Regular8); + var comp1A = CreateCompilation(source1, references: new MetadataReference[] { new CSharpCompilationReference(comp0) }); verify(comp1A); - var comp1B = CreateCompilation(source1, references: new[] { comp0.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + var comp1B = CreateCompilation(source1, references: new[] { comp0.EmitToImageReference() }); verify(comp1B); } @@ -739,10 +746,10 @@ void verify(Compilation c) verifyTuple(method.Parameters[0].Type); } - var comp1A = CreateCompilation(source1, references: new[] { new CSharpCompilationReference(comp0) }, parseOptions: TestOptions.Regular8); + var comp1A = CreateCompilation(source1, references: new[] { new CSharpCompilationReference(comp0) }); verify(comp1A); - var comp1B = CreateCompilation(source1, references: new[] { comp0.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + var comp1B = CreateCompilation(source1, references: new[] { comp0.EmitToImageReference() }); verify(comp1B); } @@ -828,7 +835,7 @@ static void F(object x, object? y) var comp0 = CreateCompilation(source0, parseOptions: TestOptions.Regular7); comp0.VerifyDiagnostics(); var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, - references: new[] { comp0.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + references: new[] { comp0.EmitToImageReference() }); comp1.VerifyDiagnostics( // (7,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // z = C.Create(y).F; @@ -903,7 +910,7 @@ static void F(object? x, D1 d1, D2 d2) comp0.VerifyDiagnostics(); var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, - references: new MetadataReference[] { new CSharpCompilationReference(comp0) }, parseOptions: TestOptions.Regular8); + references: new MetadataReference[] { new CSharpCompilationReference(comp0) }); comp1.VerifyDiagnostics( // (43,18): warning CS8604: Possible null reference argument for parameter 'o' in 'object? B2.F(object o)'. // y = b2.F(x); @@ -919,7 +926,7 @@ static void F(object? x, D1 d1, D2 d2) Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "d2.F(x)").WithLocation(51, 13)); comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, - references: new[] { comp0.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + references: new[] { comp0.EmitToImageReference() }); comp1.VerifyDiagnostics( // (43,18): warning CS8604: Possible null reference argument for parameter 'o' in 'object? B2.F(object o)'. // y = b2.F(x); @@ -986,7 +993,7 @@ static void F(object o, D d) ((I)d).G(null).ToString(); } }"; - var comp0 = CreateCompilation(new[] { source0, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp0 = CreateCompilation(new[] { source0, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp0.VerifyDiagnostics(); var ref0 = comp0.EmitToImageReference(); @@ -997,7 +1004,7 @@ static void F(object o, D d) var comp2A = CreateCompilation(source2, references: new[] { ref0, ref1 }, parseOptions: TestOptions.Regular7); comp2A.VerifyDiagnostics(); - var comp2B = CreateCompilation(source2, references: new[] { ref0, ref1 }, parseOptions: TestOptions.Regular8); + var comp2B = CreateCompilation(source2, references: new[] { ref0, ref1 }); comp2B.VerifyDiagnostics(); var expectedDiagnostics = new[] @@ -1021,10 +1028,10 @@ static void F(object o, D d) // ((I)d).G(null).ToString(); Diagnostic(ErrorCode.WRN_NullAsNonNullable, "null").WithLocation(20, 18) }; - var comp2C = CreateCompilation(new[] { source2, NonNullTypesTrue }, references: new[] { ref0, ref1 }, parseOptions: TestOptions.Regular8); + var comp2C = CreateCompilation(new[] { source2, NonNullTypesTrue }, references: new[] { ref0, ref1 }); comp2C.VerifyDiagnostics(expectedDiagnostics); - var comp2D = CreateCompilation(new[] { source2, NonNullTypesFalse }, references: new[] { ref0, ref1 }, parseOptions: TestOptions.Regular8); + var comp2D = CreateCompilation(new[] { source2, NonNullTypesFalse }, references: new[] { ref0, ref1 }); comp2D.VerifyDiagnostics(expectedDiagnostics); } @@ -1072,7 +1079,7 @@ static void F(object? x, object y, C2 c) ((A)c).F(x, y).ToString(); } }"; - var comp0 = CreateCompilation(source0, parseOptions: TestOptions.Regular8); + var comp0 = CreateCompilation(source0); comp0.VerifyDiagnostics(); var ref0 = comp0.EmitToImageReference(); @@ -1080,7 +1087,7 @@ static void F(object? x, object y, C2 c) comp1.VerifyDiagnostics(); var ref1 = comp1.EmitToImageReference(); - var comp2 = CreateCompilation(source2, references: new[] { ref0, ref1 }, parseOptions: TestOptions.Regular8); + var comp2 = CreateCompilation(source2, references: new[] { ref0, ref1 }); comp2.VerifyDiagnostics( // (15,13): warning CS8604: Possible null reference argument for parameter 'x' in 'object C1.F(object x, object y)'. // c.F(x, y).ToString(); @@ -1131,10 +1138,10 @@ static void Main() var comp0 = CreateCompilation(source0, parseOptions: TestOptions.Regular7); comp0.VerifyDiagnostics(); - var comp1 = CreateCompilation(source1, references: new MetadataReference[] { new CSharpCompilationReference(comp0) }, parseOptions: TestOptions.Regular8); + var comp1 = CreateCompilation(source1, references: new MetadataReference[] { new CSharpCompilationReference(comp0) }); comp1.VerifyDiagnostics(); - comp1 = CreateCompilation(source1, references: new[] { comp0.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + comp1 = CreateCompilation(source1, references: new[] { comp0.EmitToImageReference() }); comp1.VerifyDiagnostics(); } @@ -1152,7 +1159,7 @@ class NonNullTypesAttribute : Attribute } } "; - var comp = CreateCompilation(new[] { source }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source }); comp.VerifyDiagnostics(); VerifyNonNullTypes(comp.GetMember("System.Runtime.CompilerServices.NonNullTypesAttribute"), false); @@ -1172,7 +1179,7 @@ class NonNullTypesAttribute : Attribute } } "; - var comp = CreateCompilation(new[] { source }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source }); comp.VerifyDiagnostics(); VerifyNonNullTypes(comp.GetMember("System.Runtime.CompilerServices.NonNullTypesAttribute"), true); @@ -1194,7 +1201,7 @@ class NonNullTypesAttribute : Attribute } "; // PROTOTYPE(NullableReferenceTypes): Why isn't the usage of NonNullTypes reported as obsolete? - var comp = CreateCompilation(new[] { source }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source }); comp.VerifyDiagnostics(); VerifyNonNullTypes(comp.GetMember("System.Runtime.CompilerServices.NonNullTypesAttribute"), true); @@ -1214,7 +1221,7 @@ class SomeAttribute : Attribute } } "; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -1225,7 +1232,7 @@ public void NonNullTypes_Cycle12() [System.Flags] enum E { } "; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -1239,7 +1246,7 @@ interface I { } interface I2 : I { } "; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -1247,16 +1254,16 @@ interface I2 : I { } public void NonNullTypes_Cycle15() { string lib_cs = "public class Base { }"; - var lib = CreateCompilation(lib_cs, parseOptions: TestOptions.Regular8, assemblyName: "lib"); + var lib = CreateCompilation(lib_cs, assemblyName: "lib"); string lib2_cs = "public class C : Base { }"; - var lib2 = CreateCompilation(lib2_cs, references: new[] { lib.EmitToImageReference() }, parseOptions: TestOptions.Regular8, assemblyName: "lib2"); + var lib2 = CreateCompilation(lib2_cs, references: new[] { lib.EmitToImageReference() }, assemblyName: "lib2"); string source_cs = @" [D] class DAttribute : C { } "; - var comp = CreateCompilation(source_cs, references: new[] { lib2.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(source_cs, references: new[] { lib2.EmitToImageReference() }); comp.VerifyDiagnostics( // (3,20): error CS0012: The type 'Base' is defined in an assembly that is not referenced. You must add a reference to assembly 'lib, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. // class DAttribute : C { } @@ -1281,7 +1288,7 @@ class AttributeWithProperty : System.ComponentModel.DisplayNameAttribute public override string DisplayName { get => throw null; } } "; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -1318,7 +1325,7 @@ class NonNullTypesAttribute : Attribute } } "; - var comp = CreateEmptyCompilation(source, parseOptions: TestOptions.Regular8); + var comp = CreateEmptyCompilation(source); comp.VerifyDiagnostics(); } @@ -1338,7 +1345,7 @@ class D } } "; - var comp = CreateCompilation(source + NonNullTypesAttributesDefinition, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(source + NonNullTypesAttributesDefinition); comp.VerifyDiagnostics(); } @@ -1396,7 +1403,7 @@ public class External } "; - var libComp = CreateCompilation(new[] { lib, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var libComp = CreateCompilation(new[] { lib, NonNullTypesTrue, NonNullTypesAttributesDefinition }); libComp.VerifyDiagnostics( // (13,27): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // public static string? fns; @@ -1556,7 +1563,7 @@ public void SuppressedNullConvertedToUnconstrainedT() public class List2 { public T Item { get; set; } = null!; } "; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (2,55): error CS0403: Cannot convert null to type parameter 'T' because it could be a non-nullable value type. Consider using 'default(T)' instead. // public class List2 { public T Item { get; set; } = null!; } @@ -1571,7 +1578,7 @@ public void TwiceSuppressedNullConvertedToUnconstrainedT() public class List2 { public T Item { get; set; } = null!!; } "; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (2,55): error CS0403: Cannot convert null to type parameter 'T' because it could be a non-nullable value type. Consider using 'default(T)' instead. // public class List2 { public T Item { get; set; } = null!!; } @@ -1607,7 +1614,7 @@ public class External } "; - var libComp = CreateCompilation(new[] { lib, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var libComp = CreateCompilation(new[] { lib, NonNullTypesTrue, NonNullTypesAttributesDefinition }); var source = @" using System.Runtime.CompilerServices; @@ -1718,7 +1725,7 @@ public class External } "; - var libComp = CreateCompilation(new[] { lib, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var libComp = CreateCompilation(new[] { lib, NonNullTypesTrue, NonNullTypesAttributesDefinition }); var source = @" using System.Runtime.CompilerServices; @@ -1821,7 +1828,7 @@ public class External } "; - var libComp = CreateCompilation(new[] { lib, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var libComp = CreateCompilation(new[] { lib, NonNullTypesTrue, NonNullTypesAttributesDefinition }); var source = @" using System.Runtime.CompilerServices; @@ -1931,7 +1938,7 @@ public class External } "; - var libComp = CreateCompilation(new[] { lib, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var libComp = CreateCompilation(new[] { lib, NonNullTypesTrue, NonNullTypesAttributesDefinition }); var source = @" using System.Runtime.CompilerServices; @@ -2045,7 +2052,7 @@ public void M() void verifyOblivious(Compilation comp) { - VerifyNonNullTypes(comp.GetMember("Oblivious"), false); + VerifyNonNullTypes(comp.GetMember("Oblivious"), null); } } @@ -2122,7 +2129,7 @@ public class External } "; - var libComp = CreateCompilation(new[] { lib, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var libComp = CreateCompilation(new[] { lib, NonNullTypesTrue, NonNullTypesAttributesDefinition }); verifyExternal(libComp); var source = @" @@ -2238,7 +2245,7 @@ public void M() void verifyOblivious(Compilation comp) { - VerifyNonNullTypes((NamedTypeSymbol)comp.GetMember("Oblivious"), false); + VerifyNonNullTypes((NamedTypeSymbol)comp.GetMember("Oblivious"), null); } void verifyExternal(Compilation comp) @@ -2257,7 +2264,7 @@ public void NonNullTypes_OnModule() public class Oblivious { } "; - var obliviousComp = CreateCompilation(new[] { obliviousLib, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var obliviousComp = CreateCompilation(new[] { obliviousLib, NonNullTypesAttributesDefinition }); obliviousComp.VerifyDiagnostics(); VerifyNonNullTypes(obliviousComp.GetMember("Oblivious"), expectNonNullTypes: false); @@ -2285,7 +2292,7 @@ public sealed class NonNullTypesAttribute : Attribute } "; - var obliviousComp = CreateCompilation(obliviousLib, parseOptions: TestOptions.Regular8); + var obliviousComp = CreateCompilation(obliviousLib); obliviousComp.VerifyDiagnostics(); VerifyNonNullTypes(obliviousComp.GetMember("Oblivious"), expectNonNullTypes: false); @@ -2305,7 +2312,7 @@ public void NonNullTypes_OnModule_WithAlias() public class Oblivious { } "; - var obliviousComp = CreateCompilation(new[] { obliviousLib, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var obliviousComp = CreateCompilation(new[] { obliviousLib, NonNullTypesAttributesDefinition }); obliviousComp.VerifyDiagnostics(); VerifyNonNullTypes(obliviousComp.GetMember("Oblivious"), expectNonNullTypes: false); @@ -2325,7 +2332,7 @@ public void NonNullTypes_OnAssembly() public class Oblivious { } "; - var obliviousComp = CreateCompilation(new[] { obliviousLib, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var obliviousComp = CreateCompilation(new[] { obliviousLib, NonNullTypesTrue, NonNullTypesAttributesDefinition }); obliviousComp.VerifyDiagnostics( // (4,12): error CS0592: Attribute 'NonNullTypes' is not valid on this declaration type. It is only valid on 'module, class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate' declarations. // [assembly: NonNullTypes(false)] @@ -2345,7 +2352,7 @@ class B { A P { get; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -2365,7 +2372,7 @@ class B : A { internal override C F() => throw null; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); var method = comp.GetMember("A.F"); @@ -2397,7 +2404,7 @@ class C }"; var comp = CreateCompilation(new[] { source }, parseOptions: TestOptions.Regular7); comp.VerifyDiagnostics(); - comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Verify no warnings are generated // when [NonNullTypes] is necessary to enable warnings. comp.VerifyDiagnostics( @@ -2427,7 +2434,7 @@ class B : A where T : A.I Diagnostic(ErrorCode.ERR_NonNullTypesNotAvailable, "System.Runtime.CompilerServices.NonNullTypes(true)").WithArguments("8.0").WithLocation(1, 10) ); - comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -2530,7 +2537,7 @@ public void M2() string?[] FalseNCollection() => throw null; // 5 } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyTypes(); compilation.VerifyDiagnostics( @@ -2617,7 +2624,7 @@ public void M2() string?[] FalseNCollection() => throw null; // 7 } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyTypes(); compilation.VerifyDiagnostics( @@ -2702,7 +2709,7 @@ public void M() void FalseNOut(out string? ns) => throw null; // warn 7 } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyTypes(); compilation.VerifyDiagnostics( @@ -2790,7 +2797,7 @@ public void M() void FalseNOut(out string? ns) => throw null; // 8 } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyTypes(); compilation.VerifyDiagnostics( @@ -2880,7 +2887,7 @@ public class Base public string? FalseNMethod() => throw null; // warn 8 } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); compilation.VerifyTypes(); compilation.VerifyDiagnostics( @@ -2970,7 +2977,7 @@ public class Base public string? FalseNMethod() => throw null; // 8 } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); compilation.VerifyTypes(); compilation.VerifyDiagnostics( @@ -3028,7 +3035,7 @@ public void M(T t) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyTypes(); compilation.VerifyDiagnostics( @@ -3080,7 +3087,7 @@ void M() public string[] NullableParameterMethod(string[]? x) => throw null; } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyTypes(); compilation.VerifyDiagnostics( @@ -3132,7 +3139,7 @@ void M() } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyTypes(); compilation.VerifyDiagnostics( @@ -3178,7 +3185,7 @@ public void M(T t, NT nt) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyTypes(); compilation.VerifyDiagnostics( @@ -3229,7 +3236,7 @@ class C3 int? F4() => throw null; Nullable F5() => throw null; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,5): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // string? F2() => throw null; @@ -3305,7 +3312,7 @@ class C3 T? F6() where T : struct => throw null; Nullable F7() where T : struct => throw null; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,5): error CS8627: A nullable type parameter must be known to be a value or reference type. Consider adding a 'class', 'struct', or type constraint. // T? F2() => throw null; @@ -3385,7 +3392,7 @@ class B : A } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); //var a = compilation.GetTypeByMetadataName("A"); //var aFoo = a.GetMember("Foo"); @@ -3416,7 +3423,7 @@ public override void Foo(T? x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics(); } @@ -3440,7 +3447,7 @@ class B : A } } "; - CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8).VerifyDiagnostics(); + CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }).VerifyDiagnostics(); } [Fact] @@ -3461,7 +3468,7 @@ public override void Foo(T? x) } } "; - CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8).VerifyDiagnostics(); + CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }).VerifyDiagnostics(); } [Fact] @@ -3484,7 +3491,7 @@ public override System.Nullable Foo() } } "; - CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8).VerifyDiagnostics(); + CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }).VerifyDiagnostics(); } [Fact] @@ -3505,7 +3512,7 @@ public override void M1(System.Nullable x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics(); var b = compilation.GetTypeByMetadataName("B"); @@ -3545,7 +3552,7 @@ public override void M1(T? x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics(); @@ -3610,7 +3617,7 @@ public override void M3(T? x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( ); @@ -3650,7 +3657,7 @@ public override void M1(T? x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): The overriding is ambiguous. // We simply matched the first candidate. Should this be an error? @@ -3714,7 +3721,7 @@ public override void M5(C x) class C {} "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics(); var b = compilation.GetTypeByMetadataName("B"); @@ -3747,7 +3754,7 @@ class B : A } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics(); var b = compilation.GetTypeByMetadataName("B"); @@ -3775,7 +3782,7 @@ class B : A } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (11,38): error CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly // public override void M1(T? x) where T : struct @@ -3838,7 +3845,7 @@ public override void M4(T? x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (8,23): error CS8627: A nullable type parameter must be known to be a value or reference type. Consider adding a 'class', 'struct', or type constraint. // public void M2(T? x) @@ -3903,7 +3910,7 @@ public override void M1(T? x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (4,50): error CS0453: The type 'T' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable' // public virtual void M1(System.Nullable x) where T : class @@ -3944,7 +3951,7 @@ class B : A class C {} "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (4,42): error CS0453: The type 'T' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable' // public virtual C> M1() where T : class @@ -4020,7 +4027,7 @@ public override string M3() } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (32,29): warning CS8609: Nullability of reference types in return type doesn't match overridden member. // public override string? M1() @@ -4105,7 +4112,7 @@ public override void M5(string? x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (27,26): warning CS8610: Nullability of reference types in type of parameter 'x' doesn't match overridden member. @@ -4203,7 +4210,7 @@ public override int M3() } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (42,25): error CS0508: 'B.M3()': return type must be 'int?' to match overridden member 'A.M3()' // public override int M3() @@ -4274,7 +4281,7 @@ public override void M5(int? x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (35,26): error CS0115: 'B.M3(int)': no suitable method found to override @@ -4335,7 +4342,7 @@ void Dummy() } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (19,49): warning CS8608: Nullability of reference types in type doesn't match overridden member. @@ -4416,7 +4423,7 @@ public class B2 : A public override System.Action M5(System.Action x) => throw null; } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (7,14): error CS0592: Attribute 'NonNullTypes' is not valid on this declaration type. It is only valid on 'module, class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate' declarations. @@ -4502,7 +4509,7 @@ public class Class : Base public override List P { get; set; } = default; } "; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,20): error CS8627: A nullable type parameter must be known to be a value or reference type. Consider adding a 'class', 'struct', or type constraint. // public virtual List P { get; set; } = default; @@ -4532,7 +4539,7 @@ public class Class : Base where T : class public override List P { get; set; } = default; } "; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (12,21): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // public override List P { get; set; } = default; @@ -4556,7 +4563,7 @@ public class Class : Base where T : struct public override List P { get; set; } = default; } "; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -4580,7 +4587,7 @@ public class Class2 : Base public override List this[[NonNullTypes(false)] List x] { [return: NonNullTypes(false)] get => throw null; set => throw null; } } "; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (15,92): error CS0592: Attribute 'NonNullTypes' is not valid on this declaration type. It is only valid on 'module, class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate' declarations. // public override List this[[NonNullTypes(false)] List x] { [return: NonNullTypes(false)] get => throw null; set => throw null; } @@ -4607,7 +4614,7 @@ public class Class : Oblivious public override List this[List x] { get => throw null; set => throw null; } } "; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -4651,7 +4658,7 @@ void Dummy() } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (19,50): warning CS8608: Nullability of reference types in type doesn't match overridden member. @@ -4709,7 +4716,7 @@ void Dummy() } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (26,40): warning CS8612: Nullability of reference types in type doesn't match implicitly implemented member 'event Action? IA.E2'. @@ -4802,7 +4809,7 @@ class B2 : IB event System.Action? IB.E3; // 2 } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (34,37): error CS0071: An explicit interface implementation of an event must use event accessor syntax @@ -4917,7 +4924,7 @@ class B2 : A2 } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (28,31): warning CS8608: Nullability of reference types in type doesn't match overridden member. @@ -4999,7 +5006,7 @@ class B1 : A1 } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (14,21): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. @@ -5065,7 +5072,7 @@ class B : IA, IA2 } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (23,22): warning CS8612: Nullability of reference types in type doesn't match implicitly implemented member 'string[] IA.P2'. @@ -5156,7 +5163,7 @@ class B : IA, IA2 } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (22,17): warning CS8615: Nullability of reference types in type doesn't match implemented member 'string?[] IA.P1'. @@ -5235,7 +5242,7 @@ class B : A } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (23,26): warning CS8609: Nullability of reference types in return type doesn't match overridden member. @@ -5291,7 +5298,7 @@ class B : A } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should report return type mismatch // for M1 and M2 (see https://github.com/dotnet/roslyn/issues/28684). compilation.VerifyDiagnostics( @@ -5349,7 +5356,7 @@ class B : IA } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (23,17): warning CS8613: Nullability of reference types in return type doesn't match implicitly implemented member 'T[] IA.M2()'. @@ -5417,7 +5424,7 @@ class B : IA } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (23,13): warning CS8616: Nullability of reference types in return type doesn't match implemented member 'T[] IA.M2()'. @@ -5475,7 +5482,7 @@ class B : IA } "; // PROTOTYPE(NullableReferenceTypes): missing a warning on IA.M2 - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (11,18): warning CS8616: Nullability of reference types in return type doesn't match implemented member 'string[] IA.M1()'. // string?[] IA.M1() @@ -5513,7 +5520,7 @@ class B : IA S[] IA.M2() => throw null; } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (13,12): warning CS8616: Nullability of reference types in return type doesn't match implemented member 'T?[] IA.M2()'. // S[] IA.M2() => throw null; @@ -5548,7 +5555,7 @@ class B : IA S[] IA.M2() => throw null; } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics(); } @@ -5585,7 +5592,7 @@ public override void M3(T?[]? x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (22,26): warning CS8610: Nullability of reference types in type of parameter 'x' doesn't match overridden member. @@ -5634,7 +5641,7 @@ public override void M2(T?[] x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (13,26): warning CS8610: Nullability of reference types in type of parameter 'x' doesn't match overridden member. @@ -5801,7 +5808,7 @@ public void M1(string?[] x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (20,17): warning CS8614: Nullability of reference types in type of parameter 'x' doesn't match implicitly implemented member 'void IA.M2(T[] x)'. @@ -5864,7 +5871,7 @@ void IA.M3(T?[]? x) } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (20,13): warning CS8617: Nullability of reference types in type of parameter 'x' doesn't match implemented member 'void IA.M2(T[] x)'. @@ -5945,7 +5952,7 @@ class B3 : A3 } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (24,25): warning CS8610: Nullability of reference types in type of parameter 'x' doesn't match overridden member. @@ -6030,7 +6037,7 @@ class B3 : IA3 } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (32,16): warning CS8614: Nullability of reference types in type of parameter 'x' doesn't match implicitly implemented member 'int IA2.this[string[] x]'. @@ -6115,7 +6122,7 @@ class B3 : IA3 } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (24,13): warning CS8617: Nullability of reference types in type of parameter 'x' doesn't match implemented member 'int IA1.this[string?[] x]'. @@ -6172,7 +6179,7 @@ partial class C1 partial void M1(T? x, T[]? y, System.Action z, System.Action?[]? u) where T : class { } }"; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (16,18): warning CS8611: Nullability of reference types in type of parameter 'x' doesn't match partial method declaration. @@ -6217,7 +6224,7 @@ partial class C1 partial void M1(T? x, T[]? y, System.Action z, System.Action?[]? u) where T : class { } }"; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (10,18): warning CS8611: Nullability of reference types in type of parameter 'x' doesn't match partial method declaration. @@ -6260,7 +6267,7 @@ partial class C1 partial void M1(T? x, T[]? y, System.Action z, System.Action?[]? u) where T : class { } }"; - var compilation = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (17,18): warning CS8611: Nullability of reference types in type of parameter 'x' doesn't match partial method declaration. @@ -6294,7 +6301,7 @@ class A string? Test2(string y2) { return y2; } } "; - CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8). + CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }). VerifyDiagnostics( // (5,10): error CS0111: Type 'A' already defines a member called 'Test1' with the same parameter types // void Test1(string x2) {} @@ -6320,7 +6327,7 @@ class A } } "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics(); } @@ -6676,7 +6683,7 @@ struct S2 { public S1 F5; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,21): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -6908,7 +6915,7 @@ void Test12(CL1? x12, CL1 y12) class CL1 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullReferenceTypes): Should report WRN_NullReferenceAssignment for `ref x3` // even though the local is unassigned. (The local should be treated as an l-value for assignment.) c.VerifyDiagnostics( @@ -6977,7 +6984,7 @@ class CL0 set { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,31): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. @@ -7012,7 +7019,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() throw new System.NotImplementedException(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,30): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. @@ -7048,7 +7055,7 @@ static void G(I x, params I[] y) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,11): warning CS8620: Nullability of reference types in argument of type 'I' doesn't match target type 'I' for parameter 'x' in 'void C.G(I x, params I[] y)'. // G(y); @@ -7121,7 +7128,7 @@ static void G(object x, params object?[] y) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,17): error CS1740: Named argument 'x' cannot be specified multiple times // G(x: x, x: y); @@ -7175,7 +7182,7 @@ static void G(object? x = null, object y) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,45): error CS1737: Optional parameters must appear after all required parameters // static void G(object? x = null, object y) @@ -7199,7 +7206,7 @@ static void G(params object[] x, params object[] y) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,19): error CS0231: A params parameter must be the last parameter in a formal parameter list // static void G(params object[] x, params object[] y) @@ -7235,7 +7242,7 @@ static void F3(params object x, params object[] y) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,20): error CS0225: The params parameter must be a single dimensional array // static void F2(params object x) @@ -7269,7 +7276,7 @@ public void ParamsArgument_BinaryOperator() public static object operator+(C x, params object?[] y) => x; static object F(C x, object[] y) => x + y; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (3,41): error CS1670: params is not valid in this context // public static object operator+(C x, params object?[] y) => x; @@ -7327,7 +7334,7 @@ void Test6(out CL1? x6, CL1 y6) class CL1 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (15,14): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -7405,7 +7412,7 @@ struct S1 public CL1 F1; public CL1? F2; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (15,14): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -7464,7 +7471,7 @@ struct S1 public CL1 F1; public CL1? F2; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (14,14): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -7511,7 +7518,7 @@ void Test3(CL0 x3) class CL0 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,16): warning CS8620: Nullability of reference types in argument of type 'CL0' doesn't match target type 'CL0' for parameter 'x' in 'void C.M1(ref CL0 x)'. @@ -7544,7 +7551,7 @@ static void G(out object x, ref object y, in object z) x = new object(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,22): warning CS8604: Possible null reference argument for parameter 'y' in 'void C.G(out object x, ref object y, in object z)'. // G(out x, ref y, in z); @@ -7575,7 +7582,7 @@ static void G(out object? x, ref object? y, in object? z) x = new object(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,15): warning CS8600: Converting null literal or possible null value to non-nullable type. // G(out x, ref y, in z); @@ -7734,7 +7741,7 @@ public struct S2 { public object? F2; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { c0.EmitToImageReference() }); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { c0.EmitToImageReference() }); c.VerifyDiagnostics( // (63,16): warning CS8603: Possible null reference return. @@ -7802,7 +7809,7 @@ void Test6() object z6 = x6 ?? new object(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { c0.EmitToImageReference() }); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { c0.EmitToImageReference() }); c.VerifyDiagnostics( // (14,21): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -7868,7 +7875,7 @@ void Test3() object z3 = x3 ?? new object(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { c0.EmitToImageReference() }); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { c0.EmitToImageReference() }); c.VerifyDiagnostics( // (20,22): hidden CS8607: Expression is probably never null. @@ -7939,7 +7946,7 @@ void Test6() object z6 = x6 ?? new object(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { c0.EmitToImageReference() }); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { c0.EmitToImageReference() }); c.VerifyDiagnostics( // (14,21): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -7995,7 +8002,7 @@ void Test3() object x3 = M4() ? M2() : M3(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { c0.EmitToImageReference() }); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { c0.EmitToImageReference() }); c.VerifyDiagnostics( // (14,21): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -8072,7 +8079,7 @@ void Test6() object z6 = x6 ?? new object(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { c0.EmitToImageReference() }); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { c0.EmitToImageReference() }); c.VerifyDiagnostics( // (16,21): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -8133,7 +8140,7 @@ void Test3() object y3 = x3; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { c0.EmitToImageReference() }); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { c0.EmitToImageReference() }); c.VerifyDiagnostics( // (16,21): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -8267,7 +8274,7 @@ class B3 : IA2 } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { c0.EmitToImageReference() }); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { c0.EmitToImageReference() }); c.VerifyDiagnostics(); } @@ -8301,7 +8308,7 @@ CL1 Test1(CL1? x1) class CL1 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,16): warning CS8603: Possible null reference return. @@ -8334,7 +8341,7 @@ CL1 Test2(CL1 x2) class CL1 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,16): warning CS8619: Nullability of reference types in value of type 'CL1' doesn't match target type 'CL1'. @@ -8362,7 +8369,7 @@ class C static IIn G(IIn x) => x; static IOut G(IOut x) => x; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,41): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. // static I F(I x) => x; @@ -8396,7 +8403,7 @@ class C static async Task> G(IIn x) => x; static async Task> G(IOut x) => x; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,53): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. // static async Task> F(I x) => x; @@ -8426,7 +8433,7 @@ public void SimpleWhere() where n < 5 select n; } -}", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +}", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (7,33): error CS1935: Could not find an implementation of the query pattern for source type 'int[]'. 'Where' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'? @@ -8457,7 +8464,7 @@ public void Main(string? s) } public static bool MyIsNullOrEmpty([NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): there should only be two diagnostics c.VerifyDiagnostics( @@ -8495,7 +8502,7 @@ public void Main(string? s) } public static bool MyIsNullOrEmpty([NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): there should only be two diagnostics c.VerifyDiagnostics( @@ -8533,7 +8540,7 @@ public void Main(string? s) } public static bool MyIsNullOrEmpty([NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): there should only be two diagnostics c.VerifyDiagnostics( @@ -8558,7 +8565,7 @@ public class C { public static object MyIsNullOrEmpty([NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); @@ -8585,7 +8592,7 @@ void M(string? s) } public static T MyIsNullOrEmpty([NotNullWhenFalse] string? s, T t) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -8619,7 +8626,7 @@ public void Main(string? s) } public static bool M([NotNullWhenTrue] string? s, out string? s2) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition, NotNullWhenTrueAttributeDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition, NotNullWhenTrueAttributeDefinition }); c.VerifyDiagnostics( // (10,13): warning CS8602: Possible dereference of a null reference. @@ -8665,7 +8672,7 @@ public void Main(string? s) } public static bool M([EnsuresNotNull] string? s, out string? s2) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition, EnsuresNotNullAttributeDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition, EnsuresNotNullAttributeDefinition }); c.VerifyDiagnostics( // (10,13): warning CS8602: Possible dereference of a null reference. @@ -8693,7 +8700,7 @@ public void Main() } public static void M(out string value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -8711,7 +8718,7 @@ public void Main() } public static void M(out string value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -8730,7 +8737,7 @@ public void Main() } public static void M(ref string value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -8748,7 +8755,7 @@ public void Main(string? s) } public static void M(ref string value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (6,15): warning CS8604: Possible null reference argument for parameter 'value' in 'void C.M(ref string value)'. @@ -8771,7 +8778,7 @@ public void Main() } public static void M(ref string value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -8790,7 +8797,7 @@ public void Main() } public static void M(ref string? value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (7,15): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -8815,7 +8822,7 @@ public void Main(string s) } public static void M(ref string? value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (6,15): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -8841,7 +8848,7 @@ public void Main() } public static void M(ref string? value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (7,15): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -8874,7 +8881,7 @@ public void Main(string key) } public static bool TryGetValue(string key, out string? value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string?"); c.VerifyTypes(); @@ -8931,7 +8938,7 @@ public void Main(string? key) } public static void Copy(T key, out T value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string!"); // PROTOTYPE(NullableReferenceTypes): expecting string? c.VerifyTypes(); @@ -8955,7 +8962,7 @@ public void Main(string? key) } public static void Copy(T key, out T value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string!"); c.VerifyTypes(); @@ -8975,7 +8982,7 @@ public void Main(string? key) } public static T Copy(T key) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyVarLocal(c, "string!"); c.VerifyTypes(); @@ -8995,7 +9002,7 @@ public void Main(string? key) } public static T Copy(T key) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyVarLocal(c, "string!"); // PROTOTYPE(NullableReferenceTypes): expecting string? c.VerifyTypes(); @@ -9020,7 +9027,7 @@ public void Main(string? key) } public static void CopyOrDefault(T key, out T value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string!"); c.VerifyTypes(); @@ -9040,7 +9047,7 @@ public void Main(string key) } public static void CopyOrDefault(T key, out T? value) where T : class => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string?"); c.VerifyTypes(); @@ -9064,7 +9071,7 @@ public void Main(string? key) } public static void CopyOrDefault(T key, out T? value) where T : class => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string?"); c.VerifyTypes(); @@ -9089,7 +9096,7 @@ public void Main(string? key) } public static void CopyOrDefault(T key, out T? value) where T : class => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string?"); c.VerifyTypes(); @@ -9113,7 +9120,7 @@ public void Main(string key) } public static void CopyOrDefault(T key, out T?[] value) where T : class => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string?[]"); c.VerifyTypes(); @@ -9137,7 +9144,7 @@ public void Main(string? key) } public static void CopyOrDefault(T key, out T?[] value) where T : class => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string?[]"); c.VerifyTypes(); @@ -9161,7 +9168,7 @@ public void Main(string key) } public static void CopyOrDefault(T key, out T[] value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string![]"); c.VerifyTypes(); @@ -9182,7 +9189,7 @@ public void Main(string? key) } public static void CopyOrDefault(T key, out T[] value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string![]"); // PROTOTYPE(NullableReferenceTypes): expecting string?[] c.VerifyTypes(); @@ -9203,7 +9210,7 @@ public void Main(string? key) } public static void Copy(T key, [EnsuresNotNull] out T value) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string!"); // PROTOTYPE(NullableReferenceTypes): T is inferred to string! instead of string?, so the `var` gets `string!` c.VerifyTypes(); @@ -9224,7 +9231,7 @@ public void Main(string? key) } public static void Copy(T key, [EnsuresNotNull] out T? value) where T : class => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string?"); c.VerifyTypes(); @@ -9244,7 +9251,7 @@ public void Main() } public static void Copy(T key, out T value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string!"); c.VerifyTypes(); @@ -9268,7 +9275,7 @@ public void Main(string key) } public static void Copy(T key, out T value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string!"); c.VerifyTypes(); @@ -9288,7 +9295,7 @@ public void Main(string? key) } public static void Copy(T key, out T value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string!"); c.VerifyTypes(); // PROTOTYPE(NullableReferenceTypes): is string! correct? @@ -9312,7 +9319,7 @@ public void Main(string key) } public static void Copy(T key, out T value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string?"); c.VerifyTypes(); @@ -9336,7 +9343,7 @@ public void Main(string? key) } public static void Copy(T key, out T value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyOutVar(c, "string?"); c.VerifyTypes(); @@ -9360,7 +9367,7 @@ public void Main(string key) } public T Copy(T key) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyVarLocal(c, "string!"); c.VerifyTypes(); @@ -9380,7 +9387,7 @@ public void Main(string? key) } public T Copy(T key) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyVarLocal(c, "string!"); // PROTOTYPE(NullableReferenceTypes): expecting string? c.VerifyTypes(); @@ -9405,7 +9412,7 @@ public void Main(string? key) } public T Copy(T key) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyVarLocal(c, "string!"); c.VerifyTypes(); @@ -9425,7 +9432,7 @@ public void Main(string? key) } public T? Copy(T key) where T : class => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyVarLocal(c, "string?"); c.VerifyTypes(); @@ -9450,7 +9457,7 @@ public void Main(string? key) } public T? Copy(T key) where T : class => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyVarLocal(c, "string?"); c.VerifyTypes(); @@ -9471,7 +9478,7 @@ public class C [EnsuresNotNull] public static T Copy(T key) => throw null; } -" + EnsuresNotNullAttributeDefinition, parseOptions: TestOptions.Regular8); +" + EnsuresNotNullAttributeDefinition); c.VerifyDiagnostics( // (5,6): error CS0592: Attribute 'EnsuresNotNull' is not valid on this declaration type. It is only valid on 'parameter' declarations. @@ -9495,7 +9502,7 @@ public void Main(string s) s2 = null; // warn } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); VerifyVarLocal(c, "string!"); c.VerifyTypes(); @@ -9515,7 +9522,7 @@ public void Main(string s) s2/*T:string*/.ToString(); // ok } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): The suppression operator isn't producing a non-null result // PROTOTYPE(NullableReferenceTypes): I'd expect null! to return a non-null result @@ -9546,7 +9553,7 @@ public void Main(string s, string? ns) ns.ToString(); // ok } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { libComp.EmitToImageReference() }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { libComp.EmitToImageReference() }); VerifyVarLocal(comp, "string!"); comp.VerifyTypes(); @@ -9574,7 +9581,7 @@ public void Main(string? ns, bool b) } public class List { public static List Create(T t) => throw null; } public class List { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyTypes(); comp.VerifyDiagnostics(); @@ -9639,7 +9646,7 @@ public void Main(string s, string? ns) } public class List { public static List Create(T t) => throw null; } public class List { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { obliviousComp.EmitToImageReference() }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { obliviousComp.EmitToImageReference() }); comp.VerifyTypes(); comp.VerifyDiagnostics( @@ -9664,7 +9671,7 @@ public void Main(string s) s.ToString(); // warn 2 } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (6,13): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -9688,7 +9695,7 @@ public void Main(string s) s.ToString(); // warn 2 } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (6,13): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -9722,7 +9729,7 @@ public void Main(string key) } public static bool TryGetValue(string key, [NotNullWhenTrue] out string? value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition, NotNullWhenTrueAttributeDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition, NotNullWhenTrueAttributeDefinition }); c.VerifyDiagnostics( // (13,13): warning CS8602: Possible dereference of a null reference. @@ -9753,7 +9760,7 @@ public void Main() } public static void M([NotNullWhenTrue, NotNullWhenFalse] out string? value) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition, NotNullWhenTrueAttributeDefinition, NotNullWhenFalseAttributeDefinition } , parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition, NotNullWhenTrueAttributeDefinition, NotNullWhenFalseAttributeDefinition } ); c.VerifyDiagnostics(); @@ -9775,7 +9782,7 @@ void Main(C? c) void MyAssert([AssertsTrue] bool condition) => throw null; } -", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -9797,7 +9804,7 @@ void Main(C? c) void MyAssert([AssertsTrue] bool condition) => throw null; } -", AssertsTrueAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", AssertsTrueAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -9817,7 +9824,7 @@ void Main(C? c) void MyAssert([AssertsTrue] bool condition) => throw null; } -", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -9840,7 +9847,7 @@ void Main(bool b) void MyAssert([AssertsTrue] ref bool condition, [AssertsFalse] out bool condition2, [AssertsTrue] in bool condition3) => throw null; } -", NonNullTypesTrue, AssertsTrueAttributeDefinition, AssertsFalseAttributeDefinition, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, AssertsTrueAttributeDefinition, AssertsFalseAttributeDefinition, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -9866,7 +9873,7 @@ void Main(C? c) bool MyAssert([AssertsTrue] bool condition) => throw null; } -", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -9883,7 +9890,7 @@ void Main(C? c) c.ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -9902,7 +9909,7 @@ void Main(string? c) } static void Assert([AssertsTrue] bool b) => throw null; } -", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -9919,7 +9926,7 @@ void Main(string? c) c.ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -9938,7 +9945,7 @@ void Main(string? c, bool b) } static void Assert([AssertsTrue] bool b) => throw null; } -", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -9959,7 +9966,7 @@ void Main(C? c) c.ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -9976,7 +9983,7 @@ void Main(C? c) c.ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -9993,7 +10000,7 @@ void Main(C? c) c.ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -10012,7 +10019,7 @@ void Main(C c) } static void Assert([AssertsTrue] bool b, string message) => throw null; } -", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (7,16): hidden CS8606: Result of the comparison is possibly always false. @@ -10036,7 +10043,7 @@ void Main(C? c) bool Method(string x) => throw null; static void Assert([AssertsTrue] bool b, string message) => throw null; } -", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (7,23): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. @@ -10067,7 +10074,7 @@ void Main(C? c) } static void Assert([AssertsTrue] bool b, string message) => throw null; } -", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (13,9): warning CS8602: Possible dereference of a null reference. @@ -10093,7 +10100,7 @@ void Main(string? s, string? s2) } static void Assert([AssertsTrue] bool b) => throw null; } -", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, AssertsTrueAttributeDefinition, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (11,9): warning CS8602: Possible dereference of a null reference. @@ -10117,7 +10124,7 @@ void Main(C? c) void MyAssert([AssertsFalse] bool condition) => throw null; } -", AssertsFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", AssertsFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -10137,7 +10144,7 @@ void Main(C? c) void MyAssert([AssertsFalse] bool condition) => throw null; } -", AssertsFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", AssertsFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -10168,7 +10175,7 @@ public void Main(string? s) } public static bool MyIsNullOrEmpty([NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -10192,7 +10199,7 @@ public class C { public static object MyIsNullOrEmpty([NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); @@ -10224,7 +10231,7 @@ void Main(string? s, string? s2) } public static bool MyIsNullOrEmpty([NotNullWhenFalse] string? s, [NotNullWhenFalse] string? s2) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -10269,7 +10276,7 @@ void Main(string? s, string? s2) } public static bool MyIsNullOrEmpty([NotNullWhenFalse] string? s, [NotNullWhenTrue] string? s2) => throw null; } -", NotNullWhenFalseAttributeDefinition, NotNullWhenTrueAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NotNullWhenTrueAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -10311,7 +10318,7 @@ void Main(string? s, int x) } public bool this[[NotNullWhenFalse] string? s, int x] => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -10343,7 +10350,7 @@ void Main(string? s) } static bool Method([NotNullWhenFalse] string? s, string s2) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (7,23): warning CS8602: Possible dereference of a null reference. @@ -10375,7 +10382,7 @@ void Main(string? s) } static bool Method([NotNullWhenFalse] string? s, string? s2) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -10408,7 +10415,7 @@ void Main(string? s) } static bool MyIsNullOrEmpty([NotNullWhenFalse] string? s) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (17,34): error CS0246: The type or namespace name 'NotNullWhenFalseAttribute' could not be found (are you missing a using directive or an assembly reference?) @@ -10477,7 +10484,7 @@ public class NotNullWhenFalseAttribute : Attribute public NotNullWhenFalseAttribute(bool bad) { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -10511,7 +10518,7 @@ void Main(string? s) } public static bool MyIsNullOrEmpty([NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (13,13): warning CS8602: Possible dereference of a null reference. @@ -10535,7 +10542,7 @@ void Main(string? s) } static bool MyIsNullOrEmpty([NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -10560,7 +10567,7 @@ void Main(string? s) } public bool MyIsNullOrEmpty([NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -10594,7 +10601,7 @@ public static class Extension { public static bool MyIsNullOrEmpty(this C c, [NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -10623,7 +10630,7 @@ void Main(string? s) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. @@ -10682,7 +10689,7 @@ public class ObsoleteAttribute : Attribute public ObsoleteAttribute(string message) => throw null; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. @@ -10742,7 +10749,7 @@ public class ObsoleteAttribute : Attribute public ObsoleteAttribute(string message) => throw null; } } -", NotNullWhenTrueAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenTrueAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -10800,7 +10807,7 @@ public static class Debug public static void Assert(bool condition, [EnsuresNotNull] string message) => throw null; } } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); @@ -10855,7 +10862,7 @@ public class ObsoleteAttribute : Attribute public ObsoleteAttribute(string message) => throw null; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. @@ -10884,7 +10891,7 @@ void Main(string? s) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,13): warning CS8602: Possible dereference of a null reference. @@ -10909,7 +10916,7 @@ void M() } string? M2(string s) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (6,38): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. @@ -10932,7 +10939,7 @@ void M() } void M2(string s) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (6,35): error CS1503: Argument 1: cannot convert from 'void' to 'string' @@ -10959,7 +10966,7 @@ void Main(string? s) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. @@ -10986,7 +10993,7 @@ public partial class C partial void M3([NotNullWhenFalse] string? s); partial void M3([NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (11,22): error CS0579: Duplicate 'NotNullWhenFalse' attribute @@ -11019,7 +11026,7 @@ void Main(string? s) } public dynamic MyIsNullOrEmpty([NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -11104,7 +11111,7 @@ void Main(C c, string? s) } } "; - var compilation = CreateCompilationWithIL(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, il, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilationWithIL(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, il); compilation.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. // s.ToString(); // warn 1 @@ -11131,7 +11138,7 @@ void Main(string? s) } object MyIsNullOrEmpty([NotNullWhenFalse] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -11162,7 +11169,7 @@ void Main(string? s) } public static bool MyIsNullOrEmpty([NotNullWhenFalse] string? s, [EnsuresNotNull] string? s2) => throw null; } -", NotNullWhenFalseAttributeDefinition, EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); @@ -11191,7 +11198,7 @@ void Main(string? s) } public static bool MyIsNullOrEmpty([NotNullWhenFalse, EnsuresNotNull] string? s) => throw null; } -", NotNullWhenFalseAttributeDefinition, EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NotNullWhenFalseAttributeDefinition, EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); @@ -11212,7 +11219,7 @@ void Main(string? s) } public static void ThrowIfNull(int x, [EnsuresNotNull] string? s) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); @@ -11234,7 +11241,7 @@ void Main(string? s, string? s2) } public static void ThrowIfNull(string? s1, [EnsuresNotNull] string? s2) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -11258,7 +11265,7 @@ void Main(string? s, string? s2) } public int this[string? s1, [EnsuresNotNull] string? s2] { get { throw null; } } } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -11281,7 +11288,7 @@ void Main(string? s, I i) } public static void ThrowIfNull(I x, [EnsuresNotNull] string? s) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,21): warning CS8620: Nullability of reference types in argument of type 'I' doesn't match target type 'I' for parameter 'x' in 'void C.ThrowIfNull(I x, string? s)'. @@ -11304,7 +11311,7 @@ void Main(string? s) } public static void ThrowIfNull([EnsuresNotNull] T s) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -11323,7 +11330,7 @@ void Main(int s) } public static void ThrowIfNull([EnsuresNotNull] T s) => throw null; } -" + EnsuresNotNullAttributeDefinition, parseOptions: TestOptions.Regular8); +" + EnsuresNotNullAttributeDefinition); c.VerifyDiagnostics(); } @@ -11342,7 +11349,7 @@ void M(U u) } public static void ThrowIfNull([EnsuresNotNull] T s) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -11364,7 +11371,7 @@ public interface Interface { void ThrowIfNull(int x, [EnsuresNotNull] string? s); } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); @@ -11391,7 +11398,7 @@ public interface Interface { void ThrowIfNull(int x, [EnsuresNotNull] string? s); } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -11423,7 +11430,7 @@ public interface Interface { void ThrowIfNull(int x, string? s); } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -11449,7 +11456,7 @@ void Main(string? s, D d) s.ToString(); // ok } } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -11475,7 +11482,7 @@ static void F(object? x, object? y, object[]? a) a.ToString(); // ok } } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,9): warning CS8602: Possible dereference of a null reference. @@ -11582,7 +11589,7 @@ static void F(object[]? a, object? b, object? c) IL_0008: ret } } -", parseOptions: TestOptions.Regular8); +"); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -11612,7 +11619,7 @@ static void F(object? x) x.ToString(); // ok } } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (11,9): warning CS8602: Possible dereference of a null reference. @@ -11631,7 +11638,7 @@ public class C public static void Bad([EnsuresNotNull] int i) => throw null; public static void ThrowIfNull([EnsuresNotNull] T t) => throw null; } -" + EnsuresNotNullAttributeDefinition, parseOptions: TestOptions.Regular8); +" + EnsuresNotNullAttributeDefinition); c.VerifyDiagnostics(); @@ -11654,7 +11661,7 @@ void M(T t) } public static void ThrowIfNull([EnsuresNotNull] T s) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (7,9): warning CS8602: Possible dereference of a null reference. @@ -11680,7 +11687,7 @@ void M(Delegate d, string? s) s.ToString(); // warn 2 } } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -11712,7 +11719,7 @@ void M(string? s1, string? s2) } public static void ThrowIfNull(string? x1, [EnsuresNotNull] string? x2) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should we be able to trace that s2 was assigned a non-null value? c.VerifyDiagnostics( @@ -11736,7 +11743,7 @@ void M(string? s1, string? s2) } public static void ThrowIfNull([EnsuresNotNull] string? x1, string? x2) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -11755,7 +11762,7 @@ void M(string? s1) } public static void ThrowIfNull([EnsuresNotNull] string? x1, string? x2) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -11778,7 +11785,7 @@ void M(string? s1, string? s2) } public static void ThrowIfNull(string? x1, string? x2, string? x3, [EnsuresNotNull] string? x4) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -11802,7 +11809,7 @@ void M(string? s1) } public static void ThrowIfNull([EnsuresNotNull] T x1, out T x2) => throw null; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition, EnsuresNotNullAttributeDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition, EnsuresNotNullAttributeDefinition }); c.VerifyTypes(); c.VerifyDiagnostics( @@ -11827,7 +11834,7 @@ void Main(string? s) [System.Diagnostics.Conditional(""DEBUG"")] static void ThrowIfNull(int x, [EnsuresNotNull] string? s) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, options: TestOptions.ReleaseDll); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, options: TestOptions.ReleaseDll); c.VerifyDiagnostics(); } @@ -11846,7 +11853,7 @@ void Main(string? s) } public static void ThrowIfNull([EnsuresNotNull] string? s, string s2) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (7,24): warning CS8602: Possible dereference of a null reference. @@ -11871,7 +11878,7 @@ void Main(string? s) } static void ThrowIfNull([EnsuresNotNull] string? s, string? s2) => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. @@ -11892,7 +11899,7 @@ void Main(string? s) s.ToString(); // ok } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); @@ -11913,7 +11920,7 @@ void Main(string? s) } public int this[int x, [EnsuresNotNull] string? s] => throw null; } -", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", EnsuresNotNullAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -12000,7 +12007,7 @@ class CL2 public override bool Equals(object obj) { return false; } public override int GetHashCode() { return 0; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (16,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -12103,7 +12110,7 @@ class CL2 public override bool Equals(object obj) { return false; } public override int GetHashCode() { return 0; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (16,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -12178,7 +12185,7 @@ class CL1 { public bool M1() { return true; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -12248,7 +12255,7 @@ class CL1 public CL1 M1() { return new CL1(); } public string? M2() { return null; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (15,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -12302,7 +12309,7 @@ class CL1 public CL1? M2() { return null; } public void M3(CL1 x) { } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -12375,7 +12382,7 @@ class CL1 public CL1 M1() { return new CL1(); } public string? M2() { return null; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (15,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -12454,7 +12461,7 @@ class CL1 public CL1 M1() { return new CL1(); } public string? M2() { return null; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (15,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -12504,7 +12511,7 @@ class CL1 public bool P1 { get { return true;} } public bool P2 { get { return true;} } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Not tracking state of x?.P == expr // unless expr is `null`. See https://github.com/dotnet/roslyn/issues/26624. c.VerifyDiagnostics( @@ -12532,7 +12539,7 @@ void Test1(object x1, object? y1) y1.ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,21): hidden CS8607: Expression is probably never null. @@ -12559,7 +12566,7 @@ void Test1(object x1, object? y1) y1.ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,21): hidden CS8605: Result of the comparison is possibly always true. @@ -12586,7 +12593,7 @@ void Test1(object x1, object? y1) y1.ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,9): hidden CS8607: Expression is probably never null. @@ -12622,7 +12629,7 @@ void Test1(object x1, object? y1) y1.ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (13,13): hidden CS8606: Result of the comparison is possibly always false. @@ -12658,7 +12665,7 @@ void Test1(object x1, object? y1) y1.ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (13,13): hidden CS8605: Result of the comparison is possibly always true. @@ -12760,7 +12767,7 @@ void Test7(C? c7) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (17,13): warning CS8602: Possible dereference of a null reference. @@ -12829,7 +12836,7 @@ void Test(C? c1) object? this[int i] { get => null; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -12858,7 +12865,7 @@ void Test(T t) t.ToString(); // warn } } -}", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +}", NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (12,13): warning CS8602: Possible dereference of a null reference. @@ -12882,7 +12889,7 @@ void Test(C? c1, C? c2) c2.Prop.ToString(); // warn 1 2 } } -}", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +}", NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (10,13): warning CS8602: Possible dereference of a null reference. @@ -12908,7 +12915,7 @@ void Test(C? x, C? y) y.ToString(); // warn } } -}", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +}", NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -12935,7 +12942,7 @@ void Test(object? x) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,13): warning CS8602: Possible dereference of a null reference. @@ -12963,7 +12970,7 @@ class C : Base } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (13,13): warning CS8602: Possible dereference of a null reference. @@ -12990,7 +12997,7 @@ static void F(object? o) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,13): warning CS8602: Possible dereference of a null reference. @@ -13017,7 +13024,7 @@ class C } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,13): warning CS8602: Possible dereference of a null reference. @@ -13044,7 +13051,7 @@ class C } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,13): warning CS8602: Possible dereference of a null reference. @@ -13066,7 +13073,7 @@ static void F(T t, object? o) if (t != null) t.ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics(); } @@ -13082,7 +13089,7 @@ static void F(object? o) if (null is string) return; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (6,13): warning CS0184: The given expression is never of the provided ('string') type @@ -13109,7 +13116,7 @@ void Test(object? x) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. @@ -13136,7 +13143,7 @@ void Test(object? x) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,13): warning CS8602: Possible dereference of a null reference. @@ -13164,7 +13171,7 @@ void Test(object? x) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (13,13): warning CS8602: Possible dereference of a null reference. @@ -13192,7 +13199,7 @@ void Test(object? x) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. @@ -13216,7 +13223,7 @@ void Test(object? x) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (7,18): error CS0150: A constant value is expected @@ -13250,7 +13257,7 @@ void Test(object? x) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (8,22): hidden CS8606: Result of the comparison is possibly always false. @@ -13283,7 +13290,7 @@ void Test(object? x) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,17): warning CS8602: Possible dereference of a null reference. @@ -13311,7 +13318,7 @@ void Test(object? x) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (13,13): warning CS8602: Possible dereference of a null reference. @@ -13348,7 +13355,7 @@ void Test(object? x) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyTypes(); c.VerifyDiagnostics( @@ -13388,7 +13395,7 @@ void Test(object? x) } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyTypes(); c.VerifyDiagnostics( @@ -13414,7 +13421,7 @@ static void F(bool b, object x, object? y) v.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,9): warning CS8602: Possible dereference of a null reference. // z.ToString(); @@ -13441,7 +13448,7 @@ static void F(bool b, object x, object? y) if (y != null) (b ? y : x).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,10): warning CS8602: Possible dereference of a null reference. // (b ? x : y).ToString(); @@ -13465,7 +13472,7 @@ static void F(object x, object? y) (true ? y : x).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,10): warning CS8602: Possible dereference of a null reference. // (false ? x : y).ToString(); @@ -13492,7 +13499,7 @@ static void G(bool b, object? x, string y) (b ? y : x).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,10): warning CS8602: Possible dereference of a null reference. // (b ? x : y).ToString(); @@ -13533,7 +13540,7 @@ static void G(bool b, A x, B2 y) (b ? y : x)/*T:A!*/.P.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyTypes(); comp.VerifyDiagnostics( // (2,7): warning CS8618: Non-nullable property 'P' is uninitialized. @@ -13576,7 +13583,7 @@ static void F(bool b, object x, string? y) (b ? default: default).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,10): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between '' and '' // (b ? null: null).ToString(); @@ -13630,7 +13637,7 @@ static void F(bool b, Unknown x, Unknown? y) (b ? y: null).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (3,27): error CS0246: The type or namespace name 'Unknown' could not be found (are you missing a using directive or an assembly reference?) // static void F(bool b, Unknown x, Unknown? y) @@ -13641,15 +13648,9 @@ static void F(bool b, Unknown x, Unknown? y) // (5,10): warning CS8602: Possible dereference of a null reference. // (b ? null : x).ToString(); Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? null : x").WithLocation(5, 10), - // (6,10): warning CS8602: Possible dereference of a null reference. - // (b ? null : y).ToString(); - Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? null : y").WithLocation(6, 10), // (7,10): warning CS8602: Possible dereference of a null reference. // (b ? x: null).ToString(); - Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? x: null").WithLocation(7, 10), - // (8,10): warning CS8602: Possible dereference of a null reference. - // (b ? y: null).ToString(); - Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? y: null").WithLocation(8, 10)); + Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? x: null").WithLocation(7, 10)); } [Fact] @@ -13674,7 +13675,7 @@ static void F3(bool b, UnknownA? x, UnknownB? y) (b ? y : x).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (3,28): error CS0246: The type or namespace name 'UnknownA' could not be found (are you missing a using directive or an assembly reference?) // static void F1(bool b, UnknownA x, UnknownB y) @@ -13700,6 +13701,12 @@ static void F3(bool b, UnknownA? x, UnknownB? y) // (11,10): warning CS8602: Possible dereference of a null reference. // (b ? y : x).ToString(); Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? y : x").WithLocation(11, 10), + // (15,10): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'UnknownA?' and 'UnknownB?' + // (b ? x : y).ToString(); + Diagnostic(ErrorCode.ERR_InvalidQM, "b ? x : y").WithArguments("UnknownA?", "UnknownB?").WithLocation(15, 10), + // (16,10): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'UnknownB?' and 'UnknownA?' + // (b ? y : x).ToString(); + Diagnostic(ErrorCode.ERR_InvalidQM, "b ? y : x").WithArguments("UnknownB?", "UnknownA?").WithLocation(16, 10), // (15,10): warning CS8602: Possible dereference of a null reference. // (b ? x : y).ToString(); Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b ? x : y").WithLocation(15, 10), @@ -13732,7 +13739,7 @@ static void F3(bool b, B x, C? y) (b ? y : x).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,10): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'A' and 'B' // (b ? x : y).ToString(); @@ -13775,7 +13782,7 @@ static void F(bool b, object? x, object y) (b ? throw new Exception() : y).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,10): warning CS8602: Possible dereference of a null reference. // (b ? x : throw new Exception()).ToString(); @@ -13797,7 +13804,7 @@ static void F(bool b, object x) (b ? throw null : x).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -13813,7 +13820,7 @@ static void F(bool b) (b ? throw new Exception() : throw new Exception()).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,10): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between '' and '' // (b ? throw new Exception() : throw new Exception()).ToString(); @@ -13894,7 +13901,7 @@ static void F3(bool b1, bool b2, object v3) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (15,13): error CS0165: Use of unassigned local variable 'x1' // x1.ToString(); // unassigned (if) @@ -13985,7 +13992,7 @@ static void F4(bool b, ref IOut x4, ref IOut y4) (b ? ref y4 : ref y4)/*T:IOut!*/.P.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyTypes(); comp.VerifyDiagnostics( // (8,10): warning CS8602: Possible dereference of a null reference. @@ -14060,7 +14067,7 @@ static void F(bool c, IOut x, IOut y) b = true ? x : y; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,13): warning CS8626: No best nullability for operands of conditional expression 'I' and 'I'. // a = c ? x : y; @@ -14117,7 +14124,7 @@ static void F(object? x, object? y) v.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,9): warning CS8602: Possible dereference of a null reference. // z.ToString(); @@ -14140,7 +14147,7 @@ static void F(object? x, object? y) if (y != null) (y ?? x).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,10): warning CS8602: Possible dereference of a null reference. // (x ?? y).ToString(); @@ -14163,7 +14170,7 @@ static void F(object x, object? y) (null ?? y).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,10): error CS0019: Operator '??' cannot be applied to operands of type '' and '' // (null ?? null).ToString(); @@ -14188,7 +14195,7 @@ static void F(string x, string? y) ("""" ?? y).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -14218,7 +14225,7 @@ public class NotNull public A A = new A(); public B B = new B(); }"; - var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp1.VerifyDiagnostics(); var ref1 = comp1.EmitToImageReference(); @@ -14262,7 +14269,7 @@ static void F9(NotNull x9, NotNull y9) (x9.A ?? y9.B)/*T:!*/.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue }, references: new[] { ref0, ref1 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue }, references: new[] { ref0, ref1 }); comp.VerifyTypes(); comp.VerifyDiagnostics( // (5,10): error CS0019: Operator '??' cannot be applied to operands of type 'A' and 'B' @@ -14319,8 +14326,8 @@ static void F1(C x1, Unknown? y1) { (x1 ?? y1)/*T:!*/.ToString(); (y1 ?? x1)/*T:!*/.ToString(); - (null ?? y1)/*T:?*/.ToString(); - (y1 ?? null)/*T:?*/.ToString(); + (null ?? y1)/*T:Unknown?*/.ToString(); + (y1 ?? null)/*T:Unknown?*/.ToString(); } static void F2(C? x2, Unknown y2) { @@ -14330,8 +14337,9 @@ static void F2(C? x2, Unknown y2) (y2 ?? null)/*T:!*/.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyTypes(); + // Note: Unknown type is treated as a value type comp.VerifyDiagnostics( // (3,26): error CS0246: The type or namespace name 'Unknown' could not be found (are you missing a using directive or an assembly reference?) // static void F1(C x1, Unknown? y1) @@ -14339,14 +14347,17 @@ static void F2(C? x2, Unknown y2) // (10,27): error CS0246: The type or namespace name 'Unknown' could not be found (are you missing a using directive or an assembly reference?) // static void F2(C? x2, Unknown y2) Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Unknown").WithArguments("Unknown").WithLocation(10, 27), + // (5,10): error CS0019: Operator '??' cannot be applied to operands of type 'C' and 'Unknown?' + // (x1 ?? y1)/*T:!*/.ToString(); + Diagnostic(ErrorCode.ERR_BadBinaryOps, "x1 ?? y1").WithArguments("??", "C", "Unknown?").WithLocation(5, 10), + // (6,10): error CS0019: Operator '??' cannot be applied to operands of type 'Unknown?' and 'C' + // (y1 ?? x1)/*T:!*/.ToString(); + Diagnostic(ErrorCode.ERR_BadBinaryOps, "y1 ?? x1").WithArguments("??", "Unknown?", "C").WithLocation(6, 10), // (5,10): hidden CS8607: Expression is probably never null. // (x1 ?? y1)/*T:!*/.ToString(); Diagnostic(ErrorCode.HDN_ExpressionIsProbablyNeverNull, "x1").WithLocation(5, 10), - // (7,10): warning CS8602: Possible dereference of a null reference. - // (null ?? y1)/*T:Unknown?*/.ToString(); - Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "null ?? y1").WithLocation(7, 10), // (8,10): warning CS8602: Possible dereference of a null reference. - // (y1 ?? null)/*T:?*/.ToString(); + // (y1 ?? null)/*T:Unknown?*/.ToString(); Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "y1 ?? null").WithLocation(8, 10), // (13,10): hidden CS8607: Expression is probably never null. // (y2 ?? x2)/*T:!*/.ToString(); @@ -14378,7 +14389,7 @@ static void F(object? o, object[]? a, object?[]? b) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. // (a ?? c)[0].ToString(); @@ -14407,7 +14418,7 @@ static object F((I, I)? x, (I, I) y) return x ?? y; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,21): warning CS8619: Nullability of reference types in value of type '(I, I)?' doesn't match target type '(I, I)?'. // return x ?? y; @@ -14466,7 +14477,7 @@ static void F7(IOut? x7, IOut y7) z7 = x7 ?? (IOut)y7; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,30): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. // I z1 = x1 ?? y1; @@ -14555,7 +14566,7 @@ static void F4(object? x4, object? y4) FOut((FOut(x4) ?? FOut(y4))/*T:IOut?*/).ToString(); // D } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyTypes(); comp.VerifyDiagnostics( // (22,14): warning CS8620: Nullability of reference types in argument of type 'IIn' doesn't match target type 'IIn' for parameter 'x' in 'void C.FIn(IIn? x)'. @@ -14605,7 +14616,7 @@ static void G((object, object)? x, (object?, object?) y) (x ?? y).Item1.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,9): warning CS8602: Possible dereference of a null reference. // (x ?? y).Item1.ToString(); @@ -14657,7 +14668,7 @@ static void F6(A? x6, B? y6) (y6 ?? x6)/*T:B?*/.Value.F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyTypes(); comp.VerifyDiagnostics( // (14,10): warning CS8619: Nullability of reference types in value of type 'A' doesn't match target type 'B'. @@ -14742,7 +14753,7 @@ static void F6(A? x6, B? y6) (y6 ?? x6)/*T:B*/.F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyTypes(); comp.VerifyDiagnostics( // (6,7): warning CS8618: Non-nullable field 'F' is uninitialized. @@ -14808,7 +14819,7 @@ static void F1(object? x, dynamic? y, dynamic z) (z ?? y).ToString(); } }"; - var comp = CreateCompilationWithMscorlib40AndSystemCore(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilationWithMscorlib40AndSystemCore(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,10): warning CS8602: Possible dereference of a null reference. // (x ?? y).ToString(); @@ -14848,7 +14859,7 @@ public class NotNull public object Object = new object(); public string String = string.Empty; }"; - var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp1.VerifyDiagnostics(); var ref1 = comp1.EmitToImageReference(); @@ -14901,7 +14912,7 @@ static void F9(NotNull x9, NotNull y9) (y9.String ?? x9.Object)/*T:object!*/.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue }, references: new[] { ref0, ref1 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue }, references: new[] { ref0, ref1 }); comp.VerifyTypes(); comp.VerifyDiagnostics( // (10,10): warning CS8602: Possible dereference of a null reference. @@ -14961,7 +14972,7 @@ static void G(A z, B? w) (w ?? z).F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (2,7): warning CS8618: Non-nullable field 'F' is uninitialized. // class A @@ -15015,7 +15026,7 @@ static void G(IIn z, IIn? w) (w ?? z)/*T:IIn!*/.F(string.Empty, null); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyTypes(); comp.VerifyDiagnostics( // (9,10): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn'. @@ -15061,7 +15072,7 @@ static void G(IOut z, IOut? w) (w ?? z)/*T:IOut!*/.P.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyTypes(); comp.VerifyDiagnostics( // (9,15): warning CS8619: Nullability of reference types in value of type 'IOut' doesn't match target type 'IOut'. @@ -15133,7 +15144,7 @@ class CL1 public void M1() { } public void M2(CL1 x) { } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (15,13): warning CS8602: Possible dereference of a null reference. @@ -15197,7 +15208,7 @@ void Test2(CL1? x2, CL1 y2, CL1? z2) class CL1 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (11,13): hidden CS8606: Result of the comparison is possibly always false. @@ -15252,7 +15263,7 @@ static object F3(B b3, object? o, A a) return b3.G; } }"; - var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { comp0.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { comp0.EmitToImageReference() }); comp1.VerifyDiagnostics( // (9,20): warning CS8601: Possible null reference assignment. // b1.G = o; @@ -15310,7 +15321,7 @@ static object F3(A a3, object? o, A a) return a3.F; } }"; - var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { comp0.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { comp0.EmitToImageReference() }); comp1.VerifyDiagnostics( // (10,16): warning CS8603: Possible null reference return. // return a1.F; @@ -15347,7 +15358,7 @@ static void Main() class CL1 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -15434,7 +15445,7 @@ static void F(string? s) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,9): warning CS8602: Possible dereference of a null reference. // t.ToString(); @@ -15462,7 +15473,7 @@ static void F(string? s) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,9): error CS0841: Cannot use local variable 't' before it is declared // t = null; @@ -15497,7 +15508,7 @@ static void F(string? s) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (11,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // t = null; @@ -15532,7 +15543,7 @@ static void F(int n) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. // t.ToString(); @@ -15564,7 +15575,7 @@ static void F(int n, string? s) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. // t.ToString(); @@ -15597,7 +15608,7 @@ static void F(int n) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. // t.ToString(); @@ -15631,7 +15642,7 @@ static void F(int n) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. // t.ToString(); @@ -15659,7 +15670,7 @@ static void F(string? s) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // t = null; @@ -15848,7 +15859,7 @@ void Test7(CL1 y7, CL1? z7) class CL1 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (11,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -15913,7 +15924,7 @@ void Test4(CL1 y4, CL1? z4) class CL1 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (37,17): warning CS8601: Possible null reference assignment. @@ -15949,7 +15960,7 @@ void Test2() var z1 = u1?[u1[0]]; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,18): warning CS8602: Possible dereference of a null reference. @@ -16034,7 +16045,7 @@ void Test19(CL1 y19, CL1? z19) class CL1 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (13,14): warning CS8619: Nullability of reference types in value of type 'CL1?[]' doesn't match target type 'CL1[]'. @@ -16081,7 +16092,7 @@ void Test2() var z2 = u2.Length; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (18,18): warning CS8602: Possible dereference of a null reference. @@ -16203,7 +16214,7 @@ void Test9() u9[0][0,0].ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (11,14): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -16343,7 +16354,7 @@ void Test9() u9[0][0,0].ToString(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (16,54): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. @@ -16419,7 +16430,7 @@ void Test1(CL0 x1, CL0 y1) class CL0 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,31): warning CS8619: Nullability of reference types in value of type 'CL0' doesn't match target type 'CL0'. @@ -16456,7 +16467,7 @@ static void F(object x, object? y) c[0][0].ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,9): warning CS8602: Possible dereference of a null reference. // b[0].ToString(); @@ -16489,7 +16500,7 @@ static void F(object[] a, object?[] b) e[0][0].ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. // b[0].ToString(); @@ -16517,7 +16528,7 @@ static void F(object x, object? y) (new[] { y, x })[1].ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,9): warning CS8602: Possible dereference of a null reference. // (new[] { y, x })[1].ToString(); @@ -16539,7 +16550,7 @@ static void F() b[0][0].ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -16562,7 +16573,7 @@ static void F(int n) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,13): warning CS8602: Possible dereference of a null reference. // a[0].ToString(); @@ -16594,7 +16605,7 @@ static void F(string s) f[0].ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,39): warning CS8600: Converting null literal or possible null value to non-nullable type. // var a = new[] { new object(), (string)null }; @@ -16647,7 +16658,7 @@ static void F() d[0].F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (2,7): warning CS8618: Non-nullable field 'F' is uninitialized. // class A @@ -16700,7 +16711,7 @@ static void F(C? a, C b) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,32): warning CS8619: Nullability of reference types in value of type 'C' doesn't match target type 'C'. // var c = new[] { a, b }; @@ -16737,7 +16748,7 @@ static void G(C? x2, Unknown y2) b2[0].ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,26): error CS0246: The type or namespace name 'Unknown' could not be found (are you missing a using directive or an assembly reference?) // static void G(C? x2, Unknown y2) @@ -16745,12 +16756,18 @@ static void G(C? x2, Unknown y2) // (3,25): error CS0246: The type or namespace name 'Unknown' could not be found (are you missing a using directive or an assembly reference?) // static void F(C x1, Unknown? y1) Diagnostic(ErrorCode.ERR_SingleTypeNameNotFound, "Unknown").WithArguments("Unknown").WithLocation(3, 25), - // (6,9): warning CS8602: Possible dereference of a null reference. - // a1[0].ToString(); - Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "a1[0]").WithLocation(6, 9), - // (8,9): warning CS8602: Possible dereference of a null reference. - // b1[0].ToString(); - Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "b1[0]").WithLocation(8, 9), + // (5,18): error CS0826: No best type found for implicitly-typed array + // var a1 = new[] { x1, y1 }; + Diagnostic(ErrorCode.ERR_ImplicitlyTypedArrayNoBestType, "new[] { x1, y1 }").WithLocation(5, 18), + // (7,18): error CS0826: No best type found for implicitly-typed array + // var b1 = new[] { y1, x1 }; + Diagnostic(ErrorCode.ERR_ImplicitlyTypedArrayNoBestType, "new[] { y1, x1 }").WithLocation(7, 18), + // (5,30): warning CS8601: Possible null reference assignment. + // var a1 = new[] { x1, y1 }; + Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "y1").WithLocation(5, 30), + // (7,26): warning CS8601: Possible null reference assignment. + // var b1 = new[] { y1, x1 }; + Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "y1").WithLocation(7, 26), // (12,26): warning CS8601: Possible null reference assignment. // var a2 = new[] { x2, y2 }; Diagnostic(ErrorCode.WRN_NullReferenceAssignment, "x2").WithLocation(12, 26), @@ -16775,7 +16792,7 @@ static void F(object x, object? y) c[0].ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,35): warning CS8601: Possible null reference assignment. // var a = new object[] { x, y }; @@ -16822,7 +16839,7 @@ static void F(IOut x, IOut y, IOut? z, IOut? w (new[] { w, z })[0].ToString(); // C6 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,21): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. // (new[] { x, y })[0].ToString(); // A1 @@ -16919,7 +16936,7 @@ static void F(A z, B w) (new[] { z!, w! })[0].F.ToString(); // 11 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyTypes(); comp.VerifyDiagnostics( // (6,9): warning CS8602: Possible dereference of a null reference. @@ -16988,7 +17005,7 @@ static void F(IOut? x, IOut? y) IOut[] d = new[] { x }; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,27): warning CS8619: Nullability of reference types in value of type 'I?[]' doesn't match target type 'I?[]'. // I?[] a = new[] { x }; @@ -17036,7 +17053,7 @@ static void F(A x, B y) var w = new A[] { x, y }; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,38): warning CS8619: Nullability of reference types in value of type 'B' doesn't match target type 'A'. // var z = new A[] { x, y }; @@ -17065,7 +17082,7 @@ static void F(IOut x, IOut y) var b = new IOut[] { y }; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,38): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn'. // var a = new IIn[] { x }; @@ -17094,7 +17111,7 @@ static void F(B x, C? y) (new[] { y, x })[0].ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (12,9): warning CS8602: Possible dereference of a null reference. // (new[] { x, y })[0].ToString(); @@ -17139,7 +17156,7 @@ class CL1 public CL1 P1 {get; set;} public CL1? P2 {get; set;} } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,35): warning CS8601: Possible null reference assignment. @@ -17164,7 +17181,7 @@ static void F(object? x) if (x != null) y = new C(x); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,23): warning CS8604: Possible null reference argument for parameter 'o' in 'C.C(object o)'. // var y = new C(x); @@ -17191,7 +17208,7 @@ static void Main() o.F.G.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -17222,7 +17239,7 @@ static object G(C c, I x, I y) set { } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,16): warning CS8620: Nullability of reference types in argument of type 'I' doesn't match target type 'I' for parameter 'y' in 'int C.this[I x, I y]'. // y: y, // warn 1 @@ -17250,7 +17267,7 @@ static void M(B? x, B y) }; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should report WRN_NullabilityMismatchInArgument for `y`. comp.VerifyDiagnostics( // (10,13): warning CS8604: Possible null reference argument for parameter 'item' in 'void List>.Add(A item)'. @@ -17324,7 +17341,7 @@ struct S2 { public S1 F2; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,14): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -17447,7 +17464,7 @@ struct S1 public CL1? F1; public CL1? F3; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (11,17): error CS0165: Use of unassigned local variable 'y1' @@ -17527,7 +17544,7 @@ struct S2 S2(CL1 x) { F2 = x; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,14): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -17568,7 +17585,7 @@ void Dummy() E2 = null; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (15,28): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -17692,7 +17709,7 @@ struct S1 public CL1? p1; public CL1? p2; }", -NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Why isn't u2 = v2 causing a warning? c.VerifyDiagnostics( @@ -17821,7 +17838,7 @@ class CL1 { public CL1? M1(CL1 x) { return null; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (25,29): error CS0269: Use of unassigned out parameter 'x3' @@ -17853,7 +17870,7 @@ void Test3(CL1 x3) class CL1 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (14,14): hidden CS8607: Expression is probably never null. @@ -17884,7 +17901,7 @@ void Test1(CL1 x1, CL1 y1) class CL1 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,14): warning CS8619: Nullability of reference types in value of type ' F1>' doesn't match target type ' F1>'. @@ -17934,7 +17951,7 @@ static void F3(IOut x3, IOut y3) b3 = a3; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should report a warning for `a0 = b0`. // PROTOTYPE(NullableReferenceTypes): Should not report a warning for `b3 = a3`. comp.VerifyDiagnostics( @@ -17970,7 +17987,7 @@ static void F(string x, string y) y = new { x, y = y }.y ?? y; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should report ErrorCode.HDN_ExpressionIsProbablyNeverNull. // See comment in DataFlowPass.VisitAnonymousObjectCreationExpression. comp.VerifyDiagnostics(); @@ -17989,7 +18006,7 @@ static void F(object? o) (new { Q = o }).Q.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,9): warning CS8602: Possible dereference of a null reference. // (new { P = o }).P.ToString(); @@ -18011,7 +18028,7 @@ static void F(object? o) (new { Q = new[] { o }}).Q[0].ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,9): warning CS8602: Possible dereference of a null reference. // (new { P = new[] { o }}).P[0].ToString(); @@ -18037,7 +18054,7 @@ void Test2() this?.Test1(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (14,9): hidden CS8607: Expression is probably never null. @@ -18114,7 +18131,7 @@ struct S1 { public C0? F1; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (22,14): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -18198,7 +18215,7 @@ struct S1 { public C0? F1; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,14): warning CS8601: Possible null reference assignment. @@ -18254,7 +18271,7 @@ void Test2(object? x2, out CL1? y2) class CL1 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (17,18): error CS0165: Use of unassigned local variable 'y1' @@ -18303,7 +18320,7 @@ void Test4() class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -18336,7 +18353,7 @@ void Test3() class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -18379,7 +18396,7 @@ void Test4() class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,37): warning CS8603: Possible null reference return. @@ -18424,7 +18441,7 @@ void Test3() class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,46): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -18479,7 +18496,7 @@ void Test4(int x4) class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (20,22): warning CS8603: Possible null reference return. @@ -18540,7 +18557,7 @@ void Test4(int x4) class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -18588,7 +18605,7 @@ void Test4(int x4) class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (19,22): warning CS8603: Possible null reference return. @@ -18648,7 +18665,7 @@ void Test4(int x4) class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -18694,7 +18711,7 @@ void Test2(int x2) class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (21,26): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -18752,7 +18769,7 @@ void Test2(int x2) class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (22,28): warning CS8603: Possible null reference return. @@ -18801,7 +18818,7 @@ void Test4() class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,50): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -18856,7 +18873,7 @@ void Test4() class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,51): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -18923,7 +18940,7 @@ void Test4() class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,33): warning CS8622: Nullability of reference types in type of parameter 'p1' of 'lambda expression' doesn't match the target delegate 'Action'. @@ -18978,7 +18995,7 @@ void Test4() class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -19029,7 +19046,7 @@ static void Test2() }; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { notAnnotated.EmitToImageReference() }); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { notAnnotated.EmitToImageReference() }); c.VerifyDiagnostics( // (20,29): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. @@ -19067,7 +19084,7 @@ void Test2() class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,42): warning CS8622: Nullability of reference types in type of parameter 'p1' of 'lambda expression' doesn't match the target delegate 'Action>'. @@ -19104,7 +19121,7 @@ void Test2() class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,54): warning CS8622: Nullability of reference types in type of parameter 'p1' of 'lambda expression' doesn't match the target delegate 'Action>'. @@ -19137,7 +19154,7 @@ static void F() }); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,22): warning CS8600: Converting null literal or possible null value to non-nullable type. // s1 = null; @@ -19196,7 +19213,7 @@ static void F3(object? x3, object y3) }"; // PROTOTYPE(NullableReferenceTypes): For captured variables, the lambda should be // considered executed at the location the lambda is converted to a delegate. - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,18): warning CS8600: Converting null literal or possible null value to non-nullable type. // z1 = x1; // warning @@ -19228,7 +19245,7 @@ static void G(string x, object? y) F(() => { if (y == null) return x; return y; }); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,56): warning CS8603: Possible null reference return. // F(() => { if ((object)x == y) return x; return y; }); @@ -19256,7 +19273,7 @@ static void H(bool b, object? x, string y) F(() => { if (b) return y; return x; }); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,43): warning CS8603: Possible null reference return. // F(() => { if (b) return x; return y; }); @@ -19292,7 +19309,7 @@ static void H(bool b, object? x, string y) F(() => { if (b) return x; return y; }).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,9): warning CS8602: Possible dereference of a null reference. // F(() => { if (b) return x; return y; }).ToString(); @@ -19323,7 +19340,7 @@ static void G(object? o) }"; // PROTOTYPE(NullableReferenceTypes): For captured variables, the lambda should be // considered executed at the location the lambda is converted to a delegate. - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,9): warning CS8602: Possible dereference of a null reference. // F(() => o).ToString(); @@ -19355,7 +19372,7 @@ static void G() F(o => { if (o == null) throw new ArgumentException(); return o; }).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -19375,7 +19392,7 @@ static void M(object? x) F(y => F(z => z, y), x).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,9): warning CS8602: Possible dereference of a null reference. // F(y => F(z => z, y), x).ToString(); @@ -19398,7 +19415,7 @@ static void G(object? x) if (x != null) F(x, y => F(y, z => { y.ToString(); z.ToString(); })); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,31): warning CS8602: Possible dereference of a null reference. // F(x, y => F(y, z => { y.ToString(); z.ToString(); })); @@ -19434,7 +19451,7 @@ static void F(I x, I y) }"; // PROTOTYPE(NullableReferenceTypes): For captured variables, the lambda should be // considered executed at the location the lambda is converted to a delegate. - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,29): warning CS8603: Possible null reference return. // D b = () => y; @@ -19469,7 +19486,7 @@ static void F() D> d = (I o) => { }; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,24): warning CS8622: Nullability of reference types in type of parameter 'o' of 'lambda expression' doesn't match the target delegate 'D'. // D a = (object o) => { }; @@ -19578,7 +19595,7 @@ static void F() var y = x => x; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,13): error CS0815: Cannot assign lambda expression to an implicitly-typed variable // var y = x => x; @@ -19597,7 +19614,7 @@ static void F(object? x) } }"; // PROTOTYPE(NullableReferenceTypes): Should not report HDN_ExpressionIsProbablyNeverNull for `y`. - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,13): error CS0815: Cannot assign lambda expression to an implicitly-typed variable // var z = y => y ?? x.ToString(); @@ -19658,7 +19675,7 @@ static void F4(object? x4) object? f() => x4; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should report warnings as indicated in source above. comp.VerifyDiagnostics( // (10,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -19727,7 +19744,7 @@ void f4(object? x4) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should report warnings for `y3.ToString()`. comp.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. @@ -19784,7 +19801,7 @@ static void F4() where T4 : new() x5 = (new T5?[1])[0]; // error 16 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,14): error CS8630: Cannot use a nullable reference type in object creation. // x1 = new object?(); // error 1 @@ -19853,7 +19870,7 @@ void Test2(T2 x2) where T2 : class, new() x2 = new T2() ?? x2; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (14,14): hidden CS8607: Expression is probably never null. @@ -19882,7 +19899,7 @@ static void G() where U : class, new() F2(y); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -19911,7 +19928,7 @@ class CL0 public CL0(int x) {} public CL0(long x) {} } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (14,14): hidden CS8607: Expression is probably never null. @@ -19935,7 +19952,7 @@ static void G(object? x, dynamic y) if (x != null) o = new C(y, x); } }"; - var comp = CreateCompilationWithMscorlib40AndSystemCore(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilationWithMscorlib40AndSystemCore(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): We should be able to report warnings // when all applicable methods agree on the nullability of particular parameters. // (For instance, x in F(x, y) above.) @@ -19960,7 +19977,7 @@ static void M(dynamic d) o.G.ToString(); } }"; - var comp = CreateCompilationWithMscorlib40AndSystemCore(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilationWithMscorlib40AndSystemCore(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -19998,7 +20015,7 @@ class CL0 set { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (14,14): hidden CS8607: Expression is probably never null. @@ -20041,7 +20058,7 @@ class CL0 set { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,22): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -20084,7 +20101,7 @@ class CL0 set { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,22): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -20127,7 +20144,7 @@ class CL0 set { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,22): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -20170,7 +20187,7 @@ class CL0 set { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (14,14): hidden CS8607: Expression is probably never null. @@ -20213,7 +20230,7 @@ class CL0 set { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (14,14): hidden CS8607: Expression is probably never null. @@ -20241,7 +20258,7 @@ void Test2(dynamic x2) x2 = x2[0] ?? x2; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -20281,7 +20298,7 @@ class CL0 set { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (22,22): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. @@ -20334,7 +20351,7 @@ class CL1 set { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (14,26): warning CS8601: Possible null reference assignment. @@ -20380,7 +20397,7 @@ class CL0 set { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,14): warning CS8602: Possible dereference of a null reference. @@ -20424,7 +20441,7 @@ public CL0 M1(long x) return new CL0(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (14,14): hidden CS8607: Expression is probably never null. @@ -20465,7 +20482,7 @@ public CL0 M1(long x) return new CL0(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,22): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -20506,7 +20523,7 @@ public CL0 M1(int x) return new CL0(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,22): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -20547,7 +20564,7 @@ class CL0 return new CL0(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,22): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -20588,7 +20605,7 @@ public int M1(long x) return (int)x; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (14,14): hidden CS8607: Expression is probably never null. @@ -20629,7 +20646,7 @@ public long M1(long x) return x; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (14,14): hidden CS8607: Expression is probably never null. @@ -20657,7 +20674,7 @@ void Test2(dynamic x2) x2 = x2.M1(0) ?? x2; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -20694,7 +20711,7 @@ public long M1(long x) return x; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (22,16): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. @@ -20735,7 +20752,7 @@ public CL0 M1(long x) return new CL0(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (9,14): warning CS8602: Possible dereference of a null reference. @@ -20771,7 +20788,7 @@ void Test3(dynamic? x3) dynamic y3 = x3.M1; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (19,22): warning CS8602: Possible dereference of a null reference. @@ -20794,7 +20811,7 @@ static void M(dynamic x) y = null; } }"; - var comp = CreateCompilationWithMscorlib40AndSystemCore(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilationWithMscorlib40AndSystemCore(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); comp.VerifyTypes(); } @@ -20831,7 +20848,7 @@ public CL0(long x) { } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (16,18): hidden CS8607: Expression is probably never null. @@ -20855,7 +20872,7 @@ static void G(object? x, dynamic y) if (x != null) F(y, x); } }"; - var comp = CreateCompilationWithMscorlib40AndSystemCore(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilationWithMscorlib40AndSystemCore(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): We should be able to report warnings // when all applicable methods agree on the nullability of particular parameters. // (For instance, x in F(x, y) above.) @@ -20883,7 +20900,7 @@ void Test2(string x2, string? y2) x2 = z2 ?? x2; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (16,14): hidden CS8607: Expression is probably never null. @@ -20912,7 +20929,7 @@ void Test2(string x2, string? y2) x2 = $""{y2}"" ?? x2; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (15,14): hidden CS8607: Expression is probably never null. @@ -20941,7 +20958,7 @@ void Test2(System.Action x2) x2 = new System.Action(Main) ?? x2; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (15,14): hidden CS8607: Expression is probably never null. @@ -20980,7 +20997,7 @@ void Test2() } class CL0{} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -21009,7 +21026,7 @@ static void G() D> h = F>; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,23): warning CS8621: Nullability of reference types in return type of 'object? C.F()' doesn't match the target delegate 'D'. // D a = F; @@ -21051,7 +21068,7 @@ static void G() D> h = F>; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (11,24): warning CS8622: Nullability of reference types in type of parameter 't' of 'void C.F(object t)' doesn't match the target delegate 'D'. // D b = F; @@ -21095,7 +21112,7 @@ static void G(object? o) e = (D)y.M; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should report WRN_NullabilityMismatchInReturnTypeOfTargetDelegate for `e = x.M`. comp.VerifyDiagnostics(); } @@ -21123,7 +21140,7 @@ static void G() D> h = F>; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should not warn for `b`, `e`, `h`. comp.VerifyDiagnostics( // (7,37): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. @@ -21178,7 +21195,7 @@ static void G() D> h = F>; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,23): warning CS8622: Nullability of reference types in type of parameter 't' of 'void C.F(ref object? t)' doesn't match the target delegate 'D'. // D a = F; @@ -21226,7 +21243,7 @@ public override void Test() base.Test(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -21252,7 +21269,7 @@ void Test2(System.Type x2) x2 = typeof(C) ?? x2; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (15,14): hidden CS8607: Expression is probably never null. @@ -21281,7 +21298,7 @@ void M() _ = typeof(List); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): should nullable reference types be disallowed in `typeof`? c.VerifyDiagnostics(); @@ -21302,7 +21319,7 @@ void Test1(C x1) x1 = default(C); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,14): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -21662,7 +21679,7 @@ static void G(C c) (x, y) = c; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Assign each of the deconstructed values. // PROTOTYPE(NullableReferenceTypes): The expected warning is confusing: "warning CS8619: Nullability of // reference types in value of type 'C' doesn't match target type '(IIn x, IOut y)'". @@ -21690,7 +21707,7 @@ static void M() y = null; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Deconstruction should infer `string?` for `var x`. comp.VerifyDiagnostics( // (8,13): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -21717,7 +21734,7 @@ static void G() y = null; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Deconstruction should infer `string?` for `var x`. comp.VerifyDiagnostics( // (9,13): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -21748,7 +21765,7 @@ static void M() y = null; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Deconstruction should infer `string?` for `var x`. comp.VerifyDiagnostics( // (13,13): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -21777,7 +21794,7 @@ static void G() t.y = null; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,9): warning CS8602: Possible dereference of a null reference. // t.y.ToString(); @@ -21805,7 +21822,7 @@ static void G() } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Deconstruction should infer `string?` for `var y`. comp.VerifyDiagnostics(); //// (11,13): warning CS8602: Possible dereference of a null reference. @@ -21827,7 +21844,7 @@ static void F((object, object?) t) } }"; // PROTOTYPE(NullableReferenceTypes): Should report WRN_NullReferenceReceiver. - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); //// (7,9): warning CS8602: Possible dereference of a null reference. //// ((x, _) = t).Item2.ToString(); @@ -21854,7 +21871,7 @@ void Test2(string? x2, string? y2) string z2 = x2 + y2 ?? """"; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (15,21): hidden CS8607: Expression is probably never null. @@ -21883,7 +21900,7 @@ void Test2(dynamic? x2, dynamic? y2) dynamic z2 = x2 + y2 ?? """"; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -21952,7 +21969,7 @@ class CL2 return y; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,24): warning CS8604: Possible null reference argument for parameter 'y' in 'CL0 CL0.operator +(string? x, CL0 y)'. @@ -22016,7 +22033,7 @@ class CL0 return false; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,19): warning CS8604: Possible null reference argument for parameter 'x' in 'bool CL0.operator false(CL0 x)'. @@ -22064,7 +22081,7 @@ class CL0 return false; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,19): warning CS8604: Possible null reference argument for parameter 'x' in 'bool CL0.operator false(CL0 x)'. @@ -22109,7 +22126,7 @@ class CL0 return false; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -22148,7 +22165,7 @@ class CL0 return false; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,19): warning CS8604: Possible null reference argument for parameter 'x' in 'bool CL0.operator true(CL0 x)'. @@ -22190,7 +22207,7 @@ class CL0 return false; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -22234,7 +22251,7 @@ class CL0 return false; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,19): warning CS8604: Possible null reference argument for parameter 'x' in 'bool CL0.operator true(CL0 x)'. @@ -22289,7 +22306,7 @@ class CL0 return false; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -22345,7 +22362,7 @@ void Test8(System.Action x8, System.Action y8) System.Action u8 = x8 - y8; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (15,28): hidden CS8607: Expression is probably never null. @@ -22409,7 +22426,7 @@ class CL0 return null; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,25): warning CS8604: Possible null reference argument for parameter 'y' in 'CL0 CL0.operator &(CL0? x, CL0 y)'. @@ -22451,7 +22468,7 @@ class CL0 return false; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -22485,7 +22502,7 @@ static void Or(S x, S? y) if (y || y) { } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -22505,7 +22522,7 @@ static void F(S x, S? y) s = y + y; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -22539,7 +22556,7 @@ static void F(S x, S? y) if (y != x) { } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -22568,7 +22585,7 @@ class CL0 { public void M1() {} } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,28): warning CS8602: Possible dereference of a null reference. @@ -22613,7 +22630,7 @@ void Test4() class CL0 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,37): warning CS8622: Nullability of reference types in type of parameter 'x' of 'void C.M1(string x)' doesn't match the target delegate 'Action'. @@ -22664,7 +22681,7 @@ void Test4() class CL0 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -22706,7 +22723,7 @@ void Test4() class CL0 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (17,34): warning CS8621: Nullability of reference types in return type of 'string? C.M1()' doesn't match the target delegate 'Func'. @@ -22757,7 +22774,7 @@ void Test4() class CL0 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -22785,7 +22802,7 @@ static void G(A x, A? y) d = Create(x).F; // warning } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Report conversion warnings. comp.VerifyDiagnostics( // (15,13): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -22854,7 +22871,7 @@ class CL2 return new CL2(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,19): warning CS8604: Possible null reference argument for parameter 'x' in 'CL0 CL0.operator !(CL0 x)'. @@ -22878,7 +22895,7 @@ static void F(S? s) s = ~s; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -22994,7 +23011,7 @@ class CL1 {} class CL2 {} class CL3 {} class CL4 : CL3 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,18): warning CS8604: Possible null reference argument for parameter 'x' in 'CL0.implicit operator CL1(CL0 x)'. @@ -23071,7 +23088,7 @@ void Test1(CL0 x1) class CL0 { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,26): warning CS8619: Nullability of reference types in value of type 'CL0' doesn't match target type 'CL0'. @@ -23107,7 +23124,7 @@ static void F3(B? x3) y3 = x3!; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,25): warning CS8619: Nullability of reference types in value of type 'B' doesn't match target type 'A'. // A y1 = x1; @@ -23172,7 +23189,7 @@ static void F3(IB? x3) y3 = x3!; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,26): warning CS8619: Nullability of reference types in value of type 'IB' doesn't match target type 'IA'. // IA y1 = x1; @@ -23225,7 +23242,7 @@ static void G(IOut x) IOut y = x; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,26): warning CS8619: Nullability of reference types in value of type 'IOut' doesn't match target type 'IOut'. // IOut y = x; @@ -23248,7 +23265,7 @@ static void G(IIn x) IIn y = x; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,26): warning CS8619: Nullability of reference types in value of type 'IIn' doesn't match target type 'IIn'. // IIn y = x; @@ -23272,7 +23289,7 @@ static void G(A x) IOut y = x; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (11,26): warning CS8619: Nullability of reference types in value of type 'A' doesn't match target type 'IOut'. // IOut y = x; @@ -23304,7 +23321,7 @@ static void G(A a2, B b2) z = b2; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Report the base types that did not match // rather than the derived or implementing type. For instance, report `'IIn' // doesn't match ... 'IIn'` rather than `'A' doesn't match ...`. @@ -23347,7 +23364,7 @@ static void Main(object? x) G(z); // ok } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Several issues with implicit user-defined conversions and // nested nullability: should report `'A' doesn't match ... 'A'` rather than // `'A' doesn't match ... 'A'`; should report warning for `G(y)` only, not `G(z)`; and @@ -23387,7 +23404,7 @@ static void F2(I x2, IIn y2, IOut z2, IBoth d2 = w2; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,25): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. // I a1 = x1; @@ -23442,7 +23459,7 @@ static void F2(I x2, IIn y2, IOut z2, IBoth' doesn't match target type 'I'. // a1 = x1; @@ -23482,7 +23499,7 @@ static void G(I x, IIn y, IOut z) F(x, y, z); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,11): warning CS8620: Nullability of reference types in argument of type 'I' doesn't match target type 'I' for parameter 'x' in 'void C.G(I x, IIn y, IOut z)'. // G(x, y, z); @@ -23516,7 +23533,7 @@ static void G(out I x, out IIn y, out IOut z) F(out x, out y, out z); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,15): warning CS8620: Nullability of reference types in argument of type 'I' doesn't match target type 'I' for parameter 'x' in 'void C.G(out I x, out IIn y, out IOut z)'. // G(out x, out y, out z); @@ -23550,7 +23567,7 @@ static void G(ref I x, ref IIn y, ref IOut z) F(ref x, ref y, ref z); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,15): warning CS8620: Nullability of reference types in argument of type 'I' doesn't match target type 'I' for parameter 'x' in 'void C.G(ref I x, ref IIn y, ref IOut z)'. // G(ref x, ref y, ref z); @@ -23590,7 +23607,7 @@ static void G(in I x, in IIn y, in IOut z) F(in x, in y, in z); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,14): warning CS8620: Nullability of reference types in argument of type 'I' doesn't match target type 'I' for parameter 'x' in 'void C.G(in I x, in IIn y, in IOut z)'. // G(in x, in y, in z); @@ -23640,7 +23657,7 @@ static void G(A z, A w) F2(w!, w).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (12,9): warning CS8602: Possible dereference of a null reference. // F1(x, x!).ToString(); @@ -23677,7 +23694,7 @@ static object G(C c, I x, I y) } object this[I x, I y] => new object(); }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,16): warning CS8620: Nullability of reference types in argument of type 'I' doesn't match target type 'I' for parameter 'y' in 'object C.this[I x, I y]'. // y: y, // warn 1 @@ -23751,7 +23768,7 @@ class CL1 return new CL1(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullReferenceTypes): Should report WRN_NullReferenceAssignment for `x7--` // even though the local is unassigned. (The local should be treated as an l-value for assignment.) c.VerifyDiagnostics( @@ -23860,7 +23877,7 @@ class CL1 return new CL1(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,21): warning CS8604: Possible null reference argument for parameter 'x' in 'CL0 CL0.operator ++(CL0 x)'. @@ -23973,7 +23990,7 @@ class X4 set { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,21): warning CS8604: Possible null reference argument for parameter 'x' in 'CL0 CL0.operator ++(CL0 x)'. @@ -24043,7 +24060,7 @@ void Test5(dynamic x5) dynamic u5 = --x5; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (16,22): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -24094,7 +24111,7 @@ class C : A class B : A { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,19): warning CS8604: Possible null reference argument for parameter 'x' in 'C? A.operator ++(A x)'. @@ -24144,7 +24161,7 @@ class C : A class B : A { } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,16): warning CS8601: Possible null reference assignment. @@ -24195,7 +24212,7 @@ class Convertible return new Convertible(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,29): warning CS8604: Possible null reference argument for parameter 'c' in 'Convertible.implicit operator int(Convertible c)'. @@ -24240,7 +24257,7 @@ class CL1 return new CL0(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,19): warning CS8604: Possible null reference argument for parameter 'x' in 'CL1.implicit operator CL0(CL1 x)'. @@ -24288,7 +24305,7 @@ class CL1 return new CL0(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,25): warning CS8604: Possible null reference argument for parameter 'y' in 'CL1 CL0.operator +(CL0 x, CL0 y)'. @@ -24356,7 +24373,7 @@ class CL1 return new CL0(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,19): warning CS8604: Possible null reference argument for parameter 'x' in 'CL1 CL0.operator +(CL0 x, CL0? y)'. @@ -24452,7 +24469,7 @@ class CL1 return new CL0(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -24528,7 +24545,7 @@ void Test4(dynamic? x4, dynamic? y4) dynamic u4 = x4 += y4; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( ); @@ -24578,7 +24595,7 @@ class CL1 return new CL0(); } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,19): warning CS8604: Possible null reference argument for parameter 'x' in 'CL1.implicit operator CL0(CL1 x)'. @@ -24654,7 +24671,7 @@ class CL3 set { } } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,19): warning CS8604: Possible null reference argument for parameter 'x' in 'CL1.implicit operator CL0(CL1 x)'. @@ -24700,7 +24717,7 @@ static void F(C c, IOut x, IOut y) y += c; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Report WRN_NullabilityMismatchInAssignment for compound assignment. comp.VerifyDiagnostics(); //// (12,9): warning CS8619: Nullability of reference types in value of type 'I' doesn't match target type 'I'. @@ -24772,7 +24789,7 @@ void Test7(D2? x7) E2 += x7; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,9): warning CS8602: Possible dereference of a null reference. @@ -24831,7 +24848,7 @@ void Test3(System.Action x3) y3 = z3.E1 ?? x3; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (16,28): hidden CS8607: Expression is probably never null. @@ -24874,7 +24891,7 @@ struct TS2 } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (16,28): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -24914,7 +24931,7 @@ void Dummy() } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,28): error CS0029: Cannot implicitly convert type 'void' to 'System.Action' @@ -24949,7 +24966,7 @@ void Test1(Test? x1) System.Action v1 = x1.E1; } } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (12,28): warning CS8602: Possible dereference of a null reference. @@ -25005,7 +25022,7 @@ void Test7(T x7) } class CL1 {} -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }); c.VerifyDiagnostics( // (10,21): hidden CS8607: Expression is probably never null. @@ -25061,7 +25078,7 @@ class Awaiter : System.Runtime.CompilerServices.INotifyCompletion public bool IsCompleted { get { return true; } } }"; - CreateCompilationWithMscorlib45(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8).VerifyDiagnostics( + CreateCompilationWithMscorlib45(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }).VerifyDiagnostics( // (10,20): hidden CS8607: Expression is probably never null. // object x = await new D() ?? new object(); Diagnostic(ErrorCode.HDN_ExpressionIsProbablyNeverNull, "await new D()").WithLocation(10, 20) @@ -25097,7 +25114,7 @@ class Awaiter : System.Runtime.CompilerServices.INotifyCompletion public bool IsCompleted { get { return true; } } }"; - CreateCompilationWithMscorlib45(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8).VerifyDiagnostics( + CreateCompilationWithMscorlib45(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }).VerifyDiagnostics( // (10,20): warning CS8600: Converting null literal or possible null value to non-nullable type. // object x = await new D(); Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "await new D()").WithLocation(10, 20) @@ -25152,7 +25169,7 @@ void Test2(ITest28 x2) var compilation = CreateCompilationWithMscorlib45(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, new MetadataReference[] { new CSharpCompilationReference(piaCompilation, embedInteropTypes: true) }, - options: TestOptions.DebugExe, parseOptions: TestOptions.Regular8); + options: TestOptions.DebugExe); compilation.VerifyDiagnostics( // (15,14): hidden CS8607: Expression is probably never null. @@ -25189,7 +25206,7 @@ class C {} class F : C, I1>, I2?> {} "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); var b = compilation.GetTypeByMetadataName("B"); Assert.Equal("System.String? B.F1", b.GetMember("F1").ToTestDisplayString()); @@ -25245,7 +25262,7 @@ public class C {} public class F : C, I1>, I2?> {} "; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (5,33): warning CS0067: The event 'B.E1' is never used @@ -25289,7 +25306,7 @@ public class CL0 public object? P1 { get; set;} } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, options: TestOptions.DebugDll); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, options: TestOptions.DebugDll); string source = @" class C @@ -25338,7 +25355,7 @@ public class CL0 { public object F1; } -", NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, options: TestOptions.DebugDll); +", NonNullTypesTrue, NonNullTypesAttributesDefinition }, options: TestOptions.DebugDll); string source = @" class C @@ -25394,7 +25411,7 @@ public class C {} [Nullable] public class F : C {} "; - var compilation = CreateCompilation(new[] { source, NullableAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NullableAttributeDefinition, NonNullTypesTrue, NonNullTypesAttributesDefinition }); compilation.VerifyDiagnostics( // (7,6): error CS8623: Explicit application of 'System.Runtime.CompilerServices.NullableAttribute' is not allowed. @@ -28621,7 +28638,7 @@ class C : I { void I.M(T? x) { } }"; - var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var compilation = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); var method = compilation.GetMember("C").GetMethod("I.M"); var implementations = method.ExplicitInterfaceImplementations; Assert.Equal(new[] { "void I.M(T? x)" }, implementations.SelectAsArray(m => m.ToTestDisplayString())); @@ -28972,29 +28989,29 @@ static void G(string s) var comp = CreateCompilation( new[] { source }, - parseOptions: TestOptions.Regular7); + parseOptions: TestOptions.Regular7, skipUsesIsNullable: true); comp.VerifyDiagnostics( - // (5,11): error CS8107: Feature 'static null checking' is not available in C# 7. Please use language version 8.0 or greater. + // (5,11): error CS8107: Feature 'static null checking' is not available in C# 7.0. Please use language version 8.0 or greater. // G(null!); Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "null!").WithArguments("static null checking", "8.0").WithLocation(5, 11), - // (6,11): error CS8107: Feature 'static null checking' is not available in C# 7. Please use language version 8.0 or greater. + // (6,11): error CS8107: Feature 'static null checking' is not available in C# 7.0. Please use language version 8.0 or greater. // G((null as string)!); Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "(null as string)!").WithArguments("static null checking", "8.0").WithLocation(6, 11), - // (7,11): error CS8107: Feature 'static null checking' is not available in C# 7. Please use language version 8.0 or greater. + // (7,11): error CS8107: Feature 'static null checking' is not available in C# 7.0. Please use language version 8.0 or greater. // G(default(string)!); Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "default(string)!").WithArguments("static null checking", "8.0").WithLocation(7, 11), - // (8,11): error CS8107: Feature 'static null checking' is not available in C# 7. Please use language version 8.0 or greater. + // (8,11): error CS8107: Feature 'static null checking' is not available in C# 7.0. Please use language version 8.0 or greater. // G(default!); Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "default!").WithArguments("static null checking", "8.0").WithLocation(8, 11), - // (8,11): error CS8107: Feature 'default literal' is not available in C# 7. Please use language version 7.1 or greater. + // (8,11): error CS8107: Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater. // G(default!); Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "default").WithArguments("default literal", "7.1").WithLocation(8, 11), - // (9,11): error CS8107: Feature 'static null checking' is not available in C# 7. Please use language version 8.0 or greater. + // (9,11): error CS8107: Feature 'static null checking' is not available in C# 7.0. Please use language version 8.0 or greater. // G(s!); Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "s!").WithArguments("static null checking", "8.0").WithLocation(9, 11), - // (3,27): error CS0453: The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable' + // (3,19): error CS8107: Feature 'static null checking' is not available in C# 7.0. Please use language version 8.0 or greater. // static void F(string? s) - Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "s").WithArguments("System.Nullable", "T", "string").WithLocation(3, 27)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "string? s").WithArguments("static null checking", "8.0").WithLocation(3, 19)); comp = CreateCompilation( new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, @@ -29310,7 +29327,7 @@ static void F(C? x, C y) var a4 = new[] { x!, y! }; // 4 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,29): warning CS8619: Nullability of reference types in value of type 'C' doesn't match target type 'C'. // var a1 = new[] { x, y }; // 1 @@ -29342,7 +29359,7 @@ static void F(C? x, C y) C c4 = x!; // 5 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,25): warning CS8619: Nullability of reference types in value of type 'C' doesn't match target type 'C'. // C? c1 = y; // 1 @@ -29377,7 +29394,7 @@ static void F(C? x, C y) var c4 = (C)x!; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should there be a warning on c1 too? comp.VerifyDiagnostics( // (7,18): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -29401,7 +29418,7 @@ static void F(C? x, C y) _ = new C() { X = y!, Y = x! }; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,32): warning CS8619: Nullability of reference types in value of type 'C' doesn't match target type 'C'. // _ = new C() { X = y, Y = x }; @@ -29447,7 +29464,7 @@ static void F(D y) _ = new D() { y!, y! }; // warn 7 and 8 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (19,28): warning CS8620: Nullability of reference types in argument of type 'D' doesn't match target type 'D' for parameter 'key' in 'void D.Add(D? key, params D?[] value)'. // _ = new D() { y, y }; // warn 5 and 6 @@ -30243,7 +30260,7 @@ static void F() var a = new object[] { new object(), F! }; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,46): error CS0428: Cannot convert method group 'F' to non-delegate type 'object'. Did you intend to invoke the method? // var a = new object[] { new object(), F }; @@ -30348,7 +30365,7 @@ static void F(object o) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (3,17): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. // object P => null; @@ -30371,7 +30388,7 @@ static void F(object? o) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -30400,7 +30417,7 @@ static void Main() F(new S()); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (15,9): warning CS8602: Possible dereference of a null reference. // i.F(); @@ -30451,7 +30468,7 @@ static void G(object? o) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,18): error CS0428: Cannot convert method group 'F' to non-delegate type 'object'. Did you intend to invoke the method? // if (o is F) @@ -30473,7 +30490,7 @@ static void G(string s) F(s is var o); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -30494,7 +30511,7 @@ static void G(string? s) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -30528,7 +30545,7 @@ static void G(object? x) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (18,19): warning CS8604: Possible null reference argument for parameter 'o' in 'void C.F(object o)'. // F(x); // null @@ -30718,7 +30735,7 @@ static void G() var a = new[] { F(a) }; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (11,27): error CS0841: Cannot use local variable 'a' before it is declared // var a = new[] { F(a) }; @@ -30731,7 +30748,7 @@ static void G() [Fact] public void InferLocalType_UsedInDeclaration_Script() { - var lib = CreateCompilation(new[] { NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var lib = CreateCompilation(new[] { NonNullTypesAttributesDefinition }); var source = @"using System; using System.Collections.Generic; @@ -30766,7 +30783,7 @@ static void G() var b = a; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (11,27): error CS0841: Cannot use local variable 'b' before it is declared // var a = new[] { F(b) }; @@ -30794,7 +30811,7 @@ static void G() }"; // ErrorCode.WRN_NullReferenceReceiver is reported for F(v).ToString() because F(v) // has type T from initial binding (see https://github.com/dotnet/roslyn/issues/25778). - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (12,21): error CS8197: Cannot infer the type of implicitly-typed out variable 'v'. // d.F(out var v); @@ -30897,7 +30914,7 @@ static void M() F0(string.Empty); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,31): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. // static void F0(string s = null) { } @@ -30948,7 +30965,7 @@ static void M() F2(null!, null); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (14,15): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. // F1(x: null); @@ -31070,7 +31087,7 @@ static void G3() where T : new() F6(default); // 6 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,29): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. // static void F1(T t = null) where T : class { } @@ -31150,11 +31167,11 @@ public sealed class NonNullTypesAttribute : Attribute Diagnostic(ErrorCode.ERR_NonNullTypesNotAvailable, "System.Runtime.CompilerServices.NonNullTypes(true)").WithArguments("8.0").WithLocation(1, 10) ); - var comp2 = CreateCompilation(new[] { NonNullTypesTrue, poisonedDefinition }, parseOptions: TestOptions.Regular8); + var comp2 = CreateCompilation(new[] { NonNullTypesTrue, poisonedDefinition }); comp2.VerifyDiagnostics(); // When referenced from metadata and in a C# 8.0 compilation, it's okay to use this attribute - var comp3 = CreateCompilation(NonNullTypesTrue, references: new[] { libComp.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + var comp3 = CreateCompilation(NonNullTypesTrue, references: new[] { libComp.EmitToImageReference() }); comp3.VerifyDiagnostics(); } @@ -31235,7 +31252,7 @@ public class D public static event System.Action Event; } "; - var libComp = CreateCompilation(new[] { libSource, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var libComp = CreateCompilation(new[] { libSource, NonNullTypesAttributesDefinition }); libComp.VerifyDiagnostics( // (19,39): warning CS0067: The event 'D.Event' is never used // public static event System.Action Event; @@ -31262,7 +31279,7 @@ void M() Diagnostic(ErrorCode.ERR_BadEventUsageNoField, "Event").WithArguments("D.Event").WithLocation(10, 11) ); - var comp2 = CreateCompilation(source, references: new[] { libComp.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + var comp2 = CreateCompilation(source, references: new[] { libComp.EmitToImageReference() }); comp2.VerifyDiagnostics( // (10,11): error CS0079: The event 'D.Event' can only appear on the left hand side of += or -= // D.Event(); @@ -31287,7 +31304,7 @@ static void M() G(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,34): warning CS1066: The default value specified for parameter 'x' will have no effect because it applies to a member that is used in contexts that do not allow optional arguments // static partial void G(object x = null, object? y = null) { } @@ -31384,7 +31401,7 @@ static T F(Func? f) return f?.Invoke(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,17): error CS0023: Operator '?' cannot be applied to operand of type 'Func' // return f?.Invoke(); @@ -31473,7 +31490,7 @@ static void G(out C? c) c.ToString(); // 3 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,9): error CS0269: Use of unassigned out parameter 'c' // c.ToString(); // 1 @@ -31497,7 +31514,7 @@ static void G(out C c) c.F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,20): error CS0269: Use of unassigned out parameter 'c' // object o = c.F; @@ -31527,7 +31544,7 @@ static void G(out S s) s.F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,20): error CS0170: Use of possibly unassigned field 'F' // object o = s.F; @@ -31555,7 +31572,7 @@ struct S { internal C? F; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,13): error CS0170: Use of possibly unassigned field 'F' // c = s.F; @@ -31592,7 +31609,7 @@ struct S internal object? F; internal object? G; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (14,17): error CS0170: Use of possibly unassigned field 'F' // o = s.F; @@ -31620,7 +31637,7 @@ struct S { internal C? P { get => null; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // c = s.P; @@ -31643,7 +31660,7 @@ void M(out object o) P.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // o = P; @@ -31666,7 +31683,7 @@ public void UnassignedClassAutoProperty_Constructor() P.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // o = P; @@ -31689,7 +31706,7 @@ void M(out object o) P.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // o = P; @@ -31712,7 +31729,7 @@ public void UnassignedStructAutoProperty_Constructor() P.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,13): error CS8079: Use of possibly unassigned auto-implemented property 'P' // o = P; @@ -31736,7 +31753,7 @@ static void M(C x) object z = y.F; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,20): warning CS8600: Converting null literal or possible null value to non-nullable type. // object z = y.F; @@ -31757,7 +31774,7 @@ static void M(S x) object z = y.F; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,20): warning CS8600: Converting null literal or possible null value to non-nullable type. // object z = y.F; @@ -31777,7 +31794,7 @@ void M() S.F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,9): error CS0120: An object reference is required for the non-static field, method, or property 'S.F' // S.F.ToString(); @@ -31827,7 +31844,7 @@ public class ObsoleteAttribute : Attribute public ObsoleteAttribute(string message) => throw null; } }"; - var comp = CreateEmptyCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateEmptyCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (16,22): warning CS8602: Possible dereference of a null reference. // _value = _f.GetHashCode(); @@ -31846,7 +31863,7 @@ static unsafe void F(int* p) *p = 0; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, options: TestOptions.UnsafeReleaseDll); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, options: TestOptions.UnsafeReleaseDll); comp.VerifyDiagnostics(); } @@ -31869,7 +31886,7 @@ class C static Task? G3() { return default; } static Task? G6() where T : class => null; }"; - var comp = CreateCompilationWithMscorlib46(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilationWithMscorlib46(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (4,25): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. // static Task F0() => null; @@ -31916,7 +31933,7 @@ class C static async Task? G3() { return default; } static async Task? G6() where T : class => null; }"; - var comp = CreateCompilationWithMscorlib46(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilationWithMscorlib46(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,30): error CS1997: Since 'C.F0()' is an async method that returns 'Task', a return keyword must not be followed by an object expression. Did you intend to return 'Task'? // static async Task F0() { return null; } @@ -31959,7 +31976,7 @@ static async Task F(ref int i) return await Task.Run(() => i++); } }"; - var comp = CreateCompilationWithMscorlib46(source, parseOptions: TestOptions.Regular8); + var comp = CreateCompilationWithMscorlib46(source); comp.VerifyDiagnostics( // (4,38): error CS1988: Async methods cannot have ref or out parameters // static async Task F(ref int i) @@ -31982,7 +31999,7 @@ static void M() s.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,15): error CS0037: Cannot convert null to 'S' because it is a non-nullable value type // S s = (S)null; @@ -32012,7 +32029,7 @@ static void F(A? x, A? y) w?.F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (17,11): warning CS8602: Possible dereference of a null reference. // w?.F.ToString(); @@ -32031,7 +32048,7 @@ static void Main() var items = from i in Enumerable.Range(0, 3) group (long)i by i; } }"; - var comp = CreateCompilationWithMscorlib40AndSystemCore(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilationWithMscorlib40AndSystemCore(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -32054,7 +32071,7 @@ static void M(C c) (new[]{ c })[0].F(string.Empty); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -32076,7 +32093,7 @@ static void F(B? b) C c = b; // (ImplicitUserDefined)(ImplicitReference) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (12,15): warning CS8604: Possible null reference argument for parameter 'a' in 'A.implicit operator C(A a)'. // C c = b; // (ImplicitUserDefined)(ImplicitReference)b @@ -32101,7 +32118,7 @@ static void F(C c) A a = c; // (ImplicitReference)(ImplicitUserDefined) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (12,15): warning CS8600: Converting null literal or possible null value to non-nullable type. // A a = c; // (ImplicitReference)(ImplicitUserDefined) @@ -32120,7 +32137,7 @@ static void M() S s = true; // (ImplicitUserDefined)(Boxing) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -32136,7 +32153,7 @@ static void M() bool b = new S(); // (Unboxing)(ExplicitUserDefined) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,18): error CS0266: Cannot implicitly convert type 'S' to 'bool'. An explicit conversion exists (are you missing a cast?) // bool b = new S(); // (Unboxing)(ExplicitUserDefined) @@ -32169,7 +32186,7 @@ static void F2(B? b2) c = (C?)b2; // (ExplicitUserDefined)(ImplicitReference) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (19,16): warning CS8604: Possible null reference argument for parameter 'a' in 'A.explicit operator C(A a)'. // c = (C)b2; // (ExplicitUserDefined)(ImplicitReference) @@ -32227,7 +32244,7 @@ static void F2(A? a2, B? b2) d = (D?)(A?)b2; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (13,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // c = (C)a1; // (ExplicitUserDefined) @@ -32292,7 +32309,7 @@ static void F(B? b) s = (S?)b; // (ImplicitNullable)(ExplicitUserDefined)(ImplicitReference) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (12,16): warning CS8604: Possible null reference argument for parameter 'a' in 'A.explicit operator S(A a)'. // s = (S)b; // (ExplicitUserDefined)(ImplicitReference) @@ -32329,7 +32346,7 @@ static void F(S s) a.F(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should only report one WRN_ConvertingNullableToNonNullable // warning for `B b2 = (B)s;` and `A a = (B)s;`. comp.VerifyDiagnostics( @@ -32378,7 +32395,7 @@ static void F((B?, B) b) (C, C?) c = b; // (ImplicitTuple)(ImplicitUserDefined)(ImplicitReference) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (12,21): warning CS8604: Possible null reference argument for parameter 'a' in 'A.implicit operator C(A a)'. // (C, C?) c = b; // (ImplicitTuple)(ImplicitUserDefined)(ImplicitReference) @@ -32406,7 +32423,7 @@ static void F(C? x, C y) (A, A?) t = (x, y); // (ImplicitTuple)(ImplicitReference)(ImplicitUserDefined) } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (12,17): warning CS0219: The variable 't' is assigned but its value is never used // (A, A?) t = (x, y); // (ImplicitTuple)(ImplicitReference)(ImplicitUserDefined) @@ -32457,7 +32474,7 @@ static void FC(C x, C y) static void EC1((IOut, IOut) t) { } static void EC2((IOut, IOut) t) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): NullableWalker should call ConversionsBase.GetTupleLiteralConversion. comp.VerifyDiagnostics(/* PROTOTYPE(NullableReferenceType) */); } @@ -32503,7 +32520,7 @@ static void FC(C x, C y) static void EC1(this (IOut, IOut) t) { } static void EC2(this (IOut, IOut) t) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): NullableWalker should call ConversionsBase.ClassifyImplicitExtensionMethodThisArgConversion. comp.VerifyDiagnostics(/* PROTOTYPE(NullableReferenceType) */); } @@ -32523,7 +32540,7 @@ static void G(string x, string? y) F((y, y)).Item2.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,9): warning CS8602: Possible dereference of a null reference. // F((x, y)).Item2.ToString(); @@ -32551,7 +32568,7 @@ static void G(string x, string? y) F((y, y)).Item2.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. // F((y, x)).Item2.ToString(); @@ -32576,7 +32593,7 @@ static void G((string, string) x, (string, string?) y, (string?, string) z, (str F(w).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. // F(z).ToString(); @@ -32605,7 +32622,7 @@ static void G(string x, string? y) F(ref t4).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,15): warning CS8620: Nullability of reference types in argument of type '(string, string)' doesn't match target type '(string, string?)' for parameter 't' in 'string C.F(ref (string, string?) t)'. // F(ref t1).ToString(); @@ -32636,7 +32653,7 @@ static void G() F(out (string?, string?) t4).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,15): warning CS8620: Nullability of reference types in argument of type '(string, string)' doesn't match target type '(string, string?)' for parameter 't' in 'string C.F(out (string, string?) t)'. // F(out (string, string) t1).ToString(); @@ -32686,7 +32703,7 @@ static void G(IOut<(string, string)> x, IOut<(string, string?)> y, IOut<(string? F(w).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,11): warning CS8620: Nullability of reference types in argument of type 'I<(string, string)>' doesn't match target type 'I<(string, string?)>' for parameter 't' in 'string C.F(I<(string, string?)> t)'. // F(x).ToString(); @@ -32746,7 +32763,7 @@ static void F(object? x, object? y) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should not report warning for // `t.Item1.Item2`, `t.Item2`, `t.Item1.y`, or `t.z`. comp.VerifyDiagnostics( @@ -32789,7 +32806,7 @@ static void F(object? x, object? y) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should not report warning for `t._9` or `t.Rest.Item2`. comp.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. @@ -32825,7 +32842,7 @@ static void M(string x, string? y) c = new C((y, y)); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should report WRN_NullabilityMismatchInArgument for `(y, x)` and `(y, y)`. comp.VerifyDiagnostics(); //// (9,19): warning CS8620: Nullability of reference types in argument of type '(string? y, string x)' doesn't match target type '(string x, string? y)' for parameter 't' in 'C.C((string x, string? y) t)'. @@ -32853,7 +32870,7 @@ static void M(string x, string? y) o = c[(y, y)]; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should report WRN_NullabilityMismatchInArgument for `(y, x)` and `(y, y)`. comp.VerifyDiagnostics(); //// (10,15): warning CS8620: Nullability of reference types in argument of type '(string? y, string x)' doesn't match target type '(string x, string? y)' for parameter 't' in 'object? C.this[(string x, string? y) t].get'. @@ -32882,7 +32899,7 @@ static void M(string x, string? y) }; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should report WRN_NullabilityMismatchInArgument for `(y, x)`. comp.VerifyDiagnostics( //// (10,13): warning CS8620: Nullability of reference types in argument of type '(string? y, string x)' doesn't match target type '(string, string?)' for parameter 'item' in 'void List<(string, string?)>.Add((string, string?) item)'. @@ -32932,7 +32949,7 @@ static void F(object? x) } }"; // PROTOTYPE(NullableReferenceTypes): Should not report warnings for `z.E2?.Invoke()`. - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, targetFramework: TargetFramework.Mscorlib46, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, targetFramework: TargetFramework.Mscorlib46); comp.VerifyDiagnostics( // (27,11): error CS0070: The event '(object?, object?).E2' can only appear on the left hand side of += or -= (except when used from within the type '(object?, object?)') // y.E2?.Invoke().ToString(); @@ -32999,7 +33016,7 @@ static void F(object? x) z.Item2.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, targetFramework: TargetFramework.Mscorlib46, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, targetFramework: TargetFramework.Mscorlib46); comp.VerifyDiagnostics( // (29,9): warning CS8602: Possible dereference of a null reference. // y.F.ToString(); @@ -33060,7 +33077,7 @@ static void M(object x) y.P.ToString(); } }"; - var comp = CreateEmptyCompilation(source, parseOptions: TestOptions.Regular8); + var comp = CreateEmptyCompilation(source); comp.VerifyDiagnostics( // (6,24): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // public object? F; @@ -33069,7 +33086,7 @@ static void M(object x) // public object? P { get; set; } Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "object?").WithLocation(11, 16)); - var comp2 = CreateEmptyCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp2 = CreateEmptyCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp2.VerifyDiagnostics( // (44,9): warning CS8602: Possible dereference of a null reference. // y.F.ToString(); @@ -33105,7 +33122,7 @@ static void F(object o) // c.F((o, -1)).x.ToString(); Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "x").WithArguments("(object, int)", "x").WithLocation(13, 22)); - comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (13,22): error CS1061: '(object, int)' does not contain a definition for 'x' and no extension method 'x' accepting a first argument of type '(object, int)' could be found (are you missing a using directive or an assembly reference?) // c.F((o, -1)).x.ToString(); @@ -33131,7 +33148,7 @@ static void F(object o) c.F((o, -1)).x.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (13,22): error CS1061: '(object?, int)' does not contain a definition for 'x' and no extension method 'x' accepting a first argument of type '(object?, int)' could be found (are you missing a using directive or an assembly reference?) // c.F((o, -1)).x.ToString(); @@ -33161,7 +33178,7 @@ static void F(dynamic x, object y) var comp = CreateCompilation(new[] { source }, parseOptions: TestOptions.Regular7); comp.VerifyDiagnostics(); - comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -33184,7 +33201,7 @@ static void F(dynamic x, object y) c.F((x, y)).Item1.G(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -33208,7 +33225,7 @@ static void F(I i, dynamic? d) i.F(d).G(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (12,9): error CS1929: 'I' does not contain a definition for 'F' and the best extension method overload 'E.F(I, T)' requires a receiver of type 'I' // i.F(d).G(); @@ -33228,7 +33245,7 @@ static ushort G(S? s) return (ushort)(s?.F ?? 0); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -33245,7 +33262,7 @@ class P static int F(S? x, int y) => x ?? y; static int G(S x, int? y) => y ?? x; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -33258,7 +33275,7 @@ public void ConstrainedToTypeParameter_01() }"; var comp = CreateCompilation(new[] { source }, parseOptions: TestOptions.Regular7); comp.VerifyDiagnostics(); - comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -33271,7 +33288,7 @@ public void ConstrainedToTypeParameter_02() }"; var comp = CreateCompilation(new[] { source }, parseOptions: TestOptions.Regular7); comp.VerifyDiagnostics(); - comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -33283,7 +33300,7 @@ public void ArrayElementConversion() { static object F() => new sbyte[] { -1 }; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -33308,7 +33325,7 @@ static void F(object x) y.ToString(); // 6 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // x = null; @@ -33347,7 +33364,7 @@ static void M(C c) c.P.ToString(); // 6 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,15): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. // c.F = null; @@ -33392,7 +33409,7 @@ static void M(C c) c.P.ToString(); } }"; - var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { comp0.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { comp0.EmitToImageReference() }); comp1.VerifyDiagnostics( // (9,9): warning CS8602: Possible dereference of a null reference. // c.F.ToString(); // 1 @@ -33468,7 +33485,7 @@ static void Property() c.P = y; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (17,21): warning CS8600: Converting null literal or possible null value to non-nullable type. // object x1 = null; @@ -33567,7 +33584,7 @@ static void F4(B2 x4, B2? y4) ((A)y4).F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (2,7): warning CS8618: Non-nullable field 'F' is uninitialized. // class A @@ -33696,7 +33713,7 @@ static void F4(A4? x4, A4 y4) b = ((B?)y4)/*T:B!*/; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (23,14): warning CS8600: Converting null literal or possible null value to non-nullable type. // b = ((B)x1)/*T:B?*/; @@ -33759,7 +33776,7 @@ static void F2(A2 x2, A2 y2) y = ((B)y2)/*T:B*/; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should not report WRN_NullabilityMismatchInAssignment for `y = ((B)x1)`. comp.VerifyDiagnostics( // (17,14): warning CS8619: Nullability of reference types in value of type 'B' doesn't match target type 'B'. @@ -33786,7 +33803,7 @@ public void ExplicitCast_StaticType() static object F(object? x) => (C)x; static object? G(object? y) => (C?)y; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (3,35): error CS0716: Cannot convert to static type 'C' // static object F(object? x) => (C)x; @@ -33827,7 +33844,7 @@ static void F(Enumerable e) z.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -33856,7 +33873,7 @@ static void F(Enumerable e) z.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (15,13): warning CS8602: Possible dereference of a null reference. // x.ToString(); @@ -33937,7 +33954,7 @@ static void G(IEnumerable e) w.ToString(); } }"; - var comp = CreateEmptyCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateEmptyCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (50,13): warning CS8602: Possible dereference of a null reference. // x.ToString(); @@ -33978,7 +33995,7 @@ static void F(IEnumerable cx, object?[] cy) z.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. // x.ToString(); @@ -34002,7 +34019,7 @@ static void F1(dynamic c) y.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -34031,7 +34048,7 @@ class P w.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (13,13): warning CS8602: Possible dereference of a null reference. // x.ToString(); @@ -34091,7 +34108,7 @@ class P w2.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (26,13): warning CS8602: Possible dereference of a null reference. // x2.ToString(); @@ -34142,7 +34159,7 @@ static void F3(IEnumerable> x3, IEnumerable> y3) b3.P.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,13): warning CS8602: Possible dereference of a null reference. // a1.P.ToString(); @@ -34174,7 +34191,7 @@ static void F(A?[] c) b2.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,13): warning CS8602: Possible dereference of a null reference. // a1.ToString(); @@ -34226,7 +34243,7 @@ static void F(A[] c) }"; // PROTOTYPE(NullableReferenceTypes): Should report WRN_NullabilityMismatchInAssignment // for `A a3 in c` and `B b1 in c`. - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (13,13): warning CS8602: Possible dereference of a null reference. // a1.F.ToString(); @@ -34366,7 +34383,7 @@ static void G(A? x, A y, B b) F(z, z)/*T:A*/.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyTypes(); comp.VerifyDiagnostics( // (7,9): warning CS8602: Possible dereference of a null reference. @@ -34677,7 +34694,7 @@ public class NotNull { public A A3; }"; - var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp1 = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp1.VerifyDiagnostics(); var ref1 = comp1.EmitToImageReference(); @@ -34722,7 +34739,7 @@ static void F9(NotNull x9, NotNull y9) F(x9.A3, y9.A3)/*T:A!*/.F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue }, references: new[] { ref0, ref1 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue }, references: new[] { ref0, ref1 }); comp.VerifyTypes(); comp.VerifyDiagnostics( // (14,9): warning CS8602: Possible dereference of a null reference. @@ -34772,7 +34789,7 @@ static void F(object? x) } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (1,7): warning CS8618: Non-nullable field 'F' is uninitialized. // class C @@ -34801,7 +34818,7 @@ static void M(I x, I y) F(y: y, x: x).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,9): warning CS8602: Possible dereference of a null reference. // F(y: y, x: x).ToString(); @@ -34975,7 +34992,7 @@ static void G(string x, string? y) F(t).Item2.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. // F(t).Item2.ToString(); @@ -35003,7 +35020,7 @@ static void G(string x, string? y) F(u).b.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. // F(t).Item2.ToString(); @@ -35033,7 +35050,7 @@ static void F(object? x, object? y) t.y.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. // t.y.ToString(); @@ -35151,7 +35168,7 @@ static void G(string s) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,11): warning CS8604: Possible null reference argument for parameter 's' in 'void Program.G(string s)'. // G(a.F); @@ -35183,7 +35200,7 @@ static void G(string s) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,11): warning CS8604: Possible null reference argument for parameter 's' in 'void Program.G(string s)'. // G(a.P); @@ -35215,7 +35232,7 @@ static void G(string s) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,11): warning CS8604: Possible null reference argument for parameter 's' in 'void Program.G(string s)'. // G(a.P); @@ -35257,7 +35274,7 @@ class B : A if (base.P != null) F(base.P); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (17,11): warning CS8604: Possible null reference argument for parameter 's' in 'void A.F(string s)'. // F(this.P); @@ -35285,7 +35302,7 @@ static void M(C c) c.F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,9): warning CS8602: Possible dereference of a null reference. // c.F.ToString(); @@ -35330,7 +35347,7 @@ static void F() o = c.B.A; // 6 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (24,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // o = c.B.A; // 2 @@ -35400,7 +35417,7 @@ static void M() o = c.B.F; // 5 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (17,13): warning CS8602: Possible dereference of a null reference. // o = c.A.A; // 1 @@ -35473,7 +35490,7 @@ static void M() o = c.B.P; // 5 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (17,13): warning CS8602: Possible dereference of a null reference. // o = c.A.A; // 1 @@ -35539,7 +35556,7 @@ static void F() o = b.A.F; // 3 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (23,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // o = b.A.F; // 2 @@ -35574,7 +35591,7 @@ void M() o = F.P; // 2 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (13,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // o = F.P; // 1 @@ -35601,7 +35618,7 @@ void M() o = F.P; // 2 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (12,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // o = F.P; // 1 @@ -35616,7 +35633,7 @@ public void ModifyMembers_StructPropertyFromMetadata() { public object? P { get; set; } }"; - var comp0 = CreateCompilation(source0, parseOptions: TestOptions.Regular8); + var comp0 = CreateCompilation(source0); var ref0 = comp0.EmitToImageReference(); var source = @@ -35632,7 +35649,7 @@ void M() o = F.P; // 2 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { ref0 }); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics( // (8,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // o = F.P; // 1 @@ -35655,7 +35672,7 @@ void M() o = P; // 2 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // o = P; // 1 @@ -35683,7 +35700,7 @@ void M() o = F.P; // 2 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (12,13): warning CS8600: Converting null literal or possible null value to non-nullable type. // o = F.P; // 1 @@ -35721,7 +35738,7 @@ static void M() o = b.Q.P; // 5 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should report warnings. comp.VerifyDiagnostics(/*...*/); } @@ -35806,7 +35823,7 @@ static void F() b.G.F2.ToString(); // 3 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (19,9): warning CS8602: Possible dereference of a null reference. // b.G.F2.ToString(); // 1 @@ -35853,7 +35870,7 @@ static void F() b.G.F2.ToString(); // 3 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (19,9): warning CS8602: Possible dereference of a null reference. // b.G.F2.ToString(); // 1 @@ -35900,7 +35917,7 @@ static void F() b.Q.P2.ToString(); // 3 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (19,9): warning CS8602: Possible dereference of a null reference. // b.Q.P2.ToString(); // 1 @@ -35933,7 +35950,7 @@ static void F() c.E.Invoke(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,9): warning CS8602: Possible dereference of a null reference. // c.E.Invoke(); // warning @@ -35970,7 +35987,7 @@ static void Main() a.F.ToString(); // 4 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (18,9): warning CS8602: Possible dereference of a null reference. // a.F.ToString(); // 2 @@ -36017,7 +36034,7 @@ static void Main() a.F.ToString(); // 4 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (17,9): warning CS8602: Possible dereference of a null reference. // a.F.ToString(); // 1 @@ -36081,7 +36098,7 @@ void M() F.F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,9): warning CS8602: Possible dereference of a null reference. // F.F.ToString(); @@ -36102,7 +36119,7 @@ void M() F.F.F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,9): warning CS8602: Possible dereference of a null reference. // F.F.F.ToString(); @@ -36124,7 +36141,7 @@ static void M() y.F.F.ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,9): warning CS8602: Possible dereference of a null reference. // y.F.F.ToString(); @@ -36150,7 +36167,7 @@ static void Main() s.G.S = s; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -36183,7 +36200,7 @@ static void M(S s) s.P.F.ToString(); // 2 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (19,9): warning CS8602: Possible dereference of a null reference. // s.P.F.ToString(); // 1 @@ -36205,7 +36222,7 @@ static void F(IEnumerable c) c.Select(o => new { E = o.E ?? F }); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,10): warning CS0649: Field 'C.E' is never assigned to, and will always have its default value // int? E; @@ -36251,7 +36268,7 @@ class B t5 = default; // 16 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Various differences from expected warnings. comp.VerifyDiagnostics( // (11,14): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -36368,7 +36385,7 @@ interface I class A { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): missing warnings comp.VerifyDiagnostics( // (14,23): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. @@ -36468,7 +36485,7 @@ interface I class A { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,11): warning CS8604: Possible null reference argument for parameter 'o' in 'void C.F(object o)'. // F(t1); @@ -36534,7 +36551,7 @@ static void F3(T3 x3) where T3 : new() y3 = (object)new T3(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,14): warning CS8600: Converting null literal or possible null value to non-nullable type. // y1 = (object)x1; // warn: T1 may be null @@ -36568,7 +36585,7 @@ public void UnconstrainedTypeParameter_Return_01() static object? F15(U u) where U : struct, T => (object?)u; static object? F16(U u) where U : T, new() => (object?)u; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -36595,7 +36612,7 @@ public void UnconstrainedTypeParameter_Return_02() static object F15(U u) where U : struct, T => (object)u; static object F16(U u) where U : T, new() => (object)u; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (3,34): warning CS8603: Possible null reference return. // static object F01(T t) => t; @@ -36663,7 +36680,7 @@ public void UnconstrainedTypeParameter_Return_03() static U F20(T t) where U : T, new() => (U)t; static U F21(T t) => (U)(object)t; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): There should be a warning for F17 @@ -36695,7 +36712,7 @@ static void F1() } "; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition, NonNullTypesTrue }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition, NonNullTypesTrue }); comp.VerifyDiagnostics( // (7,9): error CS0165: Use of unassigned local variable 't' // t.ToString(); // 1 @@ -36720,7 +36737,7 @@ class C "; // PROTOTYPE(NullableReferenceTypes): there should be a warning for F5 - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition, NonNullTypesTrue }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition, NonNullTypesTrue }); comp.VerifyDiagnostics( // (4,39): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. // static void F1(out T t) => t = default; // 1 @@ -36770,7 +36787,7 @@ static void F1(object o, T tin) } "; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition, NonNullTypesTrue }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition, NonNullTypesTrue }); comp.VerifyDiagnostics( // (12,18): warning CS8625: Cannot convert null literal to non-nullable reference or unconstrained type parameter. // t1 = default; // 1 @@ -36822,7 +36839,7 @@ static void M(U u) } "; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition, NonNullTypesTrue }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition, NonNullTypesTrue }); // PROTOTYPE(NullableReferenceTypes): Should not report warnings after `if (u == null) throw null;`. comp.VerifyDiagnostics( // (29,9): error CS0411: The type arguments for method 'C.CopyOutInherit(T1, out T2)' cannot be inferred from the usage. Try specifying the type arguments explicitly. @@ -36864,7 +36881,7 @@ class C static U F5(T t) where T : struct => (U)(object)t; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Errors are different than expected. comp.VerifyDiagnostics( // (4,34): warning CS8600: Converting null literal or possible null value to non-nullable type. @@ -36931,7 +36948,7 @@ static T F4(T x4) return y4; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,9): warning CS8602: Possible dereference of a null reference. // default(T).ToString(); // warn 1 @@ -36973,7 +36990,7 @@ static void F1(T1 t1) if (t2 != null) F((object)t2); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (8,11): warning CS8600: Converting null literal or possible null value to non-nullable type. // F((object)t1); @@ -37009,7 +37026,7 @@ class P static void F4(D o) { } static void F5(E o) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (2,11): error CS8627: A nullable type parameter must be known to be a value or reference type. Consider adding a 'class', 'struct', or type constraint. // interface IB : IA { } @@ -37039,7 +37056,7 @@ class B static void F() where U : A { } }"; // PROTOTYPE(NullableReferenceTypes): Report errors for T? in constraints. - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -37065,7 +37082,7 @@ class B event EventHandler E; public static explicit operator A(B t) => throw null; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Report error for `const object c = default(T?[]);`. comp.VerifyDiagnostics( // (5,10): error CS8627: A nullable type parameter must be known to be a value or reference type. Consider adding a 'class', 'struct', or type constraint. @@ -37120,7 +37137,7 @@ class C static U?[] F6() where T : I where U : T => throw null; // error static U?[] F7() where T : A where U : T => throw null; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (16,12): error CS8627: A nullable type parameter must be known to be a value or reference type. Consider adding a 'class', 'struct', or type constraint. // static U?[] F2() where T : class where U : T => throw null; @@ -37176,7 +37193,7 @@ class B : A internal override void F6(U? u) { } // error internal override void F7(U? u) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (4,34): error CS8627: A nullable type parameter must be known to be a value or reference type. Consider adding a 'class', 'struct', or type constraint. // internal abstract void F1(T? t); // error @@ -37212,7 +37229,7 @@ class C static void F1(A.I i) { } static void F2(A.E[] e) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (9,23): error CS8627: A nullable type parameter must be known to be a value or reference type. Consider adding a 'class', 'struct', or type constraint. // static void F2(A.E[] e) { } @@ -37237,7 +37254,7 @@ static void M() o = new U?[0]; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Report errors within method body. comp.VerifyDiagnostics(); } @@ -37255,7 +37272,7 @@ static void G() F((T? t) => { }); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,12): error CS8627: A nullable type parameter must be known to be a value or reference type. Consider adding a 'class', 'struct', or type constraint. // F((T? t) => { }); @@ -37278,7 +37295,7 @@ static void F2() void L2(T?[] t) { } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,9): error CS8627: A nullable type parameter must be known to be a value or reference type. Consider adding a 'class', 'struct', or type constraint. // T? L1() => throw null; @@ -37320,7 +37337,7 @@ public void NullableT_FromMetadata_BaseAndInterfaces() static void F(IB b) { } static void G(B b) { } }"; - var comp = CreateCompilation(source1, new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(source1, new[] { ref0 }); // PROTOTYPE(NullableReferenceTypes): Report errors for T? in metadata? comp.VerifyDiagnostics(); } @@ -37399,7 +37416,7 @@ static void Main() C.F6(); } }"; - var comp = CreateCompilation(source1, new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(source1, new[] { ref0 }); // PROTOTYPE(NullableReferenceTypes): Report errors for T? in metadata? comp.VerifyDiagnostics(); } @@ -37414,7 +37431,7 @@ class B where T : T? { } class C where T : class, T? { } class D where T : struct, T? { } class E where T : A, T? { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (4,30): error CS0701: 'T?' is not a valid constraint. A type used as a constraint must be an interface, a non-sealed class or a type parameter. // class D where T : struct, T? { } @@ -37459,7 +37476,7 @@ class E where U : T? { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (10,9): error CS0454: Circular constraint dependency involving 'T' and 'U' // class C @@ -37487,7 +37504,7 @@ class C where V : V?, V? { } delegate void D3() where T3 : class where U3 : T3, T3?;"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (1,25): error CS0405: Duplicate constraint 'T' for type parameter 'T' // class A where T : T, T? { } @@ -37533,7 +37550,7 @@ class B static void F6() where T : class where U : T? { } static void F7() where T : struct where U : T? { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,20): error CS0454: Circular constraint dependency involving 'T' and 'T' // static void F2() where T : class, T? { } @@ -37571,7 +37588,7 @@ static void M() void F7() where T : struct where U : T? { } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (7,17): error CS0454: Circular constraint dependency involving 'T' and 'T' // void F1() where T : T? { } @@ -37612,7 +37629,7 @@ class B void F5() where U : T? { } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -37646,7 +37663,7 @@ class B4 : A, I where T : class { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // PROTOTYPE(NullableReferenceTypes): Should report warnings that `T?` // does not satisfy `where T : class` constraint or `where U : T` constraint. comp.VerifyDiagnostics(); @@ -37680,7 +37697,7 @@ static void Main() o = new C(); // 2 } }"; - var comp = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, new[] { ref0 }); comp.VerifyDiagnostics( // (6,19): error CS0454: Circular constraint dependency involving 'T' and 'T' // o = new C(); // 1 @@ -37700,7 +37717,7 @@ public void NullableTInConstraint_09() where U : T? { }"; - var comp = CreateCompilation(source0, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(source0); var ref0 = comp.EmitToImageReference(); var source1 = @"class Program @@ -37714,7 +37731,7 @@ static void Main() o = new C(); // 4 } }"; - comp = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, new[] { ref0 }, parseOptions: TestOptions.Regular8); + comp = CreateCompilation(new[] { source1, NonNullTypesTrue, NonNullTypesAttributesDefinition }, new[] { ref0 }); // PROTOTYPE(NullableReferenceTypes): TypeSymbolExtensions.GetTypeRefWithAttributes // drops the top-level nullability when emitting the `T?` constraint. See also // AttributeTests_Nullable.EmitAttribute_Constraint_03. @@ -37732,7 +37749,7 @@ class C static void F1() where T : class, I { } static void F2() where T : I { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (5,35): error CS1968: Constraint cannot be a dynamic type 'I' // static void F2() where T : I { } @@ -37755,7 +37772,7 @@ class C where T : class static void F7() where U : I, I { } static void F8() where U : I, I { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (4,38): error CS0405: Duplicate constraint 'T' for type parameter 'U' // static void F1() where U : T, T { } @@ -37804,7 +37821,7 @@ partial class B }"; var comp = CreateCompilation(new[] { source }, parseOptions: TestOptions.Regular7); comp.VerifyDiagnostics(); - comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -37815,7 +37832,7 @@ public void PartialClassConstraintMismatch() @"class A { } partial class B where T : A { } partial class B where T : A? { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (2,15): error CS0265: Partial declarations of 'B' have inconsistent constraints for type parameter 'T' // partial class B where T : A { } @@ -37831,7 +37848,7 @@ class C1 : I, I { } class C2 : I, I { } class C3 : I, I { } class C4 : I, I { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (2,7): error CS0695: 'C1' cannot implement both 'I' and 'I' because they may unify for some type parameter substitutions // class C1 : I, I { } @@ -37865,7 +37882,7 @@ class C1 : I, I where T : struct { } class C2 : I, I where T : struct { } class C3 : I, I where T : struct { } class C4 : I, I where T : struct { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (2,7): error CS0695: 'C1' cannot implement both 'I' and 'I' because they may unify for some type parameter substitutions // class C1 : I, I where T : struct { } @@ -37896,7 +37913,7 @@ class C1 : I, I where T : class { } class C2 : I, I where T : class { } class C3 : I, I where T : class { } class C4 : I, I where T : class { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (2,7): error CS0695: 'C1' cannot implement both 'I' and 'I' because they may unify for some type parameter substitutions // class C1 : I, I where T : class { } @@ -37927,7 +37944,7 @@ class C1 : I, I where T : struct where U : class { } class C2 : I, I where T : struct where U : class { } class C3 : I, I where T : struct where U : class { } class C4 : I, I where T : struct where U : class { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); // Constraints are ignored when unifying types. comp.VerifyDiagnostics( // (2,7): error CS0695: 'C1' cannot implement both 'I' and 'I' because they may unify for some type parameter substitutions @@ -37953,7 +37970,7 @@ class C1 : I, I where T : class where U : class { } class C2 : I, I where T : class where U : class { } class C3 : I, I where T : class where U : class { } class C4 : I, I where T : class where U : class { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (2,7): error CS0695: 'C1' cannot implement both 'I' and 'I' because they may unify for some type parameter substitutions // class C1 : I, I where T : class where U : class { } @@ -37988,7 +38005,7 @@ static void F2(string? x2, string y2) (z2 = y2).ToString(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (6,10): warning CS8602: Possible dereference of a null reference. // (z1 = x1).ToString(); @@ -38010,14 +38027,14 @@ public void OverriddenMethodNullableValueTypeParameter_01() { public abstract void F(int? i); }"; - var comp0 = CreateCompilation(source0, parseOptions: TestOptions.Regular8); + var comp0 = CreateCompilation(source0); var ref0 = comp0.EmitToImageReference(); var source = @"class B : A { public override void F(int? i) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { ref0 }); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics(); } @@ -38029,7 +38046,7 @@ public void OverriddenMethodNullableValueTypeParameter_02() { public abstract void F(T? t); }"; - var comp0 = CreateCompilation(source0, parseOptions: TestOptions.Regular8); + var comp0 = CreateCompilation(source0); var ref0 = comp0.EmitToImageReference(); var source = @"class B1 : A where T : struct @@ -38040,7 +38057,7 @@ class B2 : A { public override void F(int? t) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { ref0 }); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics(); } @@ -38076,7 +38093,7 @@ static void F(C y) I b = y; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics(); } @@ -38112,7 +38129,7 @@ static void F(C y) A b = y; } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics(); } @@ -38145,7 +38162,7 @@ static void F(I1 i1, I2 i2, object x, object? y) i2.F(y); // warn } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics( // (11,14): warning CS8604: Possible null reference argument for parameter 't' in 'void I.F(object t)'. // i2.F(y); // warn @@ -38181,7 +38198,7 @@ static void F(object x, object? y) B2.F(y); // warn } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics( // (11,14): warning CS8604: Possible null reference argument for parameter 't' in 'void A.F(object t)'. // B2.F(y); // warn @@ -38211,7 +38228,7 @@ static void Main() new B2>(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics(); var typeParameters = comp.GetMember("B1").TypeParameters; Assert.Equal("A1", typeParameters[0].ConstraintTypesNoUseSiteDiagnostics[0].ToTestDisplayString(true)); @@ -38228,7 +38245,7 @@ public class A1 { } public class A2 { } [NonNullTypes(false)] public class B1 where T : A1 where U : A1? { } [NonNullTypes(false)] public class B2 where T : A2 where U : A2 { }"; - var comp0 = CreateCompilation(new[] { source0, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp0 = CreateCompilation(new[] { source0, NonNullTypesAttributesDefinition }); comp0.VerifyDiagnostics( // (4,68): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // [NonNullTypes(false)] public class B1 where T : A1 where U : A1? { } @@ -38250,7 +38267,7 @@ static void Main() new B2, A2>(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue }, references: new[] { ref0 }); comp.VerifyDiagnostics( // (8,29): warning CS8631: The type 'A2' cannot be used as type parameter 'U' in the generic type or method 'B2'. Nullability of type argument 'A2' doesn't match constraint type 'A2'. // new B2, A2>(); @@ -38276,7 +38293,7 @@ public abstract class A where T : class [NonNullTypes(true)] public abstract void F3() where U : T, I; [NonNullTypes(true)] public abstract void F4() where U : T?, I; }"; - var comp0 = CreateCompilation(new[] { source0, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp0 = CreateCompilation(new[] { source0, NonNullTypesAttributesDefinition }); comp0.VerifyDiagnostics( // (6,66): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // [NonNullTypes(false)] public abstract void F2() where U : T?, I; @@ -38321,14 +38338,14 @@ class B4 : A public override void F3() { } public override void F4() { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue }, references: new[] { new CSharpCompilationReference(comp0) }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue }, references: new[] { new CSharpCompilationReference(comp0) }); comp.VerifyDiagnostics( // (11,7): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // class B2 : A Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "B2").WithLocation(11, 7)); verifyAllConstraintTypes(); - comp = CreateCompilation(new[] { source, NonNullTypesTrue }, references: new[] { comp0.EmitToImageReference() }, parseOptions: TestOptions.Regular8); + comp = CreateCompilation(new[] { source, NonNullTypesTrue }, references: new[] { comp0.EmitToImageReference() }); comp.VerifyDiagnostics( // (11,7): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // class B2 : A @@ -38398,7 +38415,7 @@ void M3() } } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (20,14): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // T? x = t; // warn 1 @@ -38452,7 +38469,7 @@ static void Main() t = typeof(A); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { ref0 }); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics( // (10,22): warning CS8631: The type 'B2' cannot be used as type parameter 'T' in the generic type or method 'A'. Nullability of type argument 'B2' doesn't match constraint type 'I'. // t = typeof(A); // 1 @@ -38485,7 +38502,7 @@ static void F(I i) { } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8, references: new[] { ref0 }); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics(); } @@ -38534,7 +38551,7 @@ class D B4 G9; // 7 B4 G10; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics( // (4,23): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // class B1 where T : A? { } @@ -38608,7 +38625,7 @@ class D B4> G9; // 9 B4> G10; }"; - var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics( // (4,23): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // class B1 where T : A { } @@ -38657,7 +38674,7 @@ public class A2 where U : class, T? { }"; - var comp0 = CreateCompilation(new[] { source0, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp0 = CreateCompilation(new[] { source0, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp0.VerifyDiagnostics(); var ref0 = comp0.EmitToImageReference(); @@ -38667,7 +38684,7 @@ class B1 where T : A1 { } // 1 class B2 where T : A2 { } // 2 [NonNullTypes] class B3 where T : A1 { } [NonNullTypes] class B4 where T : A2 { }"; - var comp = CreateCompilation(new[] { source }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source }, references: new[] { ref0 }); // PROTOTYPE(NullableReferenceTypes): Should report warnings for each. comp.VerifyDiagnostics( // (2,23): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. @@ -38752,7 +38769,7 @@ static void FOut() FOut2(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics( // (22,9): warning CS8627: The type 'S2' cannot be used as type parameter 'T' in the generic type or method 'B.F1()'. Nullability of type argument 'S2' doesn't match constraint type 'I'. // F1(); // 1 @@ -38822,7 +38839,7 @@ public class A FOut2(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics( // (14,9): warning CS8627: The type 'U' cannot be used as type parameter 'T' in the generic type or method 'B.F1()'. Nullability of type argument 'U' doesn't match constraint type 'I'. // F1(); // 1 @@ -38870,7 +38887,7 @@ static void G(A x, A? y) F1(x); // 2 } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, references: new[] { ref0 }); comp.VerifyDiagnostics( // (11,9): warning CS8631: The type 'A?' cannot be used as type parameter 'T' in the generic type or method 'C.F1(T)'. Nullability of type argument 'A?' doesn't match constraint type 'A'. // F1(y); // 1 @@ -38913,7 +38930,7 @@ void M() }"; // PROTOTYPE(NullableReferenceTypes): Should not report warning for // dereference of `this.F` or `base.F` after assignment. - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (13,21): warning CS8602: Possible dereference of a null reference. // int n = this.F.Length; // 1 @@ -38944,7 +38961,7 @@ static void Main() new B(); } }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); var diagnostics = comp.GetDiagnostics(); diagnostics.Verify( // (8,15): warning CS8631: The type 'A' cannot be used as type parameter 'T' in the generic type or method 'B'. Nullability of type argument 'A' doesn't match constraint type 'I'. @@ -38978,32 +38995,29 @@ public class A6 where T : IEquatable { }"; { static void Main() { - new A0(); // warning + new A0(); // 1 new A0(); - new A2(); - new A2(); // warning - new A5(); - new A5(); // warning + new A2(); // 2 + new A2(); // 3 + new A5(); // 4 + new A5(); // 5 } }"; // No [NullNullTypes] - var comp0 = CreateCompilation(source0, parseOptions: TestOptions.Regular8); + var comp0 = CreateCompilation(source0); var ref0 = comp0.EmitToImageReference(); - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular8, references: new[] { ref0 }); - // PROTOTYPE(NullableReferenceTypes): Should report a warning for A0() and A2(). + var comp = CreateCompilation(source, references: new[] { ref0 }); + // PROTOTYPE(NullableReferenceTypes): Should report a nullability mismatch warning for A0() and A2(). comp.VerifyDiagnostics( // (5,22): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. - // new A0(); // warning + // new A0(); // 1 Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(5, 22), // (7,22): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. - // new A2(); + // new A2(); // 2 Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(7, 22), // (9,22): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. - // new A5(); - Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(9, 22), - // (9,16): warning CS8631: The type 'string?' cannot be used as type parameter 'T' in the generic type or method 'A5'. Nullability of type argument 'string?' doesn't match constraint type 'System.IEquatable'. - // new A5(); - Diagnostic(ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint, "string?").WithArguments("A5", "System.IEquatable", "T", "string?").WithLocation(9, 16) + // new A5(); // 4 + Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(9, 22) ); verifyTypeParameterConstraint("A0", "System.IEquatable"); verifyTypeParameterConstraint("A1", "System.IEquatable"); @@ -39014,19 +39028,19 @@ static void Main() verifyTypeParameterConstraint("A6", "System.IEquatable"); // [NullNullTypes(false)] - comp0 = CreateCompilation(new[] { source0, NonNullTypesFalse, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + comp0 = CreateCompilation(new[] { source0, NonNullTypesFalse, NonNullTypesAttributesDefinition }); ref0 = comp0.EmitToImageReference(); - comp = CreateCompilation(source, parseOptions: TestOptions.Regular8, references: new[] { ref0 }); + comp = CreateCompilation(source, references: new[] { ref0 }); // PROTOTYPE(NullableReferenceTypes): Should report same warnings as other two cases. comp.VerifyDiagnostics( // (5,22): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. - // new A0(); // warning + // new A0(); // 1 Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(5, 22), // (7,22): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. - // new A2(); + // new A2(); // 2 Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(7, 22), // (9,22): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. - // new A5(); + // new A5(); // 4 Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(9, 22) ); verifyTypeParameterConstraint("A0", "System.IEquatable"); @@ -39038,22 +39052,22 @@ static void Main() verifyTypeParameterConstraint("A6", "System.IEquatable"); // [NullNullTypes(true)] - comp0 = CreateCompilation(new[] { source0, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + comp0 = CreateCompilation(new[] { source0, NonNullTypesTrue, NonNullTypesAttributesDefinition }); ref0 = comp0.EmitToImageReference(); - comp = CreateCompilation(source, parseOptions: TestOptions.Regular8, references: new[] { ref0 }); - // PROTOTYPE(NullableReferenceTypes): Should report a warning for A0() and A2(). + comp = CreateCompilation(source, references: new[] { ref0 }); + // PROTOTYPE(NullableReferenceTypes): Should report a nullability mismatch warning for A0() and A2(). comp.VerifyDiagnostics( // (5,22): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. - // new A0(); // warning + // new A0(); // 1 Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(5, 22), // (7,22): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. - // new A2(); + // new A2(); // 2 Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(7, 22), // (9,22): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. - // new A5(); + // new A5(); // 4 Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(9, 22), // (9,16): warning CS8631: The type 'string?' cannot be used as type parameter 'T' in the generic type or method 'A5'. Nullability of type argument 'string?' doesn't match constraint type 'System.IEquatable'. - // new A5(); + // new A5(); // 4 Diagnostic(ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint, "string?").WithArguments("A5", "System.IEquatable", "T", "string?").WithLocation(9, 16) ); verifyTypeParameterConstraint("A0", "System.IEquatable"); @@ -39088,9 +39102,9 @@ interface IB where T : IA { } class C { }"; - var comp = CreateCompilation(source, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(source); comp.VerifyDiagnostics(); - comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics(); } @@ -39106,7 +39120,7 @@ class B where T : A { } class C { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesFalse, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesFalse, NonNullTypesAttributesDefinition }); comp.VerifyDiagnostics( // (4,15): error CS1503: Argument 1: cannot convert from 'System.Type' to 'bool' // [NonNullTypes(typeof(B))] @@ -39132,8 +39146,23 @@ class C class D { }"; - var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular8); + var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, parseOptions: TestOptions.Regular7_3, skipUsesIsNullable: true); comp.VerifyDiagnostics( + // (1,10): error CS8630: Please use language version 8.0 or greater to use the NonNullTypes attribute. + // [module: System.Runtime.CompilerServices.NonNullTypes(true)] + Diagnostic(ErrorCode.ERR_NonNullTypesNotAvailable, "System.Runtime.CompilerServices.NonNullTypes(true)").WithArguments("8.0").WithLocation(1, 10), + // (7,2): error CS8630: Please use language version 8.0 or greater to use the NonNullTypes attribute. + // [NonNullTypes(B.True)] + Diagnostic(ErrorCode.ERR_NonNullTypesNotAvailable, "NonNullTypes(B.True)").WithArguments("8.0").WithLocation(7, 2), + // (11,18): error CS8370: Feature 'static null checking' is not available in C# 7.3. Please use language version 8.0 or greater. + // [NonNullTypes(B.True)] + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_3, "?").WithArguments("static null checking", "8.0").WithLocation(11, 18), + // (11,2): error CS8630: Please use language version 8.0 or greater to use the NonNullTypes attribute. + // [NonNullTypes(B.True)] + Diagnostic(ErrorCode.ERR_NonNullTypesNotAvailable, "NonNullTypes(B.True)").WithArguments("8.0").WithLocation(11, 2)); + + var comp2 = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); + comp2.VerifyDiagnostics( // (11,15): warning CS8631: The type 'A?' cannot be used as type parameter 'T' in the generic type or method 'B'. Nullability of type argument 'A?' doesn't match constraint type 'A'. // [NonNullTypes(B.True)] Diagnostic(ErrorCode.WRN_NullabilityMismatchInTypeParameterConstraint, "B").WithArguments("B", "A", "T", "A?").WithLocation(11, 15)); @@ -39177,7 +39206,7 @@ struct S : INullable { } class C { }"; - var comp = CreateEmptyCompilation(new[] { source0, source }, parseOptions: TestOptions.Regular8); + var comp = CreateEmptyCompilation(new[] { source0, source }); comp.VerifyDiagnostics( // (7,11): warning CS8631: The type 'S' cannot be used as type parameter 'T' in the generic type or method 'Nullable'. Nullability of type argument 'S' doesn't match constraint type 'System.INullable'. // [A(typeof(S?))] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableTests.cs index 6dfd70db0c3..9278e796d78 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableTests.cs @@ -54,14 +54,39 @@ static void Main() Console.WriteLine(s1.ToString() + s2.ToString()); } }"; - var comp = CreateCompilation(source); + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular7_3); comp.VerifyDiagnostics( -// (7,5): error CS0453: The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable' -// string? s1 = null; -Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "string?").WithArguments("System.Nullable", "T", "string"), -// (8,14): error CS0453: The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable' -// Nullable s2 = null; -Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "string").WithArguments("System.Nullable", "T", "string") + // (7,11): error CS8370: Feature 'static null checking' is not available in C# 7.3. Please use language version 8.0 or greater. + // string? s1 = null; + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_3, "?").WithArguments("static null checking", "8.0").WithLocation(7, 11), + // (8,14): error CS0453: The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable' + // Nullable s2 = null; + Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "string").WithArguments("System.Nullable", "T", "string").WithLocation(8, 14) + ); + } + + [Fact, WorkItem(544152, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/544152")] + public void TestBug12347_CSharp8() + { + string source = @" +using System; +class C +{ + static void Main() + { + string? s1 = null; + Nullable s2 = null; + Console.WriteLine(s1.ToString() + s2.ToString()); + } +}"; + var comp = CreateCompilation(source, parseOptions: TestOptions.Regular8); + comp.VerifyDiagnostics( + // (7,15): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. + // string? s1 = null; + Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "?").WithLocation(7, 15), + // (8,18): error CS0453: The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable' + // Nullable s2 = null; + Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "string").WithArguments("System.Nullable", "T", "string").WithLocation(8, 18) ); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/QueryTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/QueryTests.cs index 26747ef4643..7b51bf8d46d 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/QueryTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/QueryTests.cs @@ -991,7 +991,7 @@ public static void Main(string[] args) Initializers(2): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: , IsImplicit) (Syntax: 'let g = x * ... elect x + z') Left: - IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'let z = g + x*100') + IPropertyReferenceOperation: ? <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'let z = g + x*100') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'let z = g + x*100') Right: @@ -1030,7 +1030,7 @@ public static void Main(string[] args) Left: IPropertyReferenceOperation: System.Int32 .x { get; } (OperationKind.PropertyReference, Type: System.Int32) (Syntax: 'x') Instance Receiver: - IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'x') + IPropertyReferenceOperation: ? <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'x') Instance Receiver: IParameterReferenceOperation: <>h__TransparentIdentifier1 (OperationKind.ParameterReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'x') Right: @@ -1216,7 +1216,7 @@ public static void Main(string[] args) Initializers(2): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: , IsImplicit) (Syntax: 'from int y ... select g') Left: - IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'from int z in c3') + IPropertyReferenceOperation: ? <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'from int z in c3') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'from int z in c3') Right: @@ -1243,7 +1243,7 @@ public static void Main(string[] args) Initializers(2): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'from int y ... select g') Left: - IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier1, System.Int32 g>.<>h__TransparentIdentifier1 { get; } (OperationKind.PropertyReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'let g = x + y + z') + IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z>? <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier1, System.Int32 g>.<>h__TransparentIdentifier1 { get; } (OperationKind.PropertyReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'let g = x + y + z') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier1, System.Int32 g>, IsImplicit) (Syntax: 'let g = x + y + z') Right: @@ -1260,13 +1260,13 @@ public static void Main(string[] args) Left: IPropertyReferenceOperation: System.Int32 .x { get; } (OperationKind.PropertyReference, Type: System.Int32) (Syntax: 'x') Instance Receiver: - IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'x') + IPropertyReferenceOperation: ? <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'x') Instance Receiver: IParameterReferenceOperation: <>h__TransparentIdentifier1 (OperationKind.ParameterReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'x') Right: IPropertyReferenceOperation: System.Int32 .y { get; } (OperationKind.PropertyReference, Type: System.Int32) (Syntax: 'y') Instance Receiver: - IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'y') + IPropertyReferenceOperation: ? <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'y') Instance Receiver: IParameterReferenceOperation: <>h__TransparentIdentifier1 (OperationKind.ParameterReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'y') Right: @@ -1292,9 +1292,9 @@ public static void Main(string[] args) Left: IPropertyReferenceOperation: System.Int32 .x { get; } (OperationKind.PropertyReference, Type: System.Int32) (Syntax: 'x') Instance Receiver: - IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'x') + IPropertyReferenceOperation: ? <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'x') Instance Receiver: - IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier1, System.Int32 g>.<>h__TransparentIdentifier1 { get; } (OperationKind.PropertyReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'x') + IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z>? <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier1, System.Int32 g>.<>h__TransparentIdentifier1 { get; } (OperationKind.PropertyReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'x') Instance Receiver: IParameterReferenceOperation: <>h__TransparentIdentifier2 (OperationKind.ParameterReference, Type: <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier1, System.Int32 g>, IsImplicit) (Syntax: 'x') Right: @@ -1302,9 +1302,9 @@ public static void Main(string[] args) Left: IPropertyReferenceOperation: System.Int32 .y { get; } (OperationKind.PropertyReference, Type: System.Int32) (Syntax: 'y') Instance Receiver: - IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'y') + IPropertyReferenceOperation: ? <>h__TransparentIdentifier0, System.Int32 z>.<>h__TransparentIdentifier0 { get; } (OperationKind.PropertyReference, Type: , IsImplicit) (Syntax: 'y') Instance Receiver: - IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier1, System.Int32 g>.<>h__TransparentIdentifier1 { get; } (OperationKind.PropertyReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'y') + IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z>? <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier1, System.Int32 g>.<>h__TransparentIdentifier1 { get; } (OperationKind.PropertyReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'y') Instance Receiver: IParameterReferenceOperation: <>h__TransparentIdentifier2 (OperationKind.ParameterReference, Type: <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier1, System.Int32 g>, IsImplicit) (Syntax: 'y') Right: @@ -1314,7 +1314,7 @@ public static void Main(string[] args) Left: IPropertyReferenceOperation: System.Int32 <>h__TransparentIdentifier0, System.Int32 z>.z { get; } (OperationKind.PropertyReference, Type: System.Int32) (Syntax: 'z') Instance Receiver: - IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier1, System.Int32 g>.<>h__TransparentIdentifier1 { get; } (OperationKind.PropertyReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'z') + IPropertyReferenceOperation: <>h__TransparentIdentifier0, System.Int32 z>? <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier1, System.Int32 g>.<>h__TransparentIdentifier1 { get; } (OperationKind.PropertyReference, Type: <>h__TransparentIdentifier0, System.Int32 z>, IsImplicit) (Syntax: 'z') Instance Receiver: IParameterReferenceOperation: <>h__TransparentIdentifier2 (OperationKind.ParameterReference, Type: <>h__TransparentIdentifier0, System.Int32 z> <>h__TransparentIdentifier1, System.Int32 g>, IsImplicit) (Syntax: 'z') Right: @@ -3656,7 +3656,7 @@ where x.ToString() == y.ToString() IParameterReferenceOperation: x (OperationKind.ParameterReference, Type: System.Int32, IsImplicit) (Syntax: 'from y in q') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: Q, IsInvalid, IsImplicit) (Syntax: 'from y in q ... .ToString()') Left: - IPropertyReferenceOperation: Q y>.y { get; } (OperationKind.PropertyReference, Type: Q, IsImplicit) (Syntax: 'from y in q') + IPropertyReferenceOperation: Q? y>.y { get; } (OperationKind.PropertyReference, Type: Q, IsImplicit) (Syntax: 'from y in q') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: y>, IsImplicit) (Syntax: 'from y in q') Right: @@ -3682,7 +3682,7 @@ where x.ToString() == y.ToString() Right: IInvocationOperation (virtual System.String System.Object.ToString()) (OperationKind.Invocation, Type: System.String) (Syntax: 'y.ToString()') Instance Receiver: - IPropertyReferenceOperation: Q y>.y { get; } (OperationKind.PropertyReference, Type: Q) (Syntax: 'y') + IPropertyReferenceOperation: Q? y>.y { get; } (OperationKind.PropertyReference, Type: Q) (Syntax: 'y') Instance Receiver: IParameterReferenceOperation: <>h__TransparentIdentifier0 (OperationKind.ParameterReference, Type: y>, IsImplicit) (Syntax: 'y') Arguments(0) diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs index 4f522b81bdc..1d573790f6c 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs @@ -644,7 +644,7 @@ void M() TestAnonymousTypePropertySymbol(model, tree.FindNodeOrTokenByKind(SyntaxKind.AnonymousObjectMemberDeclarator, 2).AsNode(), - "System.String .b { get; }"); + "System.String? .b { get; }"); } [Fact] @@ -665,7 +665,7 @@ void M() TestAnonymousTypePropertySymbol(model, tree.FindNodeOrTokenByKind(SyntaxKind.AnonymousObjectMemberDeclarator, 1).AsNode(), - "error .a { get; }"); + "error? .a { get; }"); TestAnonymousTypePropertySymbol(model, tree.FindNodeOrTokenByKind(SyntaxKind.AnonymousObjectMemberDeclarator, 2).AsNode(), @@ -677,7 +677,7 @@ void M() TestAnonymousTypePropertySymbol(model, tree.FindNodeOrTokenByKind(SyntaxKind.AnonymousObjectMemberDeclarator, 4).AsNode(), - "error .c { get; }"); + "error? .c { get; }"); } private void TestAnonymousTypePropertySymbol(SemanticModel model, SyntaxNode node, string name) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/AnonymousTypesSemanticsTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/AnonymousTypesSemanticsTests.cs index d0654a87e16..f893f3211a5 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/AnonymousTypesSemanticsTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/AnonymousTypesSemanticsTests.cs @@ -158,7 +158,7 @@ public int aa ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, Constant: """") (Syntax: 'BB = """"') Left: - IPropertyReferenceOperation: System.String .BB { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'BB') + IPropertyReferenceOperation: System.String? .BB { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'BB') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'new ... }') Right: @@ -205,7 +205,7 @@ public int aa ILiteralOperation (OperationKind.Literal, Type: System.Double, Constant: 123.456) (Syntax: '123.456') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ) (Syntax: 'CCC = new ... }') Left: - IPropertyReferenceOperation: CCC>.CCC { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'CCC') + IPropertyReferenceOperation: ? CCC>.CCC { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'CCC') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: CCC>, IsImplicit) (Syntax: 'new ... }') Right: @@ -225,7 +225,7 @@ public int aa null ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, Constant: ""-=-= -"", IsImplicit) (Syntax: 'ClassA.BB') Left: - IPropertyReferenceOperation: System.String .BB { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'ClassA.BB') + IPropertyReferenceOperation: System.String? .BB { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'ClassA.BB') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'new ... }') Right: @@ -314,7 +314,7 @@ public int select info0.Type.ToTestDisplayString()); Assert.Equal( - "..ctor(System.Int32 select, System.String global)", + "..ctor(System.Int32 select, System.String? global)", info1.Symbol.ToTestDisplayString()); } @@ -352,14 +352,14 @@ public int select Initializers(3): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, Constant: ""var"") (Syntax: 'var = ""var""') Left: - IPropertyReferenceOperation: System.String get, partial>.var { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'var') + IPropertyReferenceOperation: System.String? get, partial>.var { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'var') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: get, partial>, IsImplicit) (Syntax: 'new ... }') Right: ILiteralOperation (OperationKind.Literal, Type: System.String, Constant: ""var"") (Syntax: '""var""') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ) (Syntax: 'get = new { }') Left: - IPropertyReferenceOperation: get, partial>.get { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'get') + IPropertyReferenceOperation: ? get, partial>.get { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'get') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: get, partial>, IsImplicit) (Syntax: 'new ... }') Right: @@ -367,7 +367,7 @@ public int select Initializers(0) ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ) (Syntax: 'partial = n ... }') Left: - IPropertyReferenceOperation: get, partial>.partial { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'partial') + IPropertyReferenceOperation: ? get, partial>.partial { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'partial') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: get, partial>, IsImplicit) (Syntax: 'new ... }') Right: @@ -387,7 +387,7 @@ public int select null ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, Constant: "" -=-= -"", IsImplicit) (Syntax: 'global') Left: - IPropertyReferenceOperation: System.String .global { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'global') + IPropertyReferenceOperation: System.String? .global { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'global') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'new ... }') Right: @@ -419,7 +419,7 @@ void Main() 1); Assert.Equal("", info0.Type.ToTestDisplayString()); - Assert.Equal("..ctor(D1 module)", info0.Symbol.ToTestDisplayString()); + Assert.Equal("..ctor(D1? module)", info0.Symbol.ToTestDisplayString()); } [CompilerTrait(CompilerFeature.IOperation)] @@ -441,7 +441,7 @@ void Main() Initializers(1): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: D1) (Syntax: 'module = (D ... ) => false)') Left: - IPropertyReferenceOperation: D1 .module { get; } (OperationKind.PropertyReference, Type: D1) (Syntax: 'module') + IPropertyReferenceOperation: D1? .module { get; } (OperationKind.PropertyReference, Type: D1) (Syntax: 'module') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'new { modul ... => false) }') Right: @@ -510,7 +510,7 @@ void Main() Initializers(1): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.Func, IsImplicit) (Syntax: 'base.F') Left: - IPropertyReferenceOperation: System.Func F>.F { get; } (OperationKind.PropertyReference, Type: System.Func, IsImplicit) (Syntax: 'base.F') + IPropertyReferenceOperation: System.Func? F>.F { get; } (OperationKind.PropertyReference, Type: System.Func, IsImplicit) (Syntax: 'base.F') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: F>, IsImplicit) (Syntax: 'new { base.F }') Right: @@ -555,7 +555,7 @@ class ClassA Initializers(1): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.Type) (Syntax: 'F123 = typeof(ClassA)') Left: - IPropertyReferenceOperation: System.Type .F123 { get; } (OperationKind.PropertyReference, Type: System.Type) (Syntax: 'F123') + IPropertyReferenceOperation: System.Type? .F123 { get; } (OperationKind.PropertyReference, Type: System.Type) (Syntax: 'F123') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'new { F123 ... f(ClassA) }') Right: @@ -615,7 +615,7 @@ static void Test1(int x) ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, Constant: """") (Syntax: 'f2 = """"') Left: - IPropertyReferenceOperation: System.String .f2 { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'f2') + IPropertyReferenceOperation: System.String? .f2 { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'f2') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'new { f1 = 1, f2 = """" }') Right: @@ -695,8 +695,8 @@ static void Test1(int x) var method = info.Symbol; Assert.NotNull(method); Assert.Equal(SymbolKind.Method, method.Kind); - Assert.Equal("..ctor(int, string)", method.ToDisplayString()); - Assert.Equal("..ctor(System.Int32 f1, System.String f2)", method.ToTestDisplayString()); + Assert.Equal("..ctor(int, string?)", method.ToDisplayString()); + Assert.Equal("..ctor(System.Int32 f1, System.String? f2)", method.ToTestDisplayString()); } [Fact()] @@ -750,7 +750,7 @@ class ClassA var info = data.Model.GetSymbolInfo((ExpressionSyntax)data.Nodes[0]); Assert.NotNull(info.Symbol); Assert.Equal(SymbolKind.Property, info.Symbol.Kind); - Assert.Equal("System.Type .F123 { get; }", info.Symbol.ToTestDisplayString()); + Assert.Equal("System.Type? .F123 { get; }", info.Symbol.ToTestDisplayString()); } [Fact()] @@ -881,11 +881,11 @@ void m() IParameterReferenceOperation: <>h__TransparentIdentifier0 (OperationKind.ParameterReference, Type: , IsImplicit) (Syntax: 'x') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, IsImplicit) (Syntax: 'y') Left: - IPropertyReferenceOperation: System.String .y { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'y') + IPropertyReferenceOperation: System.String? .y { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'y') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'new { x, y }') Right: - IPropertyReferenceOperation: System.String .y { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'y') + IPropertyReferenceOperation: System.String? .y { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'y') Instance Receiver: IParameterReferenceOperation: <>h__TransparentIdentifier0 (OperationKind.ParameterReference, Type: , IsImplicit) (Syntax: 'y') "; @@ -915,7 +915,7 @@ void m() var info1 = GetAnonymousTypeInfoSummary(data, 3, data.Tree.FindNodeOrTokenByKind(SyntaxKind.NewKeyword, 2).Span); - Assert.Equal(" y>..ctor(System.Int32 x, y)", info0.Symbol.ToTestDisplayString()); + Assert.Equal(" y>..ctor(System.Int32 x, ? y)", info0.Symbol.ToTestDisplayString()); } [CompilerTrait(CompilerFeature.IOperation)] @@ -944,7 +944,7 @@ void m() ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ) (Syntax: 'y = new { }') Left: - IPropertyReferenceOperation: y>.y { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'y') + IPropertyReferenceOperation: ? y>.y { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'y') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: y>, IsImplicit) (Syntax: 'new { x = 1 ... = new { } }') Right: @@ -980,7 +980,7 @@ void m() var info1 = GetAnonymousTypeInfoSummary(data, 3, data.Tree.FindNodeOrTokenByKind(SyntaxKind.NewKeyword, 2).Span); - Assert.Equal(" y>..ctor(System.Int32 x, y)", info0.Symbol.ToTestDisplayString()); + Assert.Equal(" y>..ctor(System.Int32 x, ? y)", info0.Symbol.ToTestDisplayString()); } [CompilerTrait(CompilerFeature.IOperation)] @@ -1012,7 +1012,7 @@ void m() ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ) (Syntax: 'y = new { }') Left: - IPropertyReferenceOperation: y>.y { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'y') + IPropertyReferenceOperation: ? y>.y { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'y') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: y>, IsImplicit) (Syntax: 'new { x = 1 ... = new { } }') Right: @@ -1189,7 +1189,7 @@ public static void Test1(int x) Initializers(3): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ?, IsInvalid) (Syntax: 'aa = xyz') Left: - IPropertyReferenceOperation: ? .aa { get; } (OperationKind.PropertyReference, Type: ?) (Syntax: 'aa') + IPropertyReferenceOperation: ?? .aa { get; } (OperationKind.PropertyReference, Type: ?) (Syntax: 'aa') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsInvalid, IsImplicit) (Syntax: 'new ... }') Right: @@ -1197,14 +1197,14 @@ public static void Test1(int x) Children(0) ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, Constant: """") (Syntax: 'BB = """"') Left: - IPropertyReferenceOperation: System.String .BB { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'BB') + IPropertyReferenceOperation: System.String? .BB { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'BB') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsInvalid, IsImplicit) (Syntax: 'new ... }') Right: ILiteralOperation (OperationKind.Literal, Type: System.String, Constant: """") (Syntax: '""""') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: SSS, IsInvalid) (Syntax: 'CCC = new SSS()') Left: - IPropertyReferenceOperation: SSS .CCC { get; } (OperationKind.PropertyReference, Type: SSS) (Syntax: 'CCC') + IPropertyReferenceOperation: SSS? .CCC { get; } (OperationKind.PropertyReference, Type: SSS) (Syntax: 'CCC') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsInvalid, IsImplicit) (Syntax: 'new ... }') Right: @@ -1225,7 +1225,7 @@ public static void Test1(int x) Initializers(3): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: SSS, IsInvalid) (Syntax: 'aa = new SSS()') Left: - IPropertyReferenceOperation: SSS CCC>.aa { get; } (OperationKind.PropertyReference, Type: SSS) (Syntax: 'aa') + IPropertyReferenceOperation: SSS? CCC>.aa { get; } (OperationKind.PropertyReference, Type: SSS) (Syntax: 'aa') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: CCC>, IsInvalid, IsImplicit) (Syntax: 'new ... }') Right: @@ -1240,7 +1240,7 @@ public static void Test1(int x) ILiteralOperation (OperationKind.Literal, Type: System.Double, Constant: 123.456) (Syntax: '123.456') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: , IsInvalid) (Syntax: 'CCC = new ... }') Left: - IPropertyReferenceOperation: CCC>.CCC { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'CCC') + IPropertyReferenceOperation: ? CCC>.CCC { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'CCC') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: CCC>, IsInvalid, IsImplicit) (Syntax: 'new ... }') Right: @@ -1248,7 +1248,7 @@ public static void Test1(int x) Initializers(3): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ?, IsInvalid, IsImplicit) (Syntax: '(new ClassA()).aa') Left: - IPropertyReferenceOperation: ? .aa { get; } (OperationKind.PropertyReference, Type: ?, IsInvalid, IsImplicit) (Syntax: '(new ClassA()).aa') + IPropertyReferenceOperation: ?? .aa { get; } (OperationKind.PropertyReference, Type: ?, IsInvalid, IsImplicit) (Syntax: '(new ClassA()).aa') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsInvalid, IsImplicit) (Syntax: 'new ... }') Right: @@ -1260,7 +1260,7 @@ public static void Test1(int x) null ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ?, IsInvalid, IsImplicit) (Syntax: 'ClassA.BB') Left: - IPropertyReferenceOperation: ? .BB { get; } (OperationKind.PropertyReference, Type: ?, IsInvalid, IsImplicit) (Syntax: 'ClassA.BB') + IPropertyReferenceOperation: ?? .BB { get; } (OperationKind.PropertyReference, Type: ?, IsInvalid, IsImplicit) (Syntax: 'ClassA.BB') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsInvalid, IsImplicit) (Syntax: 'new ... }') Right: @@ -1269,7 +1269,7 @@ public static void Test1(int x) IOperation: (OperationKind.None, Type: null) (Syntax: 'ClassA') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ?, IsInvalid, IsImplicit) (Syntax: 'ClassA.CCC') Left: - IPropertyReferenceOperation: ? .CCC { get; } (OperationKind.PropertyReference, Type: ?, IsInvalid, IsImplicit) (Syntax: 'ClassA.CCC') + IPropertyReferenceOperation: ?? .CCC { get; } (OperationKind.PropertyReference, Type: ?, IsInvalid, IsImplicit) (Syntax: 'ClassA.CCC') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsInvalid, IsImplicit) (Syntax: 'new ... }') Right: @@ -1396,7 +1396,7 @@ public static void Test1(int x) Assert.Equal(3, properties.Length); Assert.Equal("System.Int32 .aa { get; }", properties[0].ToTestDisplayString()); - Assert.Equal("System.String .$1 { get; }", properties[1].ToTestDisplayString()); + Assert.Equal("System.String? .$1 { get; }", properties[1].ToTestDisplayString()); Assert.Equal("System.Double .bb { get; }", properties[2].ToTestDisplayString()); } @@ -1432,7 +1432,7 @@ public static void Test1(int x) ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, IsInvalid, IsImplicit) (Syntax: 'ClassA.aa') Left: - IPropertyReferenceOperation: System.String .$1 { get; } (OperationKind.PropertyReference, Type: System.String, IsInvalid, IsImplicit) (Syntax: 'ClassA.aa') + IPropertyReferenceOperation: System.String? .$1 { get; } (OperationKind.PropertyReference, Type: System.String, IsInvalid, IsImplicit) (Syntax: 'ClassA.aa') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsInvalid, IsImplicit) (Syntax: 'new ... }') Right: @@ -1490,8 +1490,8 @@ public static void Test1(int x) Assert.Equal("System.Boolean System.Object.ReferenceEquals(System.Object objA, System.Object objB)", syms[index++]); Assert.Equal("System.Double .abc { get; }", syms[index++]); Assert.Equal("System.Int32 System.Object.GetHashCode()", syms[index++]); - Assert.Equal("System.String .aa { get; }", syms[index++]); Assert.Equal("System.String System.Object.ToString()", syms[index++]); + Assert.Equal("System.String? .aa { get; }", syms[index++]); Assert.Equal("System.Type System.Object.GetType()", syms[index++]); info0 = GetAnonymousTypeInfoSummary(data, 3, @@ -1620,7 +1620,7 @@ public static void Main() Initializers(1): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ) (Syntax: 'Conditional ... upplierID }') Left: - IPropertyReferenceOperation: Conditional>.Conditional { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'Conditional') + IPropertyReferenceOperation: ? Conditional>.Conditional { get; } (OperationKind.PropertyReference, Type: ) (Syntax: 'Conditional') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: Conditional>, IsImplicit) (Syntax: 'new { Condi ... plierID } }') Right: @@ -1641,7 +1641,7 @@ public static void Main() IParameterReferenceOperation: p (OperationKind.ParameterReference, Type: Product) (Syntax: 'p') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, IsImplicit) (Syntax: 'p.ProductName') Left: - IPropertyReferenceOperation: System.String .ProductName { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'p.ProductName') + IPropertyReferenceOperation: System.String? .ProductName { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'p.ProductName') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'new { p.Pro ... upplierID }') Right: @@ -1671,7 +1671,7 @@ public static void Main() IParameterReferenceOperation: p (OperationKind.ParameterReference, Type: Product) (Syntax: 'p') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.String, IsImplicit) (Syntax: 'p.ProductName') Left: - IPropertyReferenceOperation: System.String .ProductName { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'p.ProductName') + IPropertyReferenceOperation: System.String? .ProductName { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'p.ProductName') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsImplicit) (Syntax: 'new { p.Pro ... upplierID }') Right: @@ -1705,6 +1705,7 @@ public static void Main() VerifyOperationTreeAndDiagnosticsForTest(source, expectedOperationTree, expectedDiagnostics); } + [WorkItem(546416, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546416")] [ClrOnlyFact] public void TestAnonymousTypeInsideGroupBy_Enumerable() @@ -1785,14 +1786,14 @@ static void M() Initializers(3): ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: error, Constant: null, IsInvalid) (Syntax: 'f1 = null') Left: - IPropertyReferenceOperation: error .f1 { get; } (OperationKind.PropertyReference, Type: error, IsInvalid) (Syntax: 'f1') + IPropertyReferenceOperation: error? .f1 { get; } (OperationKind.PropertyReference, Type: error, IsInvalid) (Syntax: 'f1') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsInvalid, IsImplicit) (Syntax: 'new { f1 = ... = default }') Right: ILiteralOperation (OperationKind.Literal, Type: null, Constant: null, IsInvalid) (Syntax: 'null') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: error, IsInvalid) (Syntax: 'f2 = M') Left: - IPropertyReferenceOperation: error .f2 { get; } (OperationKind.PropertyReference, Type: error, IsInvalid) (Syntax: 'f2') + IPropertyReferenceOperation: error? .f2 { get; } (OperationKind.PropertyReference, Type: error, IsInvalid) (Syntax: 'f2') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsInvalid, IsImplicit) (Syntax: 'new { f1 = ... = default }') Right: @@ -1801,7 +1802,7 @@ static void M() IInstanceReferenceOperation (ReferenceKind: ContainingTypeInstance) (OperationKind.InstanceReference, Type: ClassA, IsInvalid, IsImplicit) (Syntax: 'M') ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: error, IsInvalid) (Syntax: 'f3 = default') Left: - IPropertyReferenceOperation: error .f3 { get; } (OperationKind.PropertyReference, Type: error, IsInvalid) (Syntax: 'f3') + IPropertyReferenceOperation: error? .f3 { get; } (OperationKind.PropertyReference, Type: error, IsInvalid) (Syntax: 'f3') Instance Receiver: IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: , IsInvalid, IsImplicit) (Syntax: 'new { f1 = ... = default }') Right: diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs index 0117026fabd..d91a6278f74 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs @@ -5605,12 +5605,24 @@ class B : A } "; CreateCompilation(source, options: TestOptions.ReleaseDll).VerifyDiagnostics( - // (4,23): error CS0453: The type 'T' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable' + // (4,20): error CS8627: A nullable type parameter must be known to be a value or reference type. Consider adding a 'class', 'struct', or type constraint. // public virtual T? Goo() - Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "Goo").WithArguments("System.Nullable", "T", "T"), - // (12,24): error CS0453: The type 'T' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable' + Diagnostic(ErrorCode.ERR_NullableUnconstrainedTypeParameter, "T?").WithLocation(4, 20), + // (4,20): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. + // public virtual T? Goo() + Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "T?").WithLocation(4, 20), + // (12,21): error CS8627: A nullable type parameter must be known to be a value or reference type. Consider adding a 'class', 'struct', or type constraint. + // public override T? Goo() + Diagnostic(ErrorCode.ERR_NullableUnconstrainedTypeParameter, "T?").WithLocation(12, 21), + // (12,21): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // public override T? Goo() - Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "Goo").WithArguments("System.Nullable", "T", "T")); + Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "T?").WithLocation(12, 21), + // (6,16): error CS0403: Cannot convert null to type parameter 'T' because it could be a non-nullable value type. Consider using 'default(T)' instead. + // return null; + Diagnostic(ErrorCode.ERR_TypeVarCantBeNull, "null").WithArguments("T").WithLocation(6, 16), + // (14,16): error CS0403: Cannot convert null to type parameter 'T' because it could be a non-nullable value type. Consider using 'default(T)' instead. + // return null; + Diagnostic(ErrorCode.ERR_TypeVarCantBeNull, "null").WithArguments("T").WithLocation(14, 16)); } [WorkItem(543710, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543710")] @@ -6328,17 +6340,13 @@ public struct S public class E { } "; - CreateCompilation(source).VerifyDiagnostics( - // (4,5): error CS0453: The type 'E' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable' + // (4,10): warning CS8632: The annotation for nullable reference types should only be used in code within a '[NonNullTypes(true)]' context. // E?[] eNullableArr; - Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "E?").WithArguments("System.Nullable", "T", "E"), - // (6,28): error CS0453: The type 'E' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable' - // public void Test() { DoSomething(this.eNullableArr); } - Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "DoSomething").WithArguments("System.Nullable", "T", "E"), + Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "eNullableArr").WithLocation(4, 10), // (4,10): warning CS0649: Field 'S.eNullableArr' is never assigned to, and will always have its default value null // E?[] eNullableArr; - Diagnostic(ErrorCode.WRN_UnassignedInternalField, "eNullableArr").WithArguments("S.eNullableArr", "null")); + Diagnostic(ErrorCode.WRN_UnassignedInternalField, "eNullableArr").WithArguments("S.eNullableArr", "null").WithLocation(4, 10)); } [WorkItem(575455, "DevDiv")] diff --git a/src/Compilers/Core/Portable/MetadataReader/PEModule.cs b/src/Compilers/Core/Portable/MetadataReader/PEModule.cs index cddc21b5b19..b3832d7bfcf 100644 --- a/src/Compilers/Core/Portable/MetadataReader/PEModule.cs +++ b/src/Compilers/Core/Portable/MetadataReader/PEModule.cs @@ -67,11 +67,6 @@ internal sealed class PEModule : IDisposable /// private int[] _lazyNoPiaLocalTypeCheckBitMap; - /// - /// Using as a type for atomicity. - /// - private ThreeState _lazyUtilizesNullableReferenceTypes; - /// /// For each TypeDef that has 1 in m_lazyNoPiaLocalTypeCheckBitMap, /// this map stores corresponding TypeIdentifier AttributeInfo. @@ -115,7 +110,6 @@ internal PEModule(ModuleMetadata owner, PEReader peReader, IntPtr metadataOpt, i _lazyNamespaceNameCollection = new Lazy(ComputeNamespaceNameCollection); _hashesOpt = (peReader != null) ? new PEHashProvider(peReader) : null; _lazyContainsNoPiaLocalTypes = includeEmbeddedInteropTypes ? ThreeState.False : ThreeState.Unknown; - _lazyUtilizesNullableReferenceTypes = ThreeState.Unknown; if (ignoreAssemblyRefs) { @@ -2399,31 +2393,6 @@ internal bool ContainsNoPiaLocalTypes() return _lazyContainsNoPiaLocalTypes == ThreeState.True; } - // PROTOTYPE(NullableReferenceTypes): This method should be removed - internal bool UtilizesNullableReferenceTypes() - { - if (_lazyUtilizesNullableReferenceTypes == ThreeState.Unknown) - { - try - { - AttributeInfo info = FindTargetAttribute(EntityHandle.ModuleDefinition, AttributeDescription.NullableAttribute); - Debug.Assert(!info.HasValue || info.SignatureIndex == 0 || info.SignatureIndex == 1); - - if (info.HasValue && info.SignatureIndex == 0) - { - _lazyUtilizesNullableReferenceTypes = ThreeState.True; - return true; - } - } - catch (BadImageFormatException) - { } - - _lazyUtilizesNullableReferenceTypes = ThreeState.False; - } - - return _lazyUtilizesNullableReferenceTypes == ThreeState.True; - } - internal bool HasNullableAttribute(EntityHandle token, out ImmutableArray nullableTransforms) { AttributeInfo info = FindTargetAttribute(token, AttributeDescription.NullableAttribute); diff --git a/src/Compilers/Test/Utilities/CSharp/TestOptions.cs b/src/Compilers/Test/Utilities/CSharp/TestOptions.cs index d8346a341b0..bddfcced3b9 100644 --- a/src/Compilers/Test/Utilities/CSharp/TestOptions.cs +++ b/src/Compilers/Test/Utilities/CSharp/TestOptions.cs @@ -12,9 +12,9 @@ public static class TestOptions // document every public member of every test input. // PROTOTYPE(NullableReferenceTypes): Use default for LanguageVersion rather than LanguageVersion.CSharp7.3. public static readonly CSharpParseOptions RegularDefault = new CSharpParseOptions(kind: SourceCodeKind.Regular, documentationMode: DocumentationMode.Parse); - public static readonly CSharpParseOptions Regular = RegularDefault.WithLanguageVersion(LanguageVersion.CSharp7_3); + public static readonly CSharpParseOptions Regular = RegularDefault.WithLanguageVersion(LanguageVersion.CSharp8); public static readonly CSharpParseOptions ScriptDefault = new CSharpParseOptions(kind: SourceCodeKind.Script, documentationMode: DocumentationMode.Parse); - public static readonly CSharpParseOptions Script = ScriptDefault.WithLanguageVersion(LanguageVersion.CSharp7_3); + public static readonly CSharpParseOptions Script = ScriptDefault.WithLanguageVersion(LanguageVersion.CSharp8); public static readonly CSharpParseOptions Regular6 = RegularDefault.WithLanguageVersion(LanguageVersion.CSharp6); public static readonly CSharpParseOptions Regular7 = RegularDefault.WithLanguageVersion(LanguageVersion.CSharp7); public static readonly CSharpParseOptions Regular7_1 = RegularDefault.WithLanguageVersion(LanguageVersion.CSharp7_1); diff --git a/src/Test/Utilities/Portable/Compilation/OperationTreeVerifier.cs b/src/Test/Utilities/Portable/Compilation/OperationTreeVerifier.cs index e152c4686fc..b2850b1ff3f 100644 --- a/src/Test/Utilities/Portable/Compilation/OperationTreeVerifier.cs +++ b/src/Test/Utilities/Portable/Compilation/OperationTreeVerifier.cs @@ -54,8 +54,10 @@ public static void Verify(string expectedOperationTree, string actualOperationTr { char[] newLineChars = Environment.NewLine.ToCharArray(); string actual = actualOperationTree.Trim(newLineChars); + actual = actual.Replace("\"", "\"\""); expectedOperationTree = expectedOperationTree.Trim(newLineChars); expectedOperationTree = expectedOperationTree.Replace("\r\n", "\n").Replace("\n", Environment.NewLine); + expectedOperationTree = expectedOperationTree.Replace("\"", "\"\""); AssertEx.AreEqual(expectedOperationTree, actual); } diff --git a/src/VisualStudio/Core/Test/ObjectBrowser/CSharp/ObjectBrowerTests.vb b/src/VisualStudio/Core/Test/ObjectBrowser/CSharp/ObjectBrowerTests.vb index e758a4295a7..e107791fcc4 100644 --- a/src/VisualStudio/Core/Test/ObjectBrowser/CSharp/ObjectBrowerTests.vb +++ b/src/VisualStudio/Core/Test/ObjectBrowser/CSharp/ObjectBrowerTests.vb @@ -141,7 +141,7 @@ namespace N Using state = CreateLibraryManager(GetWorkspaceDefinition(code, metaDatacode, False)) Dim library = state.GetLibrary() - Dim list = library.GetProjectList().GetReferenceList(0).GetNamespaceList(0).GetTypeList(1) + Dim list = library.GetProjectList().GetReferenceList(0).GetNamespaceList(0).GetTypeList(0) list.VerifyNames("C", "C.PublicEnumTest") End Using End Sub -- GitLab