提交 c1a0658e 编写于 作者: C Charles Stoner

Misc. changes following merge 'upstream/master'

上级 037ce5aa
...@@ -124,7 +124,7 @@ internal static IArgument CreateArgumentOperation(ArgumentKind kind, IParameterS ...@@ -124,7 +124,7 @@ internal static IArgument CreateArgumentOperation(ArgumentKind kind, IParameterS
// is undefined. // is undefined.
if ((object)optionalParametersMethod == null if ((object)optionalParametersMethod == null
|| n.HasAnyErrors || n.HasAnyErrors
|| parameters.Any(p => p.Type.IsErrorType()) || parameters.Any(p => p.Type.TypeSymbol.IsErrorType())
|| optionalParametersMethod.GetUseSiteDiagnostic()?.DefaultSeverity == DiagnosticSeverity.Error) || optionalParametersMethod.GetUseSiteDiagnostic()?.DefaultSeverity == DiagnosticSeverity.Error)
{ {
// optionalParametersMethod can be null if we are writing to a readonly indexer or reading from an writeonly indexer, // optionalParametersMethod can be null if we are writing to a readonly indexer or reading from an writeonly indexer,
......
...@@ -382,7 +382,7 @@ private static MethodSymbol DelegateInvokeMethod(NamedTypeSymbol delegateType) ...@@ -382,7 +382,7 @@ private static MethodSymbol DelegateInvokeMethod(NamedTypeSymbol delegateType)
return delegateType.GetDelegateType()?.DelegateInvokeMethod; return delegateType.GetDelegateType()?.DelegateInvokeMethod;
} }
private static TypeSymbolWithAnnotations DelegateReturnType(MethodSymbol invokeMethod, out RefKind refKind) private TypeSymbolWithAnnotations DelegateReturnType(MethodSymbol invokeMethod, out RefKind refKind)
{ {
if ((object)invokeMethod == null) if ((object)invokeMethod == null)
{ {
......
...@@ -2523,56 +2523,6 @@ protected override void AfterLeftChildHasBeenVisited(BoundBinaryOperator binary) ...@@ -2523,56 +2523,6 @@ protected override void AfterLeftChildHasBeenVisited(BoundBinaryOperator binary)
} }
} }
public override BoundNode VisitFixedLocalCollectionInitializer(BoundFixedLocalCollectionInitializer node)
{
var initializer = node.Expression;
if (initializer.Kind == BoundKind.AddressOfOperator)
{
initializer = ((BoundAddressOfOperator)initializer).Operand;
}
// If the node is a fixed statement address-of operator (e.g. fixed(int *p = &...)),
// then we don't need to consider it for membership in unsafeAddressTakenVariables,
// because it is either not a local/parameter/range variable (if the variable is
// non-moveable) or it is and it has a RefKind other than None, in which case it can't
// be referred to in a lambda (i.e. can't be captured).
VisitAddressOfOperand(initializer, shouldReadOperand: false);
return null;
}
public override BoundNode VisitAddressOfOperator(BoundAddressOfOperator node)
{
BoundExpression operand = node.Operand;
bool shouldReadOperand = false;
Symbol variable = UseNonFieldSymbolUnsafely(operand);
if ((object)variable != null)
{
// The goal here is to treat address-of as a read in cases where
// we (a) care about a read happening (e.g. for DataFlowsIn) and
// (b) have information indicating that this will not result in
// a read to an unassigned variable (i.e. the operand is definitely
// assigned).
if (_unassignedVariableAddressOfSyntaxes?.Contains(node.Syntax as PrefixUnaryExpressionSyntax) == false)
{
shouldReadOperand = true;
}
if (!_unsafeAddressTakenVariables.ContainsKey(variable))
{
_unsafeAddressTakenVariables.Add(variable, node.Syntax.Location);
}
}
else
{
VisitAddressOfOperand(node.Operand, shouldReadOperand);
}
SetUnknownResultNullability();
return null;
}
private static BoundExpression SkipReferenceConversions(BoundExpression possiblyConversion) private static BoundExpression SkipReferenceConversions(BoundExpression possiblyConversion)
{ {
while (possiblyConversion.Kind == BoundKind.Conversion) while (possiblyConversion.Kind == BoundKind.Conversion)
...@@ -3256,6 +3206,54 @@ public override BoundNode VisitCompoundAssignmentOperator(BoundCompoundAssignmen ...@@ -3256,6 +3206,54 @@ public override BoundNode VisitCompoundAssignmentOperator(BoundCompoundAssignmen
return null; return null;
} }
public override BoundNode VisitFixedLocalCollectionInitializer(BoundFixedLocalCollectionInitializer node)
{
var initializer = node.Expression;
if (initializer.Kind == BoundKind.AddressOfOperator)
{
initializer = ((BoundAddressOfOperator)initializer).Operand;
}
// If the node is a fixed statement address-of operator (e.g. fixed(int *p = &...)),
// then we don't need to consider it for membership in unsafeAddressTakenVariables,
// because it is either not a local/parameter/range variable (if the variable is
// non-moveable) or it is and it has a RefKind other than None, in which case it can't
// be referred to in a lambda (i.e. can't be captured).
VisitAddressOfOperand(initializer, shouldReadOperand: false);
return null;
}
public override BoundNode VisitAddressOfOperator(BoundAddressOfOperator node)
{
BoundExpression operand = node.Operand;
bool shouldReadOperand = false;
Symbol variable = UseNonFieldSymbolUnsafely(operand);
if ((object)variable != null)
{
// The goal here is to treat address-of as a read in cases where
// we (a) care about a read happening (e.g. for DataFlowsIn) and
// (b) have information indicating that this will not result in
// a read to an unassigned variable (i.e. the operand is definitely
// assigned).
if (_unassignedVariableAddressOfSyntaxes?.Contains(node.Syntax as PrefixUnaryExpressionSyntax) == false)
{
shouldReadOperand = true;
}
if (!_unsafeAddressTakenVariables.ContainsKey(variable))
{
_unsafeAddressTakenVariables.Add(variable, node.Syntax.Location);
}
}
VisitAddressOfOperand(node.Operand, shouldReadOperand);
SetUnknownResultNullability();
return null;
}
protected override void VisitArgumentAsRvalue(BoundExpression argument, ParameterSymbol parameter, bool expanded) protected override void VisitArgumentAsRvalue(BoundExpression argument, ParameterSymbol parameter, bool expanded)
{ {
base.VisitArgumentAsRvalue(argument, parameter, expanded); base.VisitArgumentAsRvalue(argument, parameter, expanded);
...@@ -4063,13 +4061,6 @@ public override BoundNode VisitArgListOperator(BoundArgListOperator node) ...@@ -4063,13 +4061,6 @@ public override BoundNode VisitArgListOperator(BoundArgListOperator node)
return result; return result;
} }
public override BoundNode VisitFixedLocalCollectionInitializer(BoundFixedLocalCollectionInitializer node)
{
var result = base.VisitFixedLocalCollectionInitializer(node);
SetUnknownResultNullability();
return result;
}
public override BoundNode VisitLiteral(BoundLiteral node) public override BoundNode VisitLiteral(BoundLiteral node)
{ {
var result = base.VisitLiteral(node); var result = base.VisitLiteral(node);
......
...@@ -175,7 +175,6 @@ public static bool IsWarning(ErrorCode code) ...@@ -175,7 +175,6 @@ public static bool IsWarning(ErrorCode code)
case ErrorCode.WRN_TupleLiteralNameMismatch: case ErrorCode.WRN_TupleLiteralNameMismatch:
case ErrorCode.WRN_Experimental: case ErrorCode.WRN_Experimental:
case ErrorCode.WRN_DefaultInSwitch: case ErrorCode.WRN_DefaultInSwitch:
<<<<<<< HEAD
case ErrorCode.WRN_NullReferenceAssignment: case ErrorCode.WRN_NullReferenceAssignment:
case ErrorCode.WRN_NullReferenceReceiver: case ErrorCode.WRN_NullReferenceReceiver:
case ErrorCode.WRN_NullReferenceReturn: case ErrorCode.WRN_NullReferenceReturn:
...@@ -194,9 +193,7 @@ <<<<<<< HEAD ...@@ -194,9 +193,7 @@ <<<<<<< HEAD
case ErrorCode.WRN_NullabilityMismatchInArgument: case ErrorCode.WRN_NullabilityMismatchInArgument:
case ErrorCode.WRN_NullabilityMismatchInReturnTypeOfTargetDelegate: case ErrorCode.WRN_NullabilityMismatchInReturnTypeOfTargetDelegate:
case ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate: case ErrorCode.WRN_NullabilityMismatchInParameterTypeOfTargetDelegate:
=======
case ErrorCode.WRN_UnreferencedLocalFunction: case ErrorCode.WRN_UnreferencedLocalFunction:
>>>>>>> upstream/master
return true; return true;
default: default:
return false; return false;
......
...@@ -233,7 +233,7 @@ public override BoundNode VisitFixedLocalCollectionInitializer(BoundFixedLocalCo ...@@ -233,7 +233,7 @@ public override BoundNode VisitFixedLocalCollectionInitializer(BoundFixedLocalCo
SyntheticBoundNodeFactory factory, SyntheticBoundNodeFactory factory,
out LocalSymbol pinnedTemp) out LocalSymbol pinnedTemp)
{ {
TypeSymbol localType = localSymbol.Type; TypeSymbol localType = localSymbol.Type.TypeSymbol;
BoundExpression initializerExpr = VisitExpression(fixedInitializer.Expression); BoundExpression initializerExpr = VisitExpression(fixedInitializer.Expression);
// initializer expr should be either an address(&) of something or a fixed field access. // initializer expr should be either an address(&) of something or a fixed field access.
...@@ -374,7 +374,7 @@ public override BoundNode VisitFixedLocalCollectionInitializer(BoundFixedLocalCo ...@@ -374,7 +374,7 @@ public override BoundNode VisitFixedLocalCollectionInitializer(BoundFixedLocalCo
pinnedTemp = factory.SynthesizedLocal(initializerType, isPinned: true); pinnedTemp = factory.SynthesizedLocal(initializerType, isPinned: true);
ArrayTypeSymbol arrayType = (ArrayTypeSymbol)pinnedTemp.Type.TypeSymbol; ArrayTypeSymbol arrayType = (ArrayTypeSymbol)pinnedTemp.Type.TypeSymbol;
TypeSymbol arrayElementType = arrayType.ElementType.TypeSymbol; TypeSymbolWithAnnotations arrayElementType = arrayType.ElementType;
// NOTE: we pin the array, not the pointer. // NOTE: we pin the array, not the pointer.
Debug.Assert(pinnedTemp.IsPinned); Debug.Assert(pinnedTemp.IsPinned);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Symbols; using Microsoft.CodeAnalysis.Symbols;
namespace Microsoft.CodeAnalysis.CSharp.Symbols namespace Microsoft.CodeAnalysis.CSharp.Symbols
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities; using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Symbols namespace Microsoft.CodeAnalysis.CSharp.Symbols
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities; using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Symbols namespace Microsoft.CodeAnalysis.CSharp.Symbols
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
using System.Collections.Immutable; using System.Collections.Immutable;
using Roslyn.Utilities; using Roslyn.Utilities;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.CodeAnalysis.PooledObjects;
namespace Microsoft.CodeAnalysis.CSharp.Symbols namespace Microsoft.CodeAnalysis.CSharp.Symbols
{ {
......
...@@ -206,7 +206,7 @@ protected SourceMemberMethodSymbol(NamedTypeSymbol containingType, SyntaxReferen ...@@ -206,7 +206,7 @@ protected SourceMemberMethodSymbol(NamedTypeSymbol containingType, SyntaxReferen
this.locations = locations; this.locations = locations;
} }
protected void CheckEffectiveAccessibility(TypeSymbol returnType, ImmutableArray<ParameterSymbol> parameters, DiagnosticBag diagnostics) protected void CheckEffectiveAccessibility(TypeSymbolWithAnnotations returnType, ImmutableArray<ParameterSymbol> parameters, DiagnosticBag diagnostics)
{ {
if (this.DeclaredAccessibility <= Accessibility.Private) if (this.DeclaredAccessibility <= Accessibility.Private)
{ {
...@@ -221,7 +221,7 @@ protected void CheckEffectiveAccessibility(TypeSymbol returnType, ImmutableArray ...@@ -221,7 +221,7 @@ protected void CheckEffectiveAccessibility(TypeSymbol returnType, ImmutableArray
if (!this.IsNoMoreVisibleThan(returnType, ref useSiteDiagnostics)) if (!this.IsNoMoreVisibleThan(returnType, ref useSiteDiagnostics))
{ {
// Inconsistent accessibility: return type '{1}' is less accessible than method '{0}' // Inconsistent accessibility: return type '{1}' is less accessible than method '{0}'
diagnostics.Add(code, Locations[0], this, returnType); diagnostics.Add(code, Locations[0], this, returnType.TypeSymbol);
} }
code = (this.MethodKind == MethodKind.Conversion || this.MethodKind == MethodKind.UserDefinedOperator) ? code = (this.MethodKind == MethodKind.Conversion || this.MethodKind == MethodKind.UserDefinedOperator) ?
...@@ -233,7 +233,7 @@ protected void CheckEffectiveAccessibility(TypeSymbol returnType, ImmutableArray ...@@ -233,7 +233,7 @@ protected void CheckEffectiveAccessibility(TypeSymbol returnType, ImmutableArray
if (!parameter.Type.IsAtLeastAsVisibleAs(this, ref useSiteDiagnostics)) if (!parameter.Type.IsAtLeastAsVisibleAs(this, ref useSiteDiagnostics))
{ {
// Inconsistent accessibility: parameter type '{1}' is less accessible than method '{0}' // Inconsistent accessibility: parameter type '{1}' is less accessible than method '{0}'
diagnostics.Add(code, Locations[0], this, parameter.Type); diagnostics.Add(code, Locations[0], this, parameter.Type.TypeSymbol);
} }
} }
...@@ -595,14 +595,6 @@ public override string GetDocumentationCommentXml(CultureInfo preferredCulture = ...@@ -595,14 +595,6 @@ public override string GetDocumentationCommentXml(CultureInfo preferredCulture =
#endregion #endregion
public override ImmutableArray<CustomModifier> ReturnTypeCustomModifiers
{
get
{
return ImmutableArray<CustomModifier>.Empty;
}
}
public override ImmutableArray<CustomModifier> RefCustomModifiers public override ImmutableArray<CustomModifier> RefCustomModifiers
{ {
get get
...@@ -611,11 +603,11 @@ public override ImmutableArray<CustomModifier> RefCustomModifiers ...@@ -611,11 +603,11 @@ public override ImmutableArray<CustomModifier> RefCustomModifiers
} }
} }
public sealed override ImmutableArray<TypeSymbol> TypeArguments public sealed override ImmutableArray<TypeSymbolWithAnnotations> TypeArguments
{ {
get get
{ {
return TypeParameters.Cast<TypeParameterSymbol, TypeSymbol>(); return TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations);
} }
} }
...@@ -967,16 +959,24 @@ internal override void AddSynthesizedReturnTypeAttributes(ref ArrayBuilder<Synth ...@@ -967,16 +959,24 @@ internal override void AddSynthesizedReturnTypeAttributes(ref ArrayBuilder<Synth
{ {
base.AddSynthesizedReturnTypeAttributes(ref attributes); base.AddSynthesizedReturnTypeAttributes(ref attributes);
if (this.ReturnType.ContainsDynamic()) var type = this.ReturnType;
if (type.TypeSymbol.ContainsDynamic())
{ {
var compilation = this.DeclaringCompilation; var compilation = this.DeclaringCompilation;
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(this.ReturnType, this.ReturnTypeCustomModifiers.Length + this.RefCustomModifiers.Length, this.RefKind)); AddSynthesizedAttribute(ref attributes, compilation.SynthesizeDynamicAttribute(type.TypeSymbol, type.CustomModifiers.Length + this.RefCustomModifiers.Length, this.RefKind));
} }
if (ReturnType.ContainsTupleNames()) if (type.TypeSymbol.ContainsTupleNames())
{ {
AddSynthesizedAttribute(ref attributes, AddSynthesizedAttribute(ref attributes,
DeclaringCompilation.SynthesizeTupleNamesAttribute(ReturnType)); DeclaringCompilation.SynthesizeTupleNamesAttribute(type.TypeSymbol));
}
if (type.ContainsNullableReferenceTypes())
{
var compilation = this.DeclaringCompilation;
AddSynthesizedAttribute(ref attributes, compilation.SynthesizeNullableAttribute(type));
} }
} }
...@@ -1085,11 +1085,11 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut ...@@ -1085,11 +1085,11 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut
if (attribute.IsTargetAttribute(this, AttributeDescription.PreserveSigAttribute)) if (attribute.IsTargetAttribute(this, AttributeDescription.PreserveSigAttribute))
{ {
arguments.GetOrCreateData<CommonMethodWellKnownAttributeData>().SetPreserveSignature(arguments.Index); arguments.GetOrCreateData<MethodWellKnownAttributeData>().SetPreserveSignature(arguments.Index);
} }
else if (attribute.IsTargetAttribute(this, AttributeDescription.MethodImplAttribute)) else if (attribute.IsTargetAttribute(this, AttributeDescription.MethodImplAttribute))
{ {
AttributeData.DecodeMethodImplAttribute<CommonMethodWellKnownAttributeData, AttributeSyntax, CSharpAttributeData, AttributeLocation>(ref arguments, MessageProvider.Instance); AttributeData.DecodeMethodImplAttribute<MethodWellKnownAttributeData, AttributeSyntax, CSharpAttributeData, AttributeLocation>(ref arguments, MessageProvider.Instance);
} }
else if (attribute.IsTargetAttribute(this, AttributeDescription.DllImportAttribute)) else if (attribute.IsTargetAttribute(this, AttributeDescription.DllImportAttribute))
{ {
...@@ -1097,11 +1097,11 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut ...@@ -1097,11 +1097,11 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut
} }
else if (attribute.IsTargetAttribute(this, AttributeDescription.SpecialNameAttribute)) else if (attribute.IsTargetAttribute(this, AttributeDescription.SpecialNameAttribute))
{ {
arguments.GetOrCreateData<CommonMethodWellKnownAttributeData>().HasSpecialNameAttribute = true; arguments.GetOrCreateData<MethodWellKnownAttributeData>().HasSpecialNameAttribute = true;
} }
else if (attribute.IsTargetAttribute(this, AttributeDescription.ExcludeFromCodeCoverageAttribute)) else if (attribute.IsTargetAttribute(this, AttributeDescription.ExcludeFromCodeCoverageAttribute))
{ {
arguments.GetOrCreateData<CommonMethodWellKnownAttributeData>().HasExcludeFromCodeCoverageAttribute = true; arguments.GetOrCreateData<MethodWellKnownAttributeData>().HasExcludeFromCodeCoverageAttribute = true;
} }
else if (attribute.IsTargetAttribute(this, AttributeDescription.ConditionalAttribute)) else if (attribute.IsTargetAttribute(this, AttributeDescription.ConditionalAttribute))
{ {
...@@ -1109,11 +1109,11 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut ...@@ -1109,11 +1109,11 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut
} }
else if (attribute.IsTargetAttribute(this, AttributeDescription.SuppressUnmanagedCodeSecurityAttribute)) else if (attribute.IsTargetAttribute(this, AttributeDescription.SuppressUnmanagedCodeSecurityAttribute))
{ {
arguments.GetOrCreateData<CommonMethodWellKnownAttributeData>().HasSuppressUnmanagedCodeSecurityAttribute = true; arguments.GetOrCreateData<MethodWellKnownAttributeData>().HasSuppressUnmanagedCodeSecurityAttribute = true;
} }
else if (attribute.IsTargetAttribute(this, AttributeDescription.DynamicSecurityMethodAttribute)) else if (attribute.IsTargetAttribute(this, AttributeDescription.DynamicSecurityMethodAttribute))
{ {
arguments.GetOrCreateData<CommonMethodWellKnownAttributeData>().HasDynamicSecurityMethodAttribute = true; arguments.GetOrCreateData<MethodWellKnownAttributeData>().HasDynamicSecurityMethodAttribute = true;
} }
else if (VerifyObsoleteAttributeAppliedToMethod(ref arguments, AttributeDescription.ObsoleteAttribute)) else if (VerifyObsoleteAttributeAppliedToMethod(ref arguments, AttributeDescription.ObsoleteAttribute))
{ {
...@@ -1134,12 +1134,16 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut ...@@ -1134,12 +1134,16 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut
arguments.Diagnostics.Add(ErrorCode.ERR_SecurityCriticalOrSecuritySafeCriticalOnAsync, arguments.AttributeSyntaxOpt.Location, arguments.AttributeSyntaxOpt.GetErrorDisplayName()); arguments.Diagnostics.Add(ErrorCode.ERR_SecurityCriticalOrSecuritySafeCriticalOnAsync, arguments.AttributeSyntaxOpt.Location, arguments.AttributeSyntaxOpt.GetErrorDisplayName());
} }
} }
else if (attribute.IsTargetAttribute(this, AttributeDescription.NullableOptOutAttribute))
{
arguments.GetOrCreateData<MethodWellKnownAttributeData>().NullableOptOut = attribute.GetConstructorArgument<bool>(0, SpecialType.System_Boolean);
}
else else
{ {
var compilation = this.DeclaringCompilation; var compilation = this.DeclaringCompilation;
if (attribute.IsSecurityAttribute(compilation)) if (attribute.IsSecurityAttribute(compilation))
{ {
attribute.DecodeSecurityAttribute<CommonMethodWellKnownAttributeData>(this, compilation, ref arguments); attribute.DecodeSecurityAttribute<MethodWellKnownAttributeData>(this, compilation, ref arguments);
} }
} }
} }
...@@ -1245,6 +1249,11 @@ private void DecodeWellKnownAttributeAppliedToReturnValue(ref DecodeWellKnownAtt ...@@ -1245,6 +1249,11 @@ private void DecodeWellKnownAttributeAppliedToReturnValue(ref DecodeWellKnownAtt
{ {
arguments.Diagnostics.Add(ErrorCode.ERR_ExplicitTupleElementNamesAttribute, arguments.AttributeSyntaxOpt.Location); arguments.Diagnostics.Add(ErrorCode.ERR_ExplicitTupleElementNamesAttribute, arguments.AttributeSyntaxOpt.Location);
} }
else if (attribute.IsTargetAttribute(this, AttributeDescription.NullableAttribute))
{
// NullableAttribute should not be set explicitly.
arguments.Diagnostics.Add(ErrorCode.ERR_ExplicitNullableAttribute, arguments.AttributeSyntaxOpt.Location);
}
} }
private void DecodeDllImportAttribute(ref DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments) private void DecodeDllImportAttribute(ref DecodeWellKnownAttributeArguments<AttributeSyntax, CSharpAttributeData, AttributeLocation> arguments)
...@@ -1346,7 +1355,7 @@ private void DecodeDllImportAttribute(ref DecodeWellKnownAttributeArguments<Attr ...@@ -1346,7 +1355,7 @@ private void DecodeDllImportAttribute(ref DecodeWellKnownAttributeArguments<Attr
if (!hasErrors) if (!hasErrors)
{ {
arguments.GetOrCreateData<CommonMethodWellKnownAttributeData>().SetDllImport( arguments.GetOrCreateData<MethodWellKnownAttributeData>().SetDllImport(
arguments.Index, arguments.Index,
moduleName, moduleName,
importName, importName,
...@@ -1451,6 +1460,15 @@ internal sealed override bool HasSpecialName ...@@ -1451,6 +1460,15 @@ internal sealed override bool HasSpecialName
} }
} }
internal override bool NullableOptOut
{
get
{
var data = GetDecodedWellKnownAttributeData() as MethodWellKnownAttributeData;
return data?.NullableOptOut ?? base.NullableOptOut;
}
}
internal sealed override bool IsDirectlyExcludedFromCodeCoverage => internal sealed override bool IsDirectlyExcludedFromCodeCoverage =>
GetDecodedWellKnownAttributeData()?.HasExcludeFromCodeCoverageAttribute == true; GetDecodedWellKnownAttributeData()?.HasExcludeFromCodeCoverageAttribute == true;
...@@ -1470,28 +1488,12 @@ internal sealed override bool HasDeclarativeSecurity ...@@ -1470,28 +1488,12 @@ internal sealed override bool HasDeclarativeSecurity
var data = this.GetDecodedWellKnownAttributeData(); var data = this.GetDecodedWellKnownAttributeData();
return data != null && data.HasDeclarativeSecurity; return data != null && data.HasDeclarativeSecurity;
} }
if (((CSharpParseOptions)implementation.Locations[0].SourceTree?.Options)?.IsFeatureEnabled(MessageID.IDS_FeatureStaticNullChecking) == true &&
!implementation.NullableOptOut)
{
ImmutableArray<ParameterSymbol> implementationParameters = implementation.Parameters;
ImmutableArray<ParameterSymbol> definitionParameters = definition.ConstructIfGeneric(implementation.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)).Parameters;
for (int i = 0; i < implementationParameters.Length; i++)
{
if (!implementationParameters[i].Type.Equals(definitionParameters[i].Type, TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes) &&
implementationParameters[i].Type.Equals(definitionParameters[i].Type, TypeCompareKind.AllIgnoreOptions))
{
diagnostics.Add(ErrorCode.WRN_NullabilityMismatchInParameterTypeOnPartial, implementation.Locations[0], new FormattedSymbol(implementationParameters[i], SymbolDisplayFormat.ShortFormat));
}
}
}
} }
internal sealed override IEnumerable<Cci.SecurityAttribute> GetSecurityInformation() internal sealed override IEnumerable<Cci.SecurityAttribute> GetSecurityInformation()
{ {
var attributesBag = this.GetAttributesBag(); var attributesBag = this.GetAttributesBag();
var wellKnownData = (CommonMethodWellKnownAttributeData)attributesBag.DecodedWellKnownAttributeData; var wellKnownData = (MethodWellKnownAttributeData)attributesBag.DecodedWellKnownAttributeData;
if (wellKnownData != null) if (wellKnownData != null)
{ {
SecurityWellKnownAttributeData securityData = wellKnownData.SecurityInformation; SecurityWellKnownAttributeData securityData = wellKnownData.SecurityInformation;
......
...@@ -21,9 +21,9 @@ internal sealed class SourceOrdinaryMethodSymbol : SourceMemberMethodSymbol ...@@ -21,9 +21,9 @@ internal sealed class SourceOrdinaryMethodSymbol : SourceMemberMethodSymbol
private readonly RefKind _refKind; private readonly RefKind _refKind;
private ImmutableArray<MethodSymbol> _lazyExplicitInterfaceImplementations; private ImmutableArray<MethodSymbol> _lazyExplicitInterfaceImplementations;
private CustomModifiersTuple _lazyCustomModifiers; private ImmutableArray<CustomModifier> _lazyRefCustomModifiers;
private ImmutableArray<ParameterSymbol> _lazyParameters; private ImmutableArray<ParameterSymbol> _lazyParameters;
private TypeSymbol _lazyReturnType; private TypeSymbolWithAnnotations _lazyReturnType;
private bool _lazyIsVararg; private bool _lazyIsVararg;
/// <summary> /// <summary>
...@@ -182,7 +182,7 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB ...@@ -182,7 +182,7 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB
else else
{ {
// Method or delegate cannot return type '{0}' // Method or delegate cannot return type '{0}'
diagnostics.Add(ErrorCode.ERR_MethodReturnCantBeRefAny, syntax.ReturnType.Location, _lazyReturnType); diagnostics.Add(ErrorCode.ERR_MethodReturnCantBeRefAny, syntax.ReturnType.Location, _lazyReturnType.TypeSymbol);
} }
} }
...@@ -208,13 +208,13 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB ...@@ -208,13 +208,13 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB
if (IsExtensionMethod) if (IsExtensionMethod)
{ {
var parameter0Type = this.Parameters[0].Type; var parameter0Type = this.Parameters[0].Type;
if (!parameter0Type.IsValidExtensionParameterType()) if (!parameter0Type.TypeSymbol.IsValidExtensionParameterType())
{ {
// Duplicate Dev10 behavior by selecting the parameter type. // Duplicate Dev10 behavior by selecting the parameter type.
var parameterSyntax = syntax.ParameterList.Parameters[0]; var parameterSyntax = syntax.ParameterList.Parameters[0];
Debug.Assert(parameterSyntax.Type != null); Debug.Assert(parameterSyntax.Type != null);
var loc = parameterSyntax.Type.Location; var loc = parameterSyntax.Type.Location;
diagnostics.Add(ErrorCode.ERR_BadTypeforThis, loc, parameter0Type); diagnostics.Add(ErrorCode.ERR_BadTypeforThis, loc, parameter0Type.TypeSymbol);
} }
else if ((object)ContainingType.ContainingType != null) else if ((object)ContainingType.ContainingType != null)
{ {
...@@ -297,12 +297,12 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB ...@@ -297,12 +297,12 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB
// unnecessary for implicit implementations because, if the custom modifiers don't match, // unnecessary for implicit implementations because, if the custom modifiers don't match,
// we'll insert a bridge method (an explicit implementation that delegates to the implicit // we'll insert a bridge method (an explicit implementation that delegates to the implicit
// implementation) with the correct custom modifiers // implementation) with the correct custom modifiers
// (see SourceNamedTypeSymbol.ImplementInterfaceMember). // (see SourceMemberContainerTypeSymbol.SynthesizeInterfaceMemberImplementation).
// This value may not be correct, but we need something while we compute overridden/implemented method. // This value may not be correct, but we need something while we compute this.OverriddenMethod.
// May be re-assigned below. // May be re-assigned below.
Debug.Assert(_lazyCustomModifiers == null); Debug.Assert(_lazyReturnType.CustomModifiers.IsEmpty);
_lazyCustomModifiers = CustomModifiersTuple.Empty; _lazyRefCustomModifiers = ImmutableArray<CustomModifier>.Empty;
// Note: we're checking if the syntax indicates explicit implementation rather, // Note: we're checking if the syntax indicates explicit implementation rather,
// than if explicitInterfaceType is null because we don't want to look for an // than if explicitInterfaceType is null because we don't want to look for an
...@@ -329,7 +329,7 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB ...@@ -329,7 +329,7 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB
if ((object)overriddenMethod != null) if ((object)overriddenMethod != null)
{ {
CustomModifierUtils.CopyMethodCustomModifiers(overriddenMethod, this, out _lazyReturnType, CustomModifierUtils.CopyMethodCustomModifiers(overriddenMethod, this, out _lazyReturnType,
out _lazyCustomModifiers, out _lazyRefCustomModifiers,
out _lazyParameters, alsoCopyParamsModifier: true); out _lazyParameters, alsoCopyParamsModifier: true);
} }
} }
...@@ -345,13 +345,17 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB ...@@ -345,13 +345,17 @@ private void MethodChecks(MethodDeclarationSyntax syntax, Binder withTypeParamsB
_lazyExplicitInterfaceImplementations = ImmutableArray.Create<MethodSymbol>(implementedMethod); _lazyExplicitInterfaceImplementations = ImmutableArray.Create<MethodSymbol>(implementedMethod);
CustomModifierUtils.CopyMethodCustomModifiers(implementedMethod, this, out _lazyReturnType, CustomModifierUtils.CopyMethodCustomModifiers(implementedMethod, this, out _lazyReturnType,
out _lazyCustomModifiers, out _lazyRefCustomModifiers,
out _lazyParameters, alsoCopyParamsModifier: false); out _lazyParameters, alsoCopyParamsModifier: false);
this.FindExplicitlyImplementedMemberVerification(implementedMethod, diagnostics);
TypeSymbol.CheckNullableReferenceTypeMismatchOnImplementingMember(this, implementedMethod, true, diagnostics);
} }
else else
{ {
Debug.Assert(_lazyExplicitInterfaceImplementations.IsDefault); Debug.Assert(_lazyExplicitInterfaceImplementations.IsDefault);
_lazyExplicitInterfaceImplementations = ImmutableArray<MethodSymbol>.Empty; _lazyExplicitInterfaceImplementations = ImmutableArray<MethodSymbol>.Empty;
Debug.Assert(_lazyReturnType.CustomModifiers.IsEmpty);
} }
} }
...@@ -374,7 +378,7 @@ internal static void ReportAsyncParameterErrors(ImmutableArray<ParameterSymbol> ...@@ -374,7 +378,7 @@ internal static void ReportAsyncParameterErrors(ImmutableArray<ParameterSymbol>
} }
else if (parameter.Type.IsRestrictedType()) else if (parameter.Type.IsRestrictedType())
{ {
diagnostics.Add(ErrorCode.ERR_BadSpecialByRefLocal, loc, parameter.Type); diagnostics.Add(ErrorCode.ERR_BadSpecialByRefLocal, loc, parameter.Type.TypeSymbol);
} }
} }
} }
...@@ -424,7 +428,7 @@ protected sealed override void LazyAsyncMethodChecks(CancellationToken cancellat ...@@ -424,7 +428,7 @@ protected sealed override void LazyAsyncMethodChecks(CancellationToken cancellat
diagnostics.Add(ErrorCode.ERR_SynchronizedAsyncMethod, errorLocation); diagnostics.Add(ErrorCode.ERR_SynchronizedAsyncMethod, errorLocation);
} }
if (diagnostics.IsEmptyWithoutResolution) if (!diagnostics.HasAnyResolvedErrors())
{ {
ReportAsyncParameterErrors(_lazyParameters, diagnostics, errorLocation); ReportAsyncParameterErrors(_lazyParameters, diagnostics, errorLocation);
} }
...@@ -543,7 +547,7 @@ internal override RefKind RefKind ...@@ -543,7 +547,7 @@ internal override RefKind RefKind
} }
} }
public override TypeSymbol ReturnType public override TypeSymbolWithAnnotations ReturnType
{ {
get get
{ {
...@@ -668,21 +672,12 @@ public override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations ...@@ -668,21 +672,12 @@ public override ImmutableArray<MethodSymbol> ExplicitInterfaceImplementations
} }
} }
public override ImmutableArray<CustomModifier> ReturnTypeCustomModifiers
{
get
{
LazyMethodChecks();
return _lazyCustomModifiers.TypeCustomModifiers;
}
}
public override ImmutableArray<CustomModifier> RefCustomModifiers public override ImmutableArray<CustomModifier> RefCustomModifiers
{ {
get get
{ {
LazyMethodChecks(); LazyMethodChecks();
return _lazyCustomModifiers.RefCustomModifiers; return _lazyRefCustomModifiers;
} }
} }
...@@ -900,7 +895,7 @@ private void CheckModifiers(Location location, DiagnosticBag diagnostics) ...@@ -900,7 +895,7 @@ private void CheckModifiers(Location location, DiagnosticBag diagnostics)
else if (!ContainingType.IsInterfaceType() && _lazyReturnType.IsStatic) else if (!ContainingType.IsInterfaceType() && _lazyReturnType.IsStatic)
{ {
// '{0}': static types cannot be used as return types // '{0}': static types cannot be used as return types
diagnostics.Add(ErrorCode.ERR_ReturnTypeIsStaticClass, location, _lazyReturnType); diagnostics.Add(ErrorCode.ERR_ReturnTypeIsStaticClass, location, _lazyReturnType.TypeSymbol);
} }
else if (IsAbstract && IsExtern) else if (IsAbstract && IsExtern)
{ {
...@@ -1046,6 +1041,22 @@ private static void PartialMethodChecks(SourceOrdinaryMethodSymbol definition, S ...@@ -1046,6 +1041,22 @@ private static void PartialMethodChecks(SourceOrdinaryMethodSymbol definition, S
{ {
diagnostics.Add(ErrorCode.ERR_PartialMethodInconsistentConstraints, implementation.Locations[0], implementation); diagnostics.Add(ErrorCode.ERR_PartialMethodInconsistentConstraints, implementation.Locations[0], implementation);
} }
if (((CSharpParseOptions)implementation.Locations[0].SourceTree?.Options)?.IsFeatureEnabled(MessageID.IDS_FeatureStaticNullChecking) == true &&
!implementation.NullableOptOut)
{
ImmutableArray<ParameterSymbol> implementationParameters = implementation.Parameters;
ImmutableArray<ParameterSymbol> definitionParameters = definition.ConstructIfGeneric(implementation.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)).Parameters;
for (int i = 0; i < implementationParameters.Length; i++)
{
if (!implementationParameters[i].Type.Equals(definitionParameters[i].Type, TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes) &&
implementationParameters[i].Type.Equals(definitionParameters[i].Type, TypeCompareKind.AllIgnoreOptions))
{
diagnostics.Add(ErrorCode.WRN_NullabilityMismatchInParameterTypeOnPartial, implementation.Locations[0], new FormattedSymbol(implementationParameters[i], SymbolDisplayFormat.ShortFormat));
}
}
}
} }
/// <summary> /// <summary>
......
...@@ -442,8 +442,8 @@ protected override TypeParameterBounds ResolveBounds(ConsList<TypeParameterSymbo ...@@ -442,8 +442,8 @@ protected override TypeParameterBounds ResolveBounds(ConsList<TypeParameterSymbo
{ {
var constraintClauses = _owner.TypeParameterConstraintClauses; var constraintClauses = _owner.TypeParameterConstraintClauses;
var constraintTypes = constraintClauses.IsEmpty var constraintTypes = constraintClauses.IsEmpty
? ImmutableArray<TypeSymbol>.Empty ? ImmutableArray<TypeSymbolWithAnnotations>.Empty
: constraintClauses[Ordinal]?.ConstraintTypes ?? ImmutableArray<TypeSymbol>.Empty; : constraintClauses[Ordinal]?.ConstraintTypes ?? ImmutableArray<TypeSymbolWithAnnotations>.Empty;
return this.ResolveBounds(this.ContainingAssembly.CorLibrary, inProgress.Prepend(this), constraintTypes, false, this.DeclaringCompilation, diagnostics); return this.ResolveBounds(this.ContainingAssembly.CorLibrary, inProgress.Prepend(this), constraintTypes, false, this.DeclaringCompilation, diagnostics);
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Immutable; using System.Collections.Immutable;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities; using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Symbols namespace Microsoft.CodeAnalysis.CSharp.Symbols
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using Microsoft.CodeAnalysis.PooledObjects;
namespace Microsoft.CodeAnalysis.CSharp.Symbols namespace Microsoft.CodeAnalysis.CSharp.Symbols
{ {
......
...@@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols ...@@ -15,7 +15,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// </summary> /// </summary>
internal sealed class SynthesizedAccessorValueParameterSymbol : SourceComplexParameterSymbol internal sealed class SynthesizedAccessorValueParameterSymbol : SourceComplexParameterSymbol
{ {
public SynthesizedAccessorValueParameterSymbol(SourceMemberMethodSymbol accessor, TypeSymbolWithAnnotations paramType, int ordinal, ImmutableArray<CustomModifier> customModifiers) public SynthesizedAccessorValueParameterSymbol(SourceMemberMethodSymbol accessor, TypeSymbolWithAnnotations paramType, int ordinal)
: base(accessor, ordinal, paramType, RefKind.None, ParameterSymbol.ValueParameterName, accessor.Locations, : base(accessor, ordinal, paramType, RefKind.None, ParameterSymbol.ValueParameterName, accessor.Locations,
syntaxRef: null, syntaxRef: null,
defaultSyntaxValue: ConstantValue.Unset, // the default value can be set via [param: DefaultParameterValue] applied on the accessor defaultSyntaxValue: ConstantValue.Unset, // the default value can be set via [param: DefaultParameterValue] applied on the accessor
......
...@@ -37,7 +37,7 @@ internal static SynthesizedEntryPointSymbol Create(SynthesizedInteractiveInitial ...@@ -37,7 +37,7 @@ internal static SynthesizedEntryPointSymbol Create(SynthesizedInteractiveInitial
else else
{ {
var systemVoid = Binder.GetSpecialType(compilation, SpecialType.System_Void, DummySyntax(), diagnostics); var systemVoid = Binder.GetSpecialType(compilation, SpecialType.System_Void, DummySyntax(), diagnostics);
return new ScriptEntryPoint(containingType, systemVoid); return new ScriptEntryPoint(containingType, TypeSymbolWithAnnotations.Create(systemVoid));
} }
} }
...@@ -397,9 +397,9 @@ internal override BoundBlock CreateBody(DiagnosticBag diagnostics) ...@@ -397,9 +397,9 @@ internal override BoundBlock CreateBody(DiagnosticBag diagnostics)
private sealed class ScriptEntryPoint : SynthesizedEntryPointSymbol private sealed class ScriptEntryPoint : SynthesizedEntryPointSymbol
{ {
private readonly TypeSymbol _returnType; private readonly TypeSymbolWithAnnotations _returnType;
internal ScriptEntryPoint(NamedTypeSymbol containingType, TypeSymbol returnType) : internal ScriptEntryPoint(NamedTypeSymbol containingType, TypeSymbolWithAnnotations returnType) :
base(containingType) base(containingType)
{ {
Debug.Assert(containingType.IsScriptClass); Debug.Assert(containingType.IsScriptClass);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Utilities; using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.Symbols namespace Microsoft.CodeAnalysis.CSharp.Symbols
......
...@@ -2407,7 +2407,7 @@ static T F<T>(System.ValueType o) ...@@ -2407,7 +2407,7 @@ static T F<T>(System.ValueType o)
comp.VerifyDiagnostics( comp.VerifyDiagnostics(
// (5,21): error CS8314: An expression of type 'ValueType' cannot be handled by a pattern of type 'T' in C# 7. Please use language version 7.1 or greater. // (5,21): error CS8314: An expression of type 'ValueType' cannot be handled by a pattern of type 'T' in C# 7. Please use language version 7.1 or greater.
// return o is T t ? t : default(T); // return o is T t ? t : default(T);
Diagnostic(ErrorCode.ERR_PatternWrongGenericTypeInVersion, "T").WithArguments("System.ValueType", "T", "7", "7.1").WithLocation(5, 21)); Diagnostic(ErrorCode.ERR_PatternWrongGenericTypeInVersion, "T").WithArguments("System.ValueType", "T", "7.0", "7.1").WithLocation(5, 21));
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册