未验证 提交 2df93864 编写于 作者: J Julien Couvreur 提交者: GitHub

Update default test options to C# 8.0 (#29225)

上级 23e2d28d
......@@ -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);
......
......@@ -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<Declaration, NamespaceOrTypeSymbol> _cache;
......
......@@ -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;
}
}
......
......@@ -9,18 +9,20 @@ namespace Microsoft.CodeAnalysis.CSharp
/// </summary>
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);
}
}
}
......@@ -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.
......
......@@ -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();
}
......
......@@ -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);
}
}
}
......
......@@ -697,22 +697,11 @@ internal IEnumerable<NamedTypeSymbol> 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;
}
}
}
......
......@@ -214,10 +214,7 @@ private ImmutableArray<TypeSymbolWithAnnotations> 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<TypeParameterSymbol> 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<TypeParameterDiagnosticInfo>.GetInstance();
ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null;
bool inherited = (_containingSymbol.Kind == SymbolKind.Method) && ((MethodSymbol)_containingSymbol).IsOverride;
......
......@@ -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; }
......
......@@ -197,14 +197,6 @@ public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
}
}
public override bool? NonNullTypes
{
get
{
return this.UtilizesNullableReferenceTypes;
}
}
/// <summary>
/// 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)
/// </summary>
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; }
/// <summary>
/// Default char set for contained types, or null if not specified.
/// </summary>
......
......@@ -271,15 +271,6 @@ internal override bool HasAssemblyRuntimeCompatibilityAttribute
}
}
internal override bool UtilizesNullableReferenceTypes
{
get
{
return _underlyingModule.UtilizesNullableReferenceTypes;
}
}
internal override CharSet? DefaultMarshallingCharSet
{
get
......
......@@ -144,13 +144,13 @@ internal static void EnsureNullableAttributeExists(ImmutableArray<ParameterSymbo
}
}
internal static void ReportMissingNonNullTypesContextForAnnotation(ImmutableArray<ParameterSymbol> parameters, DiagnosticBag diagnostics)
internal static void ReportNullableReferenceTypesIfNeeded(ImmutableArray<ParameterSymbol> parameters, DiagnosticBag diagnostics)
{
foreach (var parameter in parameters)
{
if (parameter.Type.ContainsNullableReferenceTypes())
{
parameter.ReportMissingNonNullTypesContextForAnnotation(diagnostics, parameter.GetNonNullSyntaxNode().Location);
parameter.ReportNullableReferenceTypesIfNeeded(diagnostics, parameter.GetNonNullSyntaxNode().Location);
}
}
}
......
......@@ -875,7 +875,7 @@ internal SourceModuleSymbol SourceModule
{
get
{
return SourceModule.UtilizesNullableReferenceTypes;
return SourceModule.NonNullTypes;
}
}
......
......@@ -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()
......
......@@ -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<CustomModifier> RefCustomModifiers => _refCustomModifiers;
......
......@@ -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);
}
}
}
......
......@@ -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);
}
}
......
......@@ -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);
}
}
......
......@@ -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<TypedConstant>.Empty));
}
}
internal override bool UtilizesNullableReferenceTypes
{
get
{
return _assemblySymbol.DeclaringCompilation.IsFeatureEnabled(MessageID.IDS_FeatureStaticNullChecking);
}
}
internal override bool HasAssemblyCompilationRelaxationsAttribute
......
......@@ -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);
}
/// <summary>
......
......@@ -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)
......
......@@ -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);
}
}
}
......@@ -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)
/// <summary>
/// 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
/// </summary>
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()
......
......@@ -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<T> 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);
......
......@@ -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<object>
public class B2 : A<object?>
{
}";
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<object?>' for parameter 'y' in 'void C.F(A<object> x, A<object?> 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<CSharpAttributeData> 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));
}
}
......
......@@ -379,7 +379,7 @@ void M(object p, List<int> a, List<string> 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 <anonymous type: System.Int32 x, System.String y>.y { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'from y in b')
IPropertyReferenceOperation: System.String? <anonymous type: System.Int32 x, System.String y>.y { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'from y in b')
Instance Receiver:
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <anonymous type: System.Int32 x, System.String y>, 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: <anonymous type: System.Int32 a, System.Int32 b>) (Syntax: 'b = new { a ... 2, b = i3 }')
Left:
IPropertyReferenceOperation: <anonymous type: System.Int32 a, System.Int32 b> <anonymous type: System.Int32 a, <anonymous type: System.Int32 a, System.Int32 b> b>.b { get; } (OperationKind.PropertyReference, Type: <anonymous type: System.Int32 a, System.Int32 b>) (Syntax: 'b')
IPropertyReferenceOperation: <anonymous type: System.Int32 a, System.Int32 b>? <anonymous type: System.Int32 a, <anonymous type: System.Int32 a, System.Int32 b> b>.b { get; } (OperationKind.PropertyReference, Type: <anonymous type: System.Int32 a, System.Int32 b>) (Syntax: 'b')
Instance Receiver:
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <anonymous type: System.Int32 a, <anonymous type: System.Int32 a, System.Int32 b> 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: ? <anonymous type: ? a>.a { get; } (OperationKind.PropertyReference, Type: ?) (Syntax: 'a')
IPropertyReferenceOperation: ?? <anonymous type: ? a>.a { get; } (OperationKind.PropertyReference, Type: ?) (Syntax: 'a')
Instance Receiver:
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <anonymous type: ? a>, 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: ? <anonymous type: ? $0>.$0 { get; } (OperationKind.PropertyReference, Type: ?, IsInvalid, IsImplicit) (Syntax: 'a[i] = j')
IPropertyReferenceOperation: ?? <anonymous type: ? $0>.$0 { get; } (OperationKind.PropertyReference, Type: ?, IsInvalid, IsImplicit) (Syntax: 'a[i] = j')
Instance Receiver:
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <anonymous type: ? $0>, IsInvalid, IsImplicit) (Syntax: 'new { a[i] = j }')
Right:
......
......@@ -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 <anonymous type: System.Char x, System.String z>.z { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'x.ToString()')
IPropertyReferenceOperation: System.String? <anonymous type: System.Char x, System.String z>.z { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'x.ToString()')
Instance Receiver:
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <anonymous type: System.Char x, System.String z>, 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 <anonymous type: System.Char x, System.String z>.z { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'z')
IPropertyReferenceOperation: System.String? <anonymous type: System.Char x, System.String z>.z { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'z')
Instance Receiver:
IParameterReferenceOperation: <>h__TransparentIdentifier0 (OperationKind.ParameterReference, Type: <anonymous type: System.Char x, System.String z>, IsImplicit) (Syntax: 'z')
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
......@@ -2099,7 +2099,7 @@ private static IEnumerable<string> 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 <anonymous type: System.Char x, System.String z>.z { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'x.ToString()')
IPropertyReferenceOperation: System.String? <anonymous type: System.Char x, System.String z>.z { get; } (OperationKind.PropertyReference, Type: System.String, IsImplicit) (Syntax: 'x.ToString()')
Instance Receiver:
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <anonymous type: System.Char x, System.String z>, IsImplicit) (Syntax: 'let z = x.ToString()')
Right:
......@@ -2118,7 +2118,7 @@ private static IEnumerable<string> fun()
IBlockOperation (1 statements) (OperationKind.Block, Type: null, IsImplicit) (Syntax: 'z')
IReturnOperation (OperationKind.Return, Type: null, IsImplicit) (Syntax: 'z')
ReturnedValue:
IPropertyReferenceOperation: System.String <anonymous type: System.Char x, System.String z>.z { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'z')
IPropertyReferenceOperation: System.String? <anonymous type: System.Char x, System.String z>.z { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'z')
Instance Receiver:
IParameterReferenceOperation: <>h__TransparentIdentifier0 (OperationKind.ParameterReference, Type: <anonymous type: System.Char x, System.String z>, IsImplicit) (Syntax: 'z')
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
......
......@@ -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 <anonymous type: System.Int32 Amount, System.String Message>.Message { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'Message')
IPropertyReferenceOperation: System.String? <anonymous type: System.Int32 Amount, System.String Message>.Message { get; } (OperationKind.PropertyReference, Type: System.String) (Syntax: 'Message')
Instance Receiver:
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <anonymous type: System.Int32 Amount, System.String Message>, IsImplicit) (Syntax: 'new { Amoun ... ello"" + y }')
Right:
......
......@@ -2241,9 +2241,54 @@ void Goo(System.Collections.Generic.IEnumerable<C>? 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<C>? e)
Diagnostic(ErrorCode.WRN_MissingNonNullTypesContextForAnnotation, "System.Collections.Generic.IEnumerable<C>? 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<T> { }
public struct Boolean { }
}
namespace System.Collections.Generic
{
public interface IEnumerable<T>
{
IEnumerator<T> GetEnumerator();
}
public interface IEnumerator<T>
{
T Current { get; }
bool MoveNext();
}
}
class C
{
void Goo(System.Collections.Generic.IEnumerable<C>? 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<C>? e)
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_3, "System.Collections.Generic.IEnumerable<C>? e").WithArguments("static null checking", "8.0").WithLocation(28, 14)
);
}
[WorkItem(798000, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/798000")]
......
......@@ -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<T>'
// string? s1 = null;
Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "string?").WithArguments("System.Nullable<T>", "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<T>'
// Nullable<string> s2 = null;
Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "string").WithArguments("System.Nullable<T>", "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<T>'
// Nullable<string> s2 = null;
Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "string").WithArguments("System.Nullable<T>", "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<string> 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<T>'
// Nullable<string> s2 = null;
Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "string").WithArguments("System.Nullable<T>", "T", "string").WithLocation(8, 18)
);
}
......
......@@ -644,7 +644,7 @@ void M()
TestAnonymousTypePropertySymbol(model,
tree.FindNodeOrTokenByKind(SyntaxKind.AnonymousObjectMemberDeclarator, 2).AsNode(),
"System.String <anonymous type: System.Int32 a, System.String b>.b { get; }");
"System.String? <anonymous type: System.Int32 a, System.String b>.b { get; }");
}
[Fact]
......@@ -665,7 +665,7 @@ void M()
TestAnonymousTypePropertySymbol(model,
tree.FindNodeOrTokenByKind(SyntaxKind.AnonymousObjectMemberDeclarator, 1).AsNode(),
"error <anonymous type: error a, System.Int32 $1, System.Int32 b, error c>.a { get; }");
"error? <anonymous type: error a, System.Int32 $1, System.Int32 b, error c>.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 <anonymous type: error a, System.Int32 $1, System.Int32 b, error c>.c { get; }");
"error? <anonymous type: error a, System.Int32 $1, System.Int32 b, error c>.c { get; }");
}
private void TestAnonymousTypePropertySymbol(SemanticModel model, SyntaxNode node, string name)
......
......@@ -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<T>'
// (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<T>()
Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "Goo").WithArguments("System.Nullable<T>", "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<T>'
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<T>()
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<T>()
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<T>()
Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "Goo").WithArguments("System.Nullable<T>", "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<T>'
// (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>", "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<T>'
// public void Test() { DoSomething(this.eNullableArr); }
Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "DoSomething").WithArguments("System.Nullable<T>", "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")]
......
......@@ -67,11 +67,6 @@ internal sealed class PEModule : IDisposable
/// </summary>
private int[] _lazyNoPiaLocalTypeCheckBitMap;
/// <summary>
/// Using <see cref="ThreeState"/> as a type for atomicity.
/// </summary>
private ThreeState _lazyUtilizesNullableReferenceTypes;
/// <summary>
/// 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<IdentifierCollection>(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<bool> nullableTransforms)
{
AttributeInfo info = FindTargetAttribute(token, AttributeDescription.NullableAttribute);
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册