未验证 提交 a805cea9 编写于 作者: C Charles Stoner 提交者: GitHub

Remove obsolete TypeSymbolWithAnnotations.Create method (#29344)

上级 d37fd83f
...@@ -457,7 +457,7 @@ private static TypeSymbol MakeMergedTupleType(ArrayBuilder<DeconstructionVariabl ...@@ -457,7 +457,7 @@ private static TypeSymbol MakeMergedTupleType(ArrayBuilder<DeconstructionVariabl
int leftLength = lhsVariables.Count; int leftLength = lhsVariables.Count;
int rightLength = rhsLiteral.Arguments.Length; int rightLength = rhsLiteral.Arguments.Length;
var typesBuilder = ArrayBuilder<TypeSymbol>.GetInstance(leftLength); var typesBuilder = ArrayBuilder<TypeSymbolWithAnnotations>.GetInstance(leftLength);
var locationsBuilder = ArrayBuilder<Location>.GetInstance(leftLength); var locationsBuilder = ArrayBuilder<Location>.GetInstance(leftLength);
for (int i = 0; i < rightLength; i++) for (int i = 0; i < rightLength; i++)
{ {
...@@ -498,11 +498,11 @@ private static TypeSymbol MakeMergedTupleType(ArrayBuilder<DeconstructionVariabl ...@@ -498,11 +498,11 @@ private static TypeSymbol MakeMergedTupleType(ArrayBuilder<DeconstructionVariabl
} }
} }
typesBuilder.Add(mergedType); typesBuilder.Add(TypeSymbolWithAnnotations.Create(mergedType));
locationsBuilder.Add(element.Syntax.Location); locationsBuilder.Add(element.Syntax.Location);
} }
if (typesBuilder.Any(t => t == null)) if (typesBuilder.Any(t => t.IsNull))
{ {
typesBuilder.Free(); typesBuilder.Free();
locationsBuilder.Free(); locationsBuilder.Free();
...@@ -514,7 +514,7 @@ private static TypeSymbol MakeMergedTupleType(ArrayBuilder<DeconstructionVariabl ...@@ -514,7 +514,7 @@ private static TypeSymbol MakeMergedTupleType(ArrayBuilder<DeconstructionVariabl
// tree of types used for figuring out natural types in tuple literal. // tree of types used for figuring out natural types in tuple literal.
return TupleTypeSymbol.Create( return TupleTypeSymbol.Create(
locationOpt: null, locationOpt: null,
elementTypes: typesBuilder.ToImmutableAndFree().SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations), // PROTOTYPE(NullableTypeReferences): Not including nullability. elementTypes: typesBuilder.ToImmutableAndFree(),
elementLocations: locationsBuilder.ToImmutableAndFree(), elementLocations: locationsBuilder.ToImmutableAndFree(),
elementNames: default(ImmutableArray<string>), elementNames: default(ImmutableArray<string>),
compilation: compilation, compilation: compilation,
......
...@@ -779,7 +779,7 @@ private BoundExpression BindTupleExpression(TupleExpressionSyntax node, Diagnost ...@@ -779,7 +779,7 @@ private BoundExpression BindTupleExpression(TupleExpressionSyntax node, Diagnost
boundArguments.Add(boundArgument); boundArguments.Add(boundArgument);
var elementType = TypeSymbolWithAnnotations.Create(boundArgument.Type, isNullableIfReferenceType: null); var elementType = TypeSymbolWithAnnotations.Create(boundArgument.Type);
elementTypes.Add(elementType); elementTypes.Add(elementType);
if (elementType.IsNull) if (elementType.IsNull)
...@@ -2719,7 +2719,7 @@ private BoundExpression BindImplicitArrayCreationExpression(ImplicitArrayCreatio ...@@ -2719,7 +2719,7 @@ private BoundExpression BindImplicitArrayCreationExpression(ImplicitArrayCreatio
} }
// Element type nullability will be inferred in flow analysis and does not need to be set here. // Element type nullability will be inferred in flow analysis and does not need to be set here.
var arrayType = ArrayTypeSymbol.CreateCSharpArray(Compilation.Assembly, TypeSymbolWithAnnotations.Create(bestType, isNullableIfReferenceType: null), rank); var arrayType = ArrayTypeSymbol.CreateCSharpArray(Compilation.Assembly, TypeSymbolWithAnnotations.Create(bestType), rank);
return BindArrayCreationWithInitializer(diagnostics, node, initializer, arrayType, return BindArrayCreationWithInitializer(diagnostics, node, initializer, arrayType,
sizes: ImmutableArray<BoundExpression>.Empty, boundInitExprOpt: boundInitializerExpressions); sizes: ImmutableArray<BoundExpression>.Empty, boundInitExprOpt: boundInitializerExpressions);
} }
...@@ -2747,7 +2747,7 @@ private BoundExpression BindImplicitStackAllocArrayCreationExpression(ImplicitSt ...@@ -2747,7 +2747,7 @@ private BoundExpression BindImplicitStackAllocArrayCreationExpression(ImplicitSt
return BindStackAllocWithInitializer( return BindStackAllocWithInitializer(
node, node,
initializer, initializer,
type: GetStackAllocType(node, TypeSymbolWithAnnotations.Create(bestType, isNullableIfReferenceType: null), diagnostics, out bool hasErrors), type: GetStackAllocType(node, TypeSymbolWithAnnotations.Create(bestType), diagnostics, out bool hasErrors),
elementType: bestType, elementType: bestType,
sizeOpt: null, sizeOpt: null,
diagnostics, diagnostics,
......
...@@ -2152,9 +2152,10 @@ private BoundExpression BindAddressOfExpression(PrefixUnaryExpressionSyntax node ...@@ -2152,9 +2152,10 @@ private BoundExpression BindAddressOfExpression(PrefixUnaryExpressionSyntax node
} }
} }
TypeSymbol pointerType = new PointerTypeSymbol(TypeSymbolWithAnnotations.Create(isManagedType && allowManagedAddressOf TypeSymbol pointedAtType = isManagedType && allowManagedAddressOf
? GetSpecialType(SpecialType.System_IntPtr, diagnostics, node) ? GetSpecialType(SpecialType.System_IntPtr, diagnostics, node)
: operandType ?? CreateErrorType())); : operandType ?? CreateErrorType();
TypeSymbol pointerType = new PointerTypeSymbol(TypeSymbolWithAnnotations.Create(pointedAtType));
return new BoundAddressOfOperator(node, operand, pointerType, hasErrors); return new BoundAddressOfOperator(node, operand, pointerType, hasErrors);
} }
......
...@@ -889,7 +889,7 @@ protected BoundExpression BindInferredVariableInitializer(DiagnosticBag diagnost ...@@ -889,7 +889,7 @@ protected BoundExpression BindInferredVariableInitializer(DiagnosticBag diagnost
TypeSymbol initializerType = initializerOpt?.Type; TypeSymbol initializerType = initializerOpt?.Type;
if ((object)initializerType != null) if ((object)initializerType != null)
{ {
declTypeOpt = TypeSymbolWithAnnotations.Create(initializerType, isNullableIfReferenceType: null); declTypeOpt = TypeSymbolWithAnnotations.Create(initializerType);
if (declTypeOpt.SpecialType == SpecialType.System_Void) if (declTypeOpt.SpecialType == SpecialType.System_Void)
{ {
......
...@@ -226,7 +226,7 @@ private BoundForEachStatement BindForEachPartsWorker(DiagnosticBag diagnostics, ...@@ -226,7 +226,7 @@ private BoundForEachStatement BindForEachPartsWorker(DiagnosticBag diagnostics,
if (isVar) if (isVar)
{ {
declType = inferredType.IsNull ? TypeSymbolWithAnnotations.Create(CreateErrorType("var"), isNullableIfReferenceType: null) : inferredType; declType = inferredType.IsNull ? TypeSymbolWithAnnotations.Create(CreateErrorType("var")) : inferredType;
} }
else else
{ {
...@@ -497,7 +497,7 @@ private bool GetEnumeratorInfoAndInferCollectionElementType(ref ForEachEnumerato ...@@ -497,7 +497,7 @@ private bool GetEnumeratorInfoAndInferCollectionElementType(ref ForEachEnumerato
else if (collectionExpr.HasDynamicType()) else if (collectionExpr.HasDynamicType())
{ {
// If the enumerator is dynamic, it yields dynamic values // If the enumerator is dynamic, it yields dynamic values
inferredType = TypeSymbolWithAnnotations.Create(DynamicTypeSymbol.Instance, isNullableIfReferenceType: null); inferredType = TypeSymbolWithAnnotations.Create(DynamicTypeSymbol.Instance);
} }
else if (collectionExpr.Type.SpecialType == SpecialType.System_String && builder.CollectionType.SpecialType == SpecialType.System_Collections_IEnumerable) else if (collectionExpr.Type.SpecialType == SpecialType.System_String && builder.CollectionType.SpecialType == SpecialType.System_Collections_IEnumerable)
{ {
...@@ -505,7 +505,7 @@ private bool GetEnumeratorInfoAndInferCollectionElementType(ref ForEachEnumerato ...@@ -505,7 +505,7 @@ private bool GetEnumeratorInfoAndInferCollectionElementType(ref ForEachEnumerato
// over the string's Chars indexer. Therefore, we should infer "char", regardless of what the spec // over the string's Chars indexer. Therefore, we should infer "char", regardless of what the spec
// indicates the element type is. This actually matters in practice because the System.String in // indicates the element type is. This actually matters in practice because the System.String in
// the portable library doesn't have a pattern GetEnumerator method or implement IEnumerable<char>. // the portable library doesn't have a pattern GetEnumerator method or implement IEnumerable<char>.
inferredType = TypeSymbolWithAnnotations.Create(GetSpecialType(SpecialType.System_Char, diagnostics, collectionExpr.Syntax), isNullableIfReferenceType: null); inferredType = TypeSymbolWithAnnotations.Create(GetSpecialType(SpecialType.System_Char, diagnostics, collectionExpr.Syntax));
} }
else else
{ {
...@@ -740,13 +740,12 @@ private ForEachEnumeratorInfo.Builder GetDefaultEnumeratorInfo(ForEachEnumerator ...@@ -740,13 +740,12 @@ private ForEachEnumeratorInfo.Builder GetDefaultEnumeratorInfo(ForEachEnumerator
builder.ElementType = TypeSymbolWithAnnotations.Create( builder.ElementType = TypeSymbolWithAnnotations.Create(
((_syntax as ForEachStatementSyntax)?.Type.IsVar == true) ? ((_syntax as ForEachStatementSyntax)?.Type.IsVar == true) ?
(TypeSymbol)DynamicTypeSymbol.Instance : (TypeSymbol)DynamicTypeSymbol.Instance :
GetSpecialType(SpecialType.System_Object, diagnostics, _syntax), GetSpecialType(SpecialType.System_Object, diagnostics, _syntax));
isNullableIfReferenceType: null);
} }
else else
{ {
builder.ElementType = collectionExprType.SpecialType == SpecialType.System_String ? builder.ElementType = collectionExprType.SpecialType == SpecialType.System_String ?
TypeSymbolWithAnnotations.Create(GetSpecialType(SpecialType.System_Char, diagnostics, _syntax), isNullableIfReferenceType: null) : TypeSymbolWithAnnotations.Create(GetSpecialType(SpecialType.System_Char, diagnostics, _syntax)) :
((ArrayTypeSymbol)collectionExprType).ElementType; ((ArrayTypeSymbol)collectionExprType).ElementType;
} }
......
...@@ -237,7 +237,7 @@ public static void GetDelegateArguments(SyntaxNode syntax, AnalyzedArguments ana ...@@ -237,7 +237,7 @@ public static void GetDelegateArguments(SyntaxNode syntax, AnalyzedArguments ana
// If we don't have System.Object, then we'll get an error type, which will cause overload resolution to fail, // If we don't have System.Object, then we'll get an error type, which will cause overload resolution to fail,
// which will cause some error to be reported. That's sufficient (i.e. no need to specifically report its absence here). // which will cause some error to be reported. That's sufficient (i.e. no need to specifically report its absence here).
parameter = new SignatureOnlyParameterSymbol( parameter = new SignatureOnlyParameterSymbol(
TypeSymbolWithAnnotations.Create(compilation.GetSpecialType(SpecialType.System_Object), parameter.Type.CustomModifiers), parameter.RefCustomModifiers, parameter.IsParams, parameter.RefKind); TypeSymbolWithAnnotations.Create(compilation.GetSpecialType(SpecialType.System_Object), customModifiers: parameter.Type.CustomModifiers), parameter.RefCustomModifiers, parameter.IsParams, parameter.RefKind);
} }
analyzedArguments.Arguments.Add(new BoundParameter(syntax, parameter) { WasCompilerGenerated = true }); analyzedArguments.Arguments.Add(new BoundParameter(syntax, parameter) { WasCompilerGenerated = true });
......
...@@ -2822,7 +2822,7 @@ private static NamedTypeSymbol GetInterfaceInferenceBound(ImmutableArray<NamedTy ...@@ -2822,7 +2822,7 @@ private static NamedTypeSymbol GetInterfaceInferenceBound(ImmutableArray<NamedTy
// extension method of x, at least until we have more information. // extension method of x, at least until we have more information.
// //
// Clearly it is pointless to run multiple phases // Clearly it is pointless to run multiple phases
public static ImmutableArray<TypeSymbol> InferTypeArgumentsFromFirstArgument( public static ImmutableArray<TypeSymbolWithAnnotations> InferTypeArgumentsFromFirstArgument(
ConversionsBase conversions, ConversionsBase conversions,
MethodSymbol method, MethodSymbol method,
ImmutableArray<BoundExpression> arguments, ImmutableArray<BoundExpression> arguments,
...@@ -2835,7 +2835,7 @@ private static NamedTypeSymbol GetInterfaceInferenceBound(ImmutableArray<NamedTy ...@@ -2835,7 +2835,7 @@ private static NamedTypeSymbol GetInterfaceInferenceBound(ImmutableArray<NamedTy
// We need at least one formal parameter type and at least one argument. // We need at least one formal parameter type and at least one argument.
if ((method.ParameterCount < 1) || (arguments.Length < 1)) if ((method.ParameterCount < 1) || (arguments.Length < 1))
{ {
return default(ImmutableArray<TypeSymbol>); return default(ImmutableArray<TypeSymbolWithAnnotations>);
} }
Debug.Assert(!method.ParameterTypes[0].IsDynamic()); Debug.Assert(!method.ParameterTypes[0].IsDynamic());
...@@ -2853,7 +2853,7 @@ private static NamedTypeSymbol GetInterfaceInferenceBound(ImmutableArray<NamedTy ...@@ -2853,7 +2853,7 @@ private static NamedTypeSymbol GetInterfaceInferenceBound(ImmutableArray<NamedTy
if (!inferrer.InferTypeArgumentsFromFirstArgument(ref useSiteDiagnostics)) if (!inferrer.InferTypeArgumentsFromFirstArgument(ref useSiteDiagnostics))
{ {
return default(ImmutableArray<TypeSymbol>); return default(ImmutableArray<TypeSymbolWithAnnotations>);
} }
return inferrer.GetInferredTypeArguments(); return inferrer.GetInferredTypeArguments();
...@@ -2899,14 +2899,9 @@ private bool InferTypeArgumentsFromFirstArgument(ref HashSet<DiagnosticInfo> use ...@@ -2899,14 +2899,9 @@ private bool InferTypeArgumentsFromFirstArgument(ref HashSet<DiagnosticInfo> use
/// Return the inferred type arguments using null /// Return the inferred type arguments using null
/// for any type arguments that were not inferred. /// for any type arguments that were not inferred.
/// </summary> /// </summary>
private ImmutableArray<TypeSymbol> GetInferredTypeArguments() private ImmutableArray<TypeSymbolWithAnnotations> GetInferredTypeArguments()
{ {
var builder = ArrayBuilder<TypeSymbol>.GetInstance(); return _fixedResults.AsImmutable();
foreach (var fixedResult in _fixedResults)
{
builder.Add(fixedResult.TypeSymbol);
}
return builder.ToImmutableAndFree();
} }
private static bool IsReallyAType(TypeSymbol type) private static bool IsReallyAType(TypeSymbol type)
......
...@@ -251,9 +251,9 @@ public override BoundNode VisitReturnStatement(BoundReturnStatement node) ...@@ -251,9 +251,9 @@ public override BoundNode VisitReturnStatement(BoundReturnStatement node)
{ {
var expression = node.ExpressionOpt; var expression = node.ExpressionOpt;
var type = (expression is null) ? var type = (expression is null) ?
TypeSymbolWithAnnotations.Create(NonNullTypesUnusedContext.Instance, NoReturnExpression) : NoReturnExpression :
TypeSymbolWithAnnotations.Create(expression.Type?.SetUnknownNullabilityForReferenceTypes()); expression.Type?.SetUnknownNullabilityForReferenceTypes();
_builder.Add((node.RefKind, type)); _builder.Add((node.RefKind, TypeSymbolWithAnnotations.Create(type)));
return null; return null;
} }
} }
......
...@@ -464,7 +464,7 @@ IEnumerable<Cci.TypeReferenceWithAttributes> Cci.ITypeDefinition.Interfaces(Emit ...@@ -464,7 +464,7 @@ IEnumerable<Cci.TypeReferenceWithAttributes> Cci.ITypeDefinition.Interfaces(Emit
diagnostics: context.Diagnostics, diagnostics: context.Diagnostics,
fromImplements: true); fromImplements: true);
var type = TypeSymbolWithAnnotations.Create(@interface, isNullableIfReferenceType: null); var type = TypeSymbolWithAnnotations.Create(@interface);
yield return type.GetTypeRefWithAttributes( yield return type.GetTypeRefWithAttributes(
moduleBeingBuilt, moduleBeingBuilt,
declaringSymbol: this, declaringSymbol: this,
......
...@@ -104,7 +104,7 @@ protected override IEnumerable<Cci.TypeReferenceWithAttributes> GetInterfaces(Em ...@@ -104,7 +104,7 @@ protected override IEnumerable<Cci.TypeReferenceWithAttributes> GetInterfaces(Em
(CSharpSyntaxNode)context.SyntaxNodeOpt, (CSharpSyntaxNode)context.SyntaxNodeOpt,
context.Diagnostics); context.Diagnostics);
var type = TypeSymbolWithAnnotations.Create(@interface, isNullableIfReferenceType: null); var type = TypeSymbolWithAnnotations.Create(@interface);
yield return type.GetTypeRefWithAttributes( yield return type.GetTypeRefWithAttributes(
moduleBeingBuilt, moduleBeingBuilt,
declaringSymbol: UnderlyingNamedType, declaringSymbol: UnderlyingNamedType,
......
...@@ -24,7 +24,7 @@ private class ObjectCreationPlaceholderLocal : LocalSymbol ...@@ -24,7 +24,7 @@ private class ObjectCreationPlaceholderLocal : LocalSymbol
public ObjectCreationPlaceholderLocal(Symbol containingSymbol, BoundExpression objectCreationExpression) public ObjectCreationPlaceholderLocal(Symbol containingSymbol, BoundExpression objectCreationExpression)
{ {
_containingSymbol = containingSymbol; _containingSymbol = containingSymbol;
_type = TypeSymbolWithAnnotations.Create(objectCreationExpression.Type); _type = TypeSymbolWithAnnotations.Create(objectCreationExpression.Type, isNullableIfReferenceType: false);
ObjectCreationExpression = objectCreationExpression; ObjectCreationExpression = objectCreationExpression;
} }
......
...@@ -1079,7 +1079,7 @@ private void VisitObjectOrDynamicObjectCreation(BoundExpression node, BoundExpre ...@@ -1079,7 +1079,7 @@ private void VisitObjectOrDynamicObjectCreation(BoundExpression node, BoundExpre
VisitObjectCreationInitializer(receiver, slot, initializerOpt); VisitObjectCreationInitializer(receiver, slot, initializerOpt);
} }
_resultType = TypeSymbolWithAnnotations.Create(type); _resultType = TypeSymbolWithAnnotations.Create(type, isNullableIfReferenceType: false);
} }
private void VisitObjectCreationInitializer(Symbol containingSymbol, int containingSlot, BoundExpression node) private void VisitObjectCreationInitializer(Symbol containingSymbol, int containingSlot, BoundExpression node)
...@@ -1227,7 +1227,7 @@ public override BoundNode VisitAnonymousObjectCreationExpression(BoundAnonymousO ...@@ -1227,7 +1227,7 @@ public override BoundNode VisitAnonymousObjectCreationExpression(BoundAnonymousO
// PROTOTYPE(NullableReferenceTypes): _result may need to be a new anonymous // PROTOTYPE(NullableReferenceTypes): _result may need to be a new anonymous
// type since the properties may have distinct nullability from original. // type since the properties may have distinct nullability from original.
// (See StaticNullChecking_FlowAnalysis.AnonymousObjectCreation_02.) // (See StaticNullChecking_FlowAnalysis.AnonymousObjectCreation_02.)
_resultType = TypeSymbolWithAnnotations.Create(node.Type); _resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
return null; return null;
} }
...@@ -1238,7 +1238,7 @@ public override BoundNode VisitArrayCreation(BoundArrayCreation node) ...@@ -1238,7 +1238,7 @@ public override BoundNode VisitArrayCreation(BoundArrayCreation node)
VisitRvalue(expr); VisitRvalue(expr);
} }
TypeSymbol resultType = (node.InitializerOpt == null) ? node.Type : VisitArrayInitializer(node); TypeSymbol resultType = (node.InitializerOpt == null) ? node.Type : VisitArrayInitializer(node);
_resultType = TypeSymbolWithAnnotations.Create(resultType); _resultType = TypeSymbolWithAnnotations.Create(resultType, isNullableIfReferenceType: false);
return null; return null;
} }
...@@ -1286,7 +1286,7 @@ private ArrayTypeSymbol VisitArrayInitializer(BoundArrayCreation node) ...@@ -1286,7 +1286,7 @@ private ArrayTypeSymbol VisitArrayInitializer(BoundArrayCreation node)
else else
{ {
// Mark the error type as null-oblivious. // Mark the error type as null-oblivious.
bestType = TypeSymbolWithAnnotations.Create(bestType.TypeSymbol, isNullableIfReferenceType: null); bestType = TypeSymbolWithAnnotations.Create(bestType.TypeSymbol);
} }
// PROTOTYPE(NullableReferenceTypes): Report a special ErrorCode.WRN_NoBestNullabilityArrayElements // PROTOTYPE(NullableReferenceTypes): Report a special ErrorCode.WRN_NoBestNullabilityArrayElements
// when InferBestType fails, and avoid reporting conversion warnings for each element in those cases. // when InferBestType fails, and avoid reporting conversion warnings for each element in those cases.
...@@ -1374,7 +1374,7 @@ private TypeSymbolWithAnnotations InferResultNullability(BinaryOperatorKind oper ...@@ -1374,7 +1374,7 @@ private TypeSymbolWithAnnotations InferResultNullability(BinaryOperatorKind oper
if (operatorKind.IsLifted()) if (operatorKind.IsLifted())
{ {
// PROTOTYPE(NullableReferenceTypes): Conversions: Lifted operator // PROTOTYPE(NullableReferenceTypes): Conversions: Lifted operator
return TypeSymbolWithAnnotations.Create(resultType, isNullableIfReferenceType: null); return TypeSymbolWithAnnotations.Create(resultType);
} }
// PROTOTYPE(NullableReferenceTypes): Update method based on operand types. // PROTOTYPE(NullableReferenceTypes): Update method based on operand types.
if ((object)methodOpt != null && methodOpt.ParameterCount == 2) if ((object)methodOpt != null && methodOpt.ParameterCount == 2)
...@@ -2840,7 +2840,7 @@ private void VisitTupleExpression(BoundTupleExpression node) ...@@ -2840,7 +2840,7 @@ private void VisitTupleExpression(BoundTupleExpression node)
var tupleOpt = (TupleTypeSymbol)node.Type; var tupleOpt = (TupleTypeSymbol)node.Type;
_resultType = (tupleOpt is null) ? _resultType = (tupleOpt is null) ?
default : default :
TypeSymbolWithAnnotations.Create(tupleOpt.WithElementTypes(elementTypes)); TypeSymbolWithAnnotations.Create(tupleOpt.WithElementTypes(elementTypes), isNullableIfReferenceType: false);
} }
public override BoundNode VisitTupleBinaryOperator(BoundTupleBinaryOperator node) public override BoundNode VisitTupleBinaryOperator(BoundTupleBinaryOperator node)
...@@ -3153,7 +3153,7 @@ public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationE ...@@ -3153,7 +3153,7 @@ public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationE
} }
base.VisitDelegateCreationExpression(node); base.VisitDelegateCreationExpression(node);
SetResult(node); _resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
return null; return null;
} }
...@@ -3221,7 +3221,7 @@ public override BoundNode VisitThisReference(BoundThisReference node) ...@@ -3221,7 +3221,7 @@ public override BoundNode VisitThisReference(BoundThisReference node)
private void VisitThisOrBaseReference(BoundExpression node) private void VisitThisOrBaseReference(BoundExpression node)
{ {
_resultType = TypeSymbolWithAnnotations.Create(node.Type); _resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
} }
public override BoundNode VisitParameter(BoundParameter node) public override BoundNode VisitParameter(BoundParameter node)
...@@ -3621,7 +3621,7 @@ public override BoundNode VisitDynamicObjectInitializerMember(BoundDynamicObject ...@@ -3621,7 +3621,7 @@ public override BoundNode VisitDynamicObjectInitializerMember(BoundDynamicObject
public override BoundNode VisitBadExpression(BoundBadExpression node) public override BoundNode VisitBadExpression(BoundBadExpression node)
{ {
var result = base.VisitBadExpression(node); var result = base.VisitBadExpression(node);
_resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: null); _resultType = TypeSymbolWithAnnotations.Create(node.Type);
return result; return result;
} }
...@@ -3660,7 +3660,7 @@ public override BoundNode VisitUnaryOperator(BoundUnaryOperator node) ...@@ -3660,7 +3660,7 @@ public override BoundNode VisitUnaryOperator(BoundUnaryOperator node)
} }
} }
_resultType = resultType.IsNull ? TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: null) : resultType; _resultType = resultType.IsNull ? TypeSymbolWithAnnotations.Create(node.Type) : resultType;
return null; return null;
} }
...@@ -3704,7 +3704,7 @@ private TypeSymbolWithAnnotations InferResultNullability(BoundUserDefinedConditi ...@@ -3704,7 +3704,7 @@ private TypeSymbolWithAnnotations InferResultNullability(BoundUserDefinedConditi
if (node.OperatorKind.IsLifted()) if (node.OperatorKind.IsLifted())
{ {
// PROTOTYPE(NullableReferenceTypes): Conversions: Lifted operator // PROTOTYPE(NullableReferenceTypes): Conversions: Lifted operator
return TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: null); return TypeSymbolWithAnnotations.Create(node.Type);
} }
// PROTOTYPE(NullableReferenceTypes): Update method based on inferred operand types. // PROTOTYPE(NullableReferenceTypes): Update method based on inferred operand types.
if ((object)node.LogicalOperator != null && node.LogicalOperator.ParameterCount == 2) if ((object)node.LogicalOperator != null && node.LogicalOperator.ParameterCount == 2)
...@@ -3808,7 +3808,7 @@ public override BoundNode VisitAwaitExpression(BoundAwaitExpression node) ...@@ -3808,7 +3808,7 @@ public override BoundNode VisitAwaitExpression(BoundAwaitExpression node)
public override BoundNode VisitTypeOfOperator(BoundTypeOfOperator node) public override BoundNode VisitTypeOfOperator(BoundTypeOfOperator node)
{ {
var result = base.VisitTypeOfOperator(node); var result = base.VisitTypeOfOperator(node);
SetResult(node); _resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
return result; return result;
} }
...@@ -4007,7 +4007,7 @@ public override BoundNode VisitDynamicMemberAccess(BoundDynamicMemberAccess node ...@@ -4007,7 +4007,7 @@ public override BoundNode VisitDynamicMemberAccess(BoundDynamicMemberAccess node
CheckPossibleNullReceiver(receiver); CheckPossibleNullReceiver(receiver);
Debug.Assert(node.Type.IsDynamic()); Debug.Assert(node.Type.IsDynamic());
_resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: null); _resultType = TypeSymbolWithAnnotations.Create(node.Type);
return null; return null;
} }
...@@ -4085,7 +4085,7 @@ public override BoundNode VisitAnonymousPropertyDeclaration(BoundAnonymousProper ...@@ -4085,7 +4085,7 @@ public override BoundNode VisitAnonymousPropertyDeclaration(BoundAnonymousProper
public override BoundNode VisitNoPiaObjectCreationExpression(BoundNoPiaObjectCreationExpression node) public override BoundNode VisitNoPiaObjectCreationExpression(BoundNoPiaObjectCreationExpression node)
{ {
var result = base.VisitNoPiaObjectCreationExpression(node); var result = base.VisitNoPiaObjectCreationExpression(node);
SetResult(node); _resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
return result; return result;
} }
...@@ -4247,7 +4247,7 @@ public override BoundNode VisitQueryClause(BoundQueryClause node) ...@@ -4247,7 +4247,7 @@ public override BoundNode VisitQueryClause(BoundQueryClause node)
public override BoundNode VisitNameOfOperator(BoundNameOfOperator node) public override BoundNode VisitNameOfOperator(BoundNameOfOperator node)
{ {
var result = base.VisitNameOfOperator(node); var result = base.VisitNameOfOperator(node);
SetResult(node); _resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
return result; return result;
} }
...@@ -4261,7 +4261,7 @@ public override BoundNode VisitNamespaceExpression(BoundNamespaceExpression node ...@@ -4261,7 +4261,7 @@ public override BoundNode VisitNamespaceExpression(BoundNamespaceExpression node
public override BoundNode VisitInterpolatedString(BoundInterpolatedString node) public override BoundNode VisitInterpolatedString(BoundInterpolatedString node)
{ {
var result = base.VisitInterpolatedString(node); var result = base.VisitInterpolatedString(node);
SetResult(node); _resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
return result; return result;
} }
......
...@@ -626,7 +626,7 @@ private static void InsertAndFreePrologue(ArrayBuilder<BoundStatement> result, A ...@@ -626,7 +626,7 @@ private static void InsertAndFreePrologue(ArrayBuilder<BoundStatement> result, A
private BoundNode IntroduceFrame(BoundNode node, Analysis.ClosureEnvironment env, Func<ArrayBuilder<BoundExpression>, ArrayBuilder<LocalSymbol>, BoundNode> F) private BoundNode IntroduceFrame(BoundNode node, Analysis.ClosureEnvironment env, Func<ArrayBuilder<BoundExpression>, ArrayBuilder<LocalSymbol>, BoundNode> F)
{ {
var frame = env.SynthesizedEnvironment; var frame = env.SynthesizedEnvironment;
var frameTypeParameters = ImmutableArray.Create(_currentTypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations), 0, frame.Arity); var frameTypeParameters = ImmutableArray.Create(_currentTypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t)), 0, frame.Arity);
NamedTypeSymbol frameType = frame.ConstructIfGeneric(frameTypeParameters); NamedTypeSymbol frameType = frame.ConstructIfGeneric(frameTypeParameters);
Debug.Assert(frame.ScopeSyntaxOpt != null); Debug.Assert(frame.ScopeSyntaxOpt != null);
...@@ -960,7 +960,7 @@ private ImmutableArray<TypeSymbolWithAnnotations> SubstituteTypeArguments(Immuta ...@@ -960,7 +960,7 @@ private ImmutableArray<TypeSymbolWithAnnotations> SubstituteTypeArguments(Immuta
// All of _currentTypeParameters might not be preserved here due to recursively calling upwards in the chain of local functions/lambdas // All of _currentTypeParameters might not be preserved here due to recursively calling upwards in the chain of local functions/lambdas
Debug.Assert((typeArgumentsOpt.IsDefault && !originalMethod.IsGenericMethod) || (typeArgumentsOpt.Length == originalMethod.Arity)); Debug.Assert((typeArgumentsOpt.IsDefault && !originalMethod.IsGenericMethod) || (typeArgumentsOpt.Length == originalMethod.Arity));
var totalTypeArgumentCount = (containerAsFrame?.Arity ?? 0) + synthesizedMethod.Arity; var totalTypeArgumentCount = (containerAsFrame?.Arity ?? 0) + synthesizedMethod.Arity;
var realTypeArguments = ImmutableArray.Create(_currentTypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations), 0, totalTypeArgumentCount - originalMethod.Arity); var realTypeArguments = ImmutableArray.Create(_currentTypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t)), 0, totalTypeArgumentCount - originalMethod.Arity);
if (!typeArgumentsOpt.IsDefault) if (!typeArgumentsOpt.IsDefault)
{ {
realTypeArguments = realTypeArguments.Concat(typeArgumentsOpt); realTypeArguments = realTypeArguments.Concat(typeArgumentsOpt);
......
...@@ -112,7 +112,7 @@ private set ...@@ -112,7 +112,7 @@ private set
methodName, methodName,
args, args,
diagnostics, diagnostics,
typeArgs: typeArgs.IsDefault ? default(ImmutableArray<TypeSymbolWithAnnotations>) : typeArgs.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations), typeArgs: typeArgs.IsDefault ? default(ImmutableArray<TypeSymbolWithAnnotations>) : typeArgs.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t)),
allowFieldsAndProperties: false, allowFieldsAndProperties: false,
allowUnexpandedForm: allowUnexpandedForm); allowUnexpandedForm: allowUnexpandedForm);
} }
......
...@@ -126,7 +126,7 @@ internal TypeSymbolWithAnnotations SubstituteType(TypeSymbol previous) ...@@ -126,7 +126,7 @@ internal TypeSymbolWithAnnotations SubstituteType(TypeSymbol previous)
} }
// PROTOTYPE(NullableReferenceTypes): we're dropping annotation and context // PROTOTYPE(NullableReferenceTypes): we're dropping annotation and context
return TypeSymbolWithAnnotations.Create(result, isNullableIfReferenceType: null); return TypeSymbolWithAnnotations.Create(result);
} }
internal TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotations previous) internal TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotations previous)
...@@ -138,34 +138,11 @@ internal TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotations prev ...@@ -138,34 +138,11 @@ internal TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotations prev
/// Same as <see cref="SubstituteType(TypeSymbol)"/>, but with special behavior around tuples. /// Same as <see cref="SubstituteType(TypeSymbol)"/>, but with special behavior around tuples.
/// In particular, if substitution makes type tuple compatible, transform it into a tuple type. /// In particular, if substitution makes type tuple compatible, transform it into a tuple type.
/// </summary> /// </summary>
internal TypeSymbolWithAnnotations SubstituteTypeWithTupleUnification(TypeSymbol previous)
{
return SubstituteType(previous, withTupleUnification: true);
}
internal TypeSymbolWithAnnotations SubstituteType(TypeSymbol previous, bool withTupleUnification) internal TypeSymbolWithAnnotations SubstituteType(TypeSymbol previous, bool withTupleUnification)
{ {
var result = SubstituteType(previous); var result = SubstituteType(previous);
// Make it a tuple if it became compatible with one.
if (withTupleUnification) return withTupleUnification ? result.TransformToTupleIfCompatible() : result;
{
// Make it a tuple if it became compatible with one.
// PROTOTYPE(NullableReferenceTypes): Avoid resolving result.TypeSymbol eagerly.
var type = result.TypeSymbol;
if ((object)type != null && !previous.IsTupleCompatible())
{
var possiblyTuple = TupleTypeSymbol.TransformToTupleIfCompatible(type);
if ((object)type != possiblyTuple)
{
// PROTOTYPE(NullableReferenceTypes): This ignores the particular TypeSymbolWithAnnotations
// derived type from result (for instance, NullableReferenceTypeWithoutCustomModifiers)
// so nullable-ness may be lost.
result = TypeSymbolWithAnnotations.Create(possiblyTuple, result.CustomModifiers);
}
}
}
return result;
} }
internal TypeSymbolWithAnnotations SubstituteTypeWithTupleUnification(TypeSymbolWithAnnotations previous) internal TypeSymbolWithAnnotations SubstituteTypeWithTupleUnification(TypeSymbolWithAnnotations previous)
......
...@@ -18,7 +18,7 @@ internal AnonymousTypeEqualsMethodSymbol(NamedTypeSymbol container) ...@@ -18,7 +18,7 @@ internal AnonymousTypeEqualsMethodSymbol(NamedTypeSymbol container)
: base(container, WellKnownMemberNames.ObjectEquals) : base(container, WellKnownMemberNames.ObjectEquals)
{ {
_parameters = ImmutableArray.Create<ParameterSymbol>( _parameters = ImmutableArray.Create<ParameterSymbol>(
SynthesizedParameterSymbol.Create(this, TypeSymbolWithAnnotations.Create(this.Manager.System_Object), 0, RefKind.None, "value")); SynthesizedParameterSymbol.Create(this, TypeSymbolWithAnnotations.Create(this.Manager.System_Object, isNullableIfReferenceType: true), 0, RefKind.None, "value"));
} }
public override MethodKind MethodKind public override MethodKind MethodKind
......
...@@ -42,7 +42,7 @@ public override RefKind RefKind ...@@ -42,7 +42,7 @@ public override RefKind RefKind
public override TypeSymbolWithAnnotations ReturnType public override TypeSymbolWithAnnotations ReturnType
{ {
get { return TypeSymbolWithAnnotations.Create(this.Manager.System_String); } get { return TypeSymbolWithAnnotations.Create(this.Manager.System_String, isNullableIfReferenceType: false); }
} }
public override ImmutableArray<ParameterSymbol> Parameters public override ImmutableArray<ParameterSymbol> Parameters
......
...@@ -39,7 +39,7 @@ internal abstract partial class ErrorTypeSymbol : NamedTypeSymbol, IErrorTypeSym ...@@ -39,7 +39,7 @@ internal abstract partial class ErrorTypeSymbol : NamedTypeSymbol, IErrorTypeSym
/// </summary> /// </summary>
internal virtual TypeSymbolWithAnnotations Substitute(AbstractTypeMap typeMap) internal virtual TypeSymbolWithAnnotations Substitute(AbstractTypeMap typeMap)
{ {
return TypeSymbolWithAnnotations.Create((ErrorTypeSymbol)typeMap.SubstituteNamedType(this), isNullableIfReferenceType: null); return TypeSymbolWithAnnotations.Create((ErrorTypeSymbol)typeMap.SubstituteNamedType(this));
} }
/// <summary> /// <summary>
......
...@@ -106,7 +106,7 @@ private TupleTypeDecoder(ImmutableArray<string> elementNames) ...@@ -106,7 +106,7 @@ private TupleTypeDecoder(ImmutableArray<string> elementNames)
// bad metadata // bad metadata
if (hasTupleElementNamesAttribute && elementNames.IsDefaultOrEmpty) if (hasTupleElementNamesAttribute && elementNames.IsDefaultOrEmpty)
{ {
return TypeSymbolWithAnnotations.Create(new UnsupportedMetadataTypeSymbol(), isNullableIfReferenceType: null); return TypeSymbolWithAnnotations.Create(new UnsupportedMetadataTypeSymbol());
} }
TypeSymbol type = metadataType.TypeSymbol; TypeSymbol type = metadataType.TypeSymbol;
......
...@@ -749,6 +749,7 @@ public MethodSymbol Construct(params TypeSymbol[] typeArguments) ...@@ -749,6 +749,7 @@ public MethodSymbol Construct(params TypeSymbol[] typeArguments)
return this.Construct(ImmutableArray.Create(typeArguments)); return this.Construct(ImmutableArray.Create(typeArguments));
} }
// PROTOTYPE(NullableReferenceTypes): Replace with Construct(ImmutableArray<TypeSymbolWithAnnotations>).
/// <summary> /// <summary>
/// Apply type substitution to a generic method to create an method symbol with the given type parameters supplied. /// Apply type substitution to a generic method to create an method symbol with the given type parameters supplied.
/// </summary> /// </summary>
......
...@@ -81,7 +81,7 @@ public static MethodSymbol InferExtensionMethodTypeArguments(this MethodSymbol m ...@@ -81,7 +81,7 @@ public static MethodSymbol InferExtensionMethodTypeArguments(this MethodSymbol m
// This prevents constraint checking from failing for corresponding type parameters. // This prevents constraint checking from failing for corresponding type parameters.
var notInferredTypeParameters = PooledHashSet<TypeParameterSymbol>.GetInstance(); var notInferredTypeParameters = PooledHashSet<TypeParameterSymbol>.GetInstance();
var typeParams = method.TypeParameters; var typeParams = method.TypeParameters;
var typeArgsForConstraintsCheck = typeArgs.SelectAsArray(a => TypeSymbolWithAnnotations.Create(a)); var typeArgsForConstraintsCheck = typeArgs;
for (int i = 0; i < typeArgsForConstraintsCheck.Length; i++) for (int i = 0; i < typeArgsForConstraintsCheck.Length; i++)
{ {
if (typeArgsForConstraintsCheck[i].IsNull) if (typeArgsForConstraintsCheck[i].IsNull)
...@@ -140,12 +140,13 @@ public static MethodSymbol InferExtensionMethodTypeArguments(this MethodSymbol m ...@@ -140,12 +140,13 @@ public static MethodSymbol InferExtensionMethodTypeArguments(this MethodSymbol m
var typeArgsForConstruct = typeArgs; var typeArgsForConstruct = typeArgs;
if (firstNullInTypeArgs != -1) if (firstNullInTypeArgs != -1)
{ {
var builder = ArrayBuilder<TypeSymbol>.GetInstance(); var builder = ArrayBuilder<TypeSymbolWithAnnotations>.GetInstance();
builder.AddRange(typeArgs, firstNullInTypeArgs); builder.AddRange(typeArgs, firstNullInTypeArgs);
for (int i = firstNullInTypeArgs; i < typeArgsForConstruct.Length; i++) for (int i = firstNullInTypeArgs; i < typeArgsForConstruct.Length; i++)
{ {
builder.Add(typeArgsForConstruct[i] ?? typeParams[i]); var typeArgForConstruct = typeArgsForConstruct[i];
builder.Add(!typeArgForConstruct.IsNull ? typeArgForConstruct : TypeSymbolWithAnnotations.Create(typeParams[i]));
} }
typeArgsForConstruct = builder.ToImmutableAndFree(); typeArgsForConstruct = builder.ToImmutableAndFree();
......
...@@ -93,7 +93,7 @@ protected override void MethodChecks(DiagnosticBag diagnostics) ...@@ -93,7 +93,7 @@ protected override void MethodChecks(DiagnosticBag diagnostics)
diagnostics: diagnostics); diagnostics: diagnostics);
_lazyIsVararg = (arglistToken.Kind() == SyntaxKind.ArgListKeyword); _lazyIsVararg = (arglistToken.Kind() == SyntaxKind.ArgListKeyword);
_lazyReturnType = TypeSymbolWithAnnotations.Create(nonNullTypesContext: this, bodyBinder.GetSpecialType(SpecialType.System_Void, diagnostics, syntax)); _lazyReturnType = TypeSymbolWithAnnotations.Create(bodyBinder.GetSpecialType(SpecialType.System_Void, diagnostics, syntax));
var location = this.Locations[0]; var location = this.Locations[0];
if (MethodKind == MethodKind.StaticConstructor && (_lazyParameters.Length != 0)) if (MethodKind == MethodKind.StaticConstructor && (_lazyParameters.Length != 0))
......
...@@ -49,10 +49,10 @@ protected void InitializeParameters(ImmutableArray<ParameterSymbol> parameters) ...@@ -49,10 +49,10 @@ protected void InitializeParameters(ImmutableArray<ParameterSymbol> parameters)
var returnType = binder.BindType(returnTypeSyntax, diagnostics); var returnType = binder.BindType(returnTypeSyntax, diagnostics);
// reuse types to avoid reporting duplicate errors if missing: // reuse types to avoid reporting duplicate errors if missing:
var voidType = TypeSymbolWithAnnotations.Create(nonNullTypesContext: delegateType, binder.GetSpecialType(SpecialType.System_Void, diagnostics, syntax)); var voidType = TypeSymbolWithAnnotations.Create(binder.GetSpecialType(SpecialType.System_Void, diagnostics, syntax));
// PROTOTYPE(NullableReferenceTypes): Should the 'object' parameter be considered nullable? // PROTOTYPE(NullableReferenceTypes): Should the 'object' parameter be considered nullable?
var objectType = TypeSymbolWithAnnotations.Create(nonNullTypesContext: delegateType, binder.GetSpecialType(SpecialType.System_Object, diagnostics, syntax)); var objectType = TypeSymbolWithAnnotations.Create(nonNullTypesContext: delegateType, binder.GetSpecialType(SpecialType.System_Object, diagnostics, syntax));
var intPtrType = TypeSymbolWithAnnotations.Create(nonNullTypesContext: delegateType, binder.GetSpecialType(SpecialType.System_IntPtr, diagnostics, syntax)); var intPtrType = TypeSymbolWithAnnotations.Create(binder.GetSpecialType(SpecialType.System_IntPtr, diagnostics, syntax));
if (returnType.IsRestrictedType(ignoreSpanLikeTypes: true)) if (returnType.IsRestrictedType(ignoreSpanLikeTypes: true))
{ {
......
...@@ -373,7 +373,7 @@ private TypeSymbolWithAnnotations ComputeReturnType(DiagnosticBag diagnostics) ...@@ -373,7 +373,7 @@ private TypeSymbolWithAnnotations ComputeReturnType(DiagnosticBag diagnostics)
else else
{ {
var binder = GetBinder(); var binder = GetBinder();
return TypeSymbolWithAnnotations.Create(nonNullTypesContext: ContainingModule, binder.GetSpecialType(SpecialType.System_Void, diagnostics, this.GetSyntax())); return TypeSymbolWithAnnotations.Create(binder.GetSpecialType(SpecialType.System_Void, diagnostics, this.GetSyntax()));
} }
} }
......
...@@ -33,7 +33,7 @@ public override string Name ...@@ -33,7 +33,7 @@ public override string Name
public override TypeSymbolWithAnnotations Type public override TypeSymbolWithAnnotations Type
{ {
get { return TypeSymbolWithAnnotations.Create(_containingType); } get { return TypeSymbolWithAnnotations.Create(_containingType, isNullableIfReferenceType: false); }
} }
public override RefKind RefKind public override RefKind RefKind
......
...@@ -147,7 +147,7 @@ public override RefKind RefKind ...@@ -147,7 +147,7 @@ public override RefKind RefKind
public sealed override TypeSymbolWithAnnotations ReturnType public sealed override TypeSymbolWithAnnotations ReturnType
{ {
get { return TypeSymbolWithAnnotations.Create(nonNullTypesContext: ContainingModule, ContainingAssembly.GetSpecialType(SpecialType.System_Void)); } get { return TypeSymbolWithAnnotations.Create(ContainingAssembly.GetSpecialType(SpecialType.System_Void)); }
} }
public override ImmutableArray<CustomModifier> RefCustomModifiers public override ImmutableArray<CustomModifier> RefCustomModifiers
......
...@@ -132,7 +132,7 @@ public override TypeSymbolWithAnnotations ReturnType ...@@ -132,7 +132,7 @@ public override TypeSymbolWithAnnotations ReturnType
{ {
get get
{ {
return TypeSymbolWithAnnotations.Create(nonNullTypesContext: ContainingModule, ContainingAssembly.GetSpecialType(SpecialType.System_Void)); return TypeSymbolWithAnnotations.Create(ContainingAssembly.GetSpecialType(SpecialType.System_Void));
} }
} }
......
...@@ -197,7 +197,7 @@ private static NamedTypeSymbol ReplaceRestExtensionType(NamedTypeSymbol tupleCom ...@@ -197,7 +197,7 @@ private static NamedTypeSymbol ReplaceRestExtensionType(NamedTypeSymbol tupleCom
var typeArgumentsBuilder = ArrayBuilder<TypeSymbolWithAnnotations>.GetInstance(RestPosition); var typeArgumentsBuilder = ArrayBuilder<TypeSymbolWithAnnotations>.GetInstance(RestPosition);
var arguments = tupleCompatibleType.TypeArgumentsNoUseSiteDiagnostics; var arguments = tupleCompatibleType.TypeArgumentsNoUseSiteDiagnostics;
typeArgumentsBuilder.AddRange(arguments, RestPosition - 1); typeArgumentsBuilder.AddRange(arguments, RestPosition - 1);
typeArgumentsBuilder.Add(TypeSymbolWithAnnotations.Create(extensionTuple, arguments[RestPosition - 1].CustomModifiers)); typeArgumentsBuilder.Add(TypeSymbolWithAnnotations.Create(extensionTuple, customModifiers: arguments[RestPosition - 1].CustomModifiers));
tupleCompatibleType = tupleCompatibleType.ConstructedFrom.Construct(typeArgumentsBuilder.ToImmutableAndFree(), unbound: false); tupleCompatibleType = tupleCompatibleType.ConstructedFrom.Construct(typeArgumentsBuilder.ToImmutableAndFree(), unbound: false);
return tupleCompatibleType; return tupleCompatibleType;
......
...@@ -16,8 +16,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols ...@@ -16,8 +16,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// </summary> /// </summary>
internal sealed class TypeMap : AbstractTypeParameterMap internal sealed class TypeMap : AbstractTypeParameterMap
{ {
// PROTOTYPE(NullableReferenceTypes): [Obsolete("Use TypeParametersAsTypeSymbolsWithAnnotations")]
public static readonly System.Func<TypeSymbol, TypeSymbolWithAnnotations> AsTypeSymbolWithAnnotations = t => TypeSymbolWithAnnotations.Create(t);
public static readonly System.Func<TypeSymbolWithAnnotations, TypeSymbol> AsTypeSymbol = t => t.TypeSymbol; public static readonly System.Func<TypeSymbolWithAnnotations, TypeSymbol> AsTypeSymbol = t => t.TypeSymbol;
internal static ImmutableArray<TypeSymbolWithAnnotations> TypeParametersAsTypeSymbolsWithAnnotations(INonNullTypesContext nonNullTypesContext, ImmutableArray<TypeParameterSymbol> typeParameters) internal static ImmutableArray<TypeSymbolWithAnnotations> TypeParametersAsTypeSymbolsWithAnnotations(INonNullTypesContext nonNullTypesContext, ImmutableArray<TypeParameterSymbol> typeParameters)
......
...@@ -1500,7 +1500,7 @@ private static bool NormalizeTaskTypesInType(CSharpCompilation compilation, ref ...@@ -1500,7 +1500,7 @@ private static bool NormalizeTaskTypesInType(CSharpCompilation compilation, ref
var type = typeWithAnnotations.TypeSymbol; var type = typeWithAnnotations.TypeSymbol;
if (NormalizeTaskTypesInType(compilation, ref type)) if (NormalizeTaskTypesInType(compilation, ref type))
{ {
typeWithAnnotations = TypeSymbolWithAnnotations.Create(type, typeWithAnnotations.CustomModifiers); typeWithAnnotations = TypeSymbolWithAnnotations.Create(type, customModifiers: typeWithAnnotations.CustomModifiers);
return true; return true;
} }
return false; return false;
...@@ -1524,7 +1524,7 @@ private static bool NormalizeTaskTypesInNamedType(CSharpCompilation compilation, ...@@ -1524,7 +1524,7 @@ private static bool NormalizeTaskTypesInNamedType(CSharpCompilation compilation,
{ {
hasChanged = true; hasChanged = true;
// Preserve custom modifiers but without normalizing those types. // Preserve custom modifiers but without normalizing those types.
typeArgumentsBuilder[i] = TypeSymbolWithAnnotations.Create(typeArgNormalized, typeWithModifier.CustomModifiers); typeArgumentsBuilder[i] = TypeSymbolWithAnnotations.Create(typeArgNormalized, customModifiers: typeWithModifier.CustomModifiers);
} }
} }
if (hasChanged) if (hasChanged)
......
...@@ -161,13 +161,6 @@ internal static TypeSymbolWithAnnotations Create(INonNullTypesContext nonNullTyp ...@@ -161,13 +161,6 @@ internal static TypeSymbolWithAnnotations Create(INonNullTypesContext nonNullTyp
return CreateNonLazyType(typeSymbol, nonNullTypesContext, isAnnotated: isAnnotated, treatUnconstrainedTypeParameterAsNullable: true, customModifiers.NullToEmpty()); return CreateNonLazyType(typeSymbol, nonNullTypesContext, isAnnotated: isAnnotated, treatUnconstrainedTypeParameterAsNullable: true, customModifiers.NullToEmpty());
} }
// PROTOTYPE(NullableReferenceTypes): Remove this method and rewrite callers to use other overloads.
//[Obsolete]
public static TypeSymbolWithAnnotations Create(TypeSymbol typeSymbol, ImmutableArray<CustomModifier> customModifiers = default)
{
return Create(NonNullTypesTrueContext.Instance, typeSymbol, customModifiers: customModifiers);
}
// PROTOTYPE(NullableReferenceTypes): Check we are not using this method on type references in // PROTOTYPE(NullableReferenceTypes): Check we are not using this method on type references in
// member signatures visible outside the assembly. Consider overriding, implementing, NoPIA embedding, etc. // member signatures visible outside the assembly. Consider overriding, implementing, NoPIA embedding, etc.
...@@ -180,7 +173,7 @@ public static TypeSymbolWithAnnotations Create(TypeSymbol typeSymbol, ImmutableA ...@@ -180,7 +173,7 @@ public static TypeSymbolWithAnnotations Create(TypeSymbol typeSymbol, ImmutableA
/// <see cref="IsNullable"/> is determined by state other than <see cref="IsAnnotated"/> /// <see cref="IsNullable"/> is determined by state other than <see cref="IsAnnotated"/>
/// (in flow analysis for instance). /// (in flow analysis for instance).
/// </remarks> /// </remarks>
public static TypeSymbolWithAnnotations Create(TypeSymbol typeSymbol, bool? isNullableIfReferenceType, ImmutableArray<CustomModifier> customModifiers = default) public static TypeSymbolWithAnnotations Create(TypeSymbol typeSymbol, bool? isNullableIfReferenceType = null, ImmutableArray<CustomModifier> customModifiers = default)
{ {
if (typeSymbol is null) if (typeSymbol is null)
{ {
...@@ -465,6 +458,8 @@ public bool IsAtLeastAsVisibleAs(Symbol sym, ref HashSet<DiagnosticInfo> useSite ...@@ -465,6 +458,8 @@ public bool IsAtLeastAsVisibleAs(Symbol sym, ref HashSet<DiagnosticInfo> useSite
public TypeSymbolWithAnnotations SubstituteTypeWithTupleUnification(AbstractTypeMap typeMap) => public TypeSymbolWithAnnotations SubstituteTypeWithTupleUnification(AbstractTypeMap typeMap) =>
_extensions.SubstituteType(this, typeMap, withTupleUnification: true); _extensions.SubstituteType(this, typeMap, withTupleUnification: true);
internal TypeSymbolWithAnnotations TransformToTupleIfCompatible() => _extensions.TransformToTupleIfCompatible(this);
internal TypeSymbolWithAnnotations SubstituteTypeCore(AbstractTypeMap typeMap, bool withTupleUnification) internal TypeSymbolWithAnnotations SubstituteTypeCore(AbstractTypeMap typeMap, bool withTupleUnification)
{ {
var newCustomModifiers = typeMap.SubstituteCustomModifiers(this.CustomModifiers); var newCustomModifiers = typeMap.SubstituteCustomModifiers(this.CustomModifiers);
...@@ -758,6 +753,7 @@ internal static Extensions CreateLazy(CSharpCompilation compilation, TypeSymbolW ...@@ -758,6 +753,7 @@ internal static Extensions CreateLazy(CSharpCompilation compilation, TypeSymbolW
internal abstract bool TypeSymbolEquals(TypeSymbolWithAnnotations type, TypeSymbolWithAnnotations other, TypeCompareKind comparison); internal abstract bool TypeSymbolEquals(TypeSymbolWithAnnotations type, TypeSymbolWithAnnotations other, TypeCompareKind comparison);
internal abstract TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotations type, AbstractTypeMap typeMap, bool withTupleUnification); internal abstract TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotations type, AbstractTypeMap typeMap, bool withTupleUnification);
internal abstract TypeSymbolWithAnnotations TransformToTupleIfCompatible(TypeSymbolWithAnnotations type);
internal abstract void ReportDiagnosticsIfObsolete(TypeSymbolWithAnnotations type, Binder binder, SyntaxNode syntax, DiagnosticBag diagnostics); internal abstract void ReportDiagnosticsIfObsolete(TypeSymbolWithAnnotations type, Binder binder, SyntaxNode syntax, DiagnosticBag diagnostics);
} }
...@@ -844,6 +840,17 @@ internal override TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotat ...@@ -844,6 +840,17 @@ internal override TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotat
return type.SubstituteTypeCore(typeMap, withTupleUnification); return type.SubstituteTypeCore(typeMap, withTupleUnification);
} }
internal override TypeSymbolWithAnnotations TransformToTupleIfCompatible(TypeSymbolWithAnnotations type)
{
var defaultType = type._defaultType;
var transformedType = TupleTypeSymbol.TransformToTupleIfCompatible(defaultType);
if ((object)defaultType != transformedType)
{
return TypeSymbolWithAnnotations.Create(transformedType, type.IsNullable, _customModifiers);
}
return type;
}
internal override void ReportDiagnosticsIfObsolete(TypeSymbolWithAnnotations type, Binder binder, SyntaxNode syntax, DiagnosticBag diagnostics) internal override void ReportDiagnosticsIfObsolete(TypeSymbolWithAnnotations type, Binder binder, SyntaxNode syntax, DiagnosticBag diagnostics)
{ {
type.ReportDiagnosticsIfObsoleteCore(binder, syntax, diagnostics); type.ReportDiagnosticsIfObsoleteCore(binder, syntax, diagnostics);
...@@ -945,7 +952,7 @@ internal override TypeSymbolWithAnnotations WithModifiers(TypeSymbolWithAnnotati ...@@ -945,7 +952,7 @@ internal override TypeSymbolWithAnnotations WithModifiers(TypeSymbolWithAnnotati
var resolvedType = GetResolvedType(); var resolvedType = GetResolvedType();
if (resolvedType.IsNullableType()) if (resolvedType.IsNullableType())
{ {
return TypeSymbolWithAnnotations.Create(resolvedType, customModifiers); return TypeSymbolWithAnnotations.Create(resolvedType, customModifiers: customModifiers);
} }
return TypeSymbolWithAnnotations.CreateNonLazyType(resolvedType, type.NonNullTypesContext, isAnnotated: true, treatUnconstrainedTypeParameterAsNullable: false, customModifiers); return TypeSymbolWithAnnotations.CreateNonLazyType(resolvedType, type.NonNullTypesContext, isAnnotated: true, treatUnconstrainedTypeParameterAsNullable: false, customModifiers);
...@@ -960,7 +967,7 @@ internal override TypeSymbolWithAnnotations WithTypeAndModifiers(TypeSymbolWithA ...@@ -960,7 +967,7 @@ internal override TypeSymbolWithAnnotations WithTypeAndModifiers(TypeSymbolWithA
{ {
if (typeSymbol.IsNullableType()) if (typeSymbol.IsNullableType())
{ {
return TypeSymbolWithAnnotations.Create(typeSymbol, customModifiers); return TypeSymbolWithAnnotations.Create(typeSymbol, customModifiers: customModifiers);
} }
return TypeSymbolWithAnnotations.CreateNonLazyType(typeSymbol, type.NonNullTypesContext, isAnnotated: true, type._treatUnconstrainedTypeParameterAsNullable, customModifiers); return TypeSymbolWithAnnotations.CreateNonLazyType(typeSymbol, type.NonNullTypesContext, isAnnotated: true, type._treatUnconstrainedTypeParameterAsNullable, customModifiers);
...@@ -1005,6 +1012,11 @@ internal override TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotat ...@@ -1005,6 +1012,11 @@ internal override TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotat
} }
} }
internal override TypeSymbolWithAnnotations TransformToTupleIfCompatible(TypeSymbolWithAnnotations type)
{
return type;
}
internal override void ReportDiagnosticsIfObsolete(TypeSymbolWithAnnotations type, Binder binder, SyntaxNode syntax, DiagnosticBag diagnostics) internal override void ReportDiagnosticsIfObsolete(TypeSymbolWithAnnotations type, Binder binder, SyntaxNode syntax, DiagnosticBag diagnostics)
{ {
if ((object)_resolved != null) if ((object)_resolved != null)
......
...@@ -21,9 +21,7 @@ public static bool CanUnify(TypeSymbol t1, TypeSymbol t2) ...@@ -21,9 +21,7 @@ public static bool CanUnify(TypeSymbol t1, TypeSymbol t2)
} }
MutableTypeMap substitution = null; MutableTypeMap substitution = null;
bool result = CanUnifyHelper(TypeSymbolWithAnnotations.Create(t1), bool result = CanUnifyHelper(t1, t2, ref substitution);
TypeSymbolWithAnnotations.Create(t2),
ref substitution);
#if DEBUG #if DEBUG
if (result && ((object)t1 != null && (object)t2 != null)) if (result && ((object)t1 != null && (object)t2 != null))
{ {
...@@ -54,6 +52,11 @@ private static TypeSymbolWithAnnotations SubstituteAllTypeParameters(AbstractTyp ...@@ -54,6 +52,11 @@ private static TypeSymbolWithAnnotations SubstituteAllTypeParameters(AbstractTyp
} }
#endif #endif
private static bool CanUnifyHelper(TypeSymbol t1, TypeSymbol t2, ref MutableTypeMap substitution)
{
return CanUnifyHelper(TypeSymbolWithAnnotations.Create(t1), TypeSymbolWithAnnotations.Create(t2), ref substitution);
}
/// <summary> /// <summary>
/// Determine whether there is any substitution of type parameters that will /// Determine whether there is any substitution of type parameters that will
/// make two types identical. /// make two types identical.
...@@ -156,7 +159,7 @@ private static bool CanUnifyHelper(TypeSymbolWithAnnotations t1, TypeSymbolWithA ...@@ -156,7 +159,7 @@ private static bool CanUnifyHelper(TypeSymbolWithAnnotations t1, TypeSymbolWithA
return false; return false;
} }
return CanUnifyHelper(TypeSymbolWithAnnotations.Create(nt1.TupleUnderlyingType), TypeSymbolWithAnnotations.Create(nt2.TupleUnderlyingType), ref substitution); return CanUnifyHelper(nt1.TupleUnderlyingType, nt2.TupleUnderlyingType, ref substitution);
} }
if (!nt1.IsGenericType) if (!nt1.IsGenericType)
...@@ -190,7 +193,7 @@ private static bool CanUnifyHelper(TypeSymbolWithAnnotations t1, TypeSymbolWithA ...@@ -190,7 +193,7 @@ private static bool CanUnifyHelper(TypeSymbolWithAnnotations t1, TypeSymbolWithA
// Note: Dev10 folds this into the loop since GetTypeArgsAll includes type args for containing types // Note: Dev10 folds this into the loop since GetTypeArgsAll includes type args for containing types
// TODO: Calling CanUnifyHelper for the containing type is an overkill, we simply need to go through type arguments for all containers. // TODO: Calling CanUnifyHelper for the containing type is an overkill, we simply need to go through type arguments for all containers.
return (object)nt1.ContainingType == null || CanUnifyHelper(TypeSymbolWithAnnotations.Create(nt1.ContainingType), TypeSymbolWithAnnotations.Create(nt2.ContainingType), ref substitution); return (object)nt1.ContainingType == null || CanUnifyHelper(nt1.ContainingType, nt2.ContainingType, ref substitution);
} }
case SymbolKind.TypeParameter: case SymbolKind.TypeParameter:
{ {
...@@ -225,8 +228,8 @@ private static bool CanUnifyHelper(TypeSymbolWithAnnotations t1, TypeSymbolWithA ...@@ -225,8 +228,8 @@ private static bool CanUnifyHelper(TypeSymbolWithAnnotations t1, TypeSymbolWithA
t1.CustomModifiers.SequenceEqual(t2.CustomModifiers.Take(t1.CustomModifiers.Length))) t1.CustomModifiers.SequenceEqual(t2.CustomModifiers.Take(t1.CustomModifiers.Length)))
{ {
AddSubstitution(ref substitution, tp1, AddSubstitution(ref substitution, tp1,
TypeSymbolWithAnnotations.Create(t2.TypeSymbol, TypeSymbolWithAnnotations.Create(t2.TypeSymbol,
ImmutableArray.Create(t2.CustomModifiers, t1.CustomModifiers.Length, t2.CustomModifiers.Length - t1.CustomModifiers.Length))); customModifiers: ImmutableArray.Create(t2.CustomModifiers, t1.CustomModifiers.Length, t2.CustomModifiers.Length - t1.CustomModifiers.Length)));
return true; return true;
} }
...@@ -244,8 +247,8 @@ private static bool CanUnifyHelper(TypeSymbolWithAnnotations t1, TypeSymbolWithA ...@@ -244,8 +247,8 @@ private static bool CanUnifyHelper(TypeSymbolWithAnnotations t1, TypeSymbolWithA
t2.CustomModifiers.SequenceEqual(t1.CustomModifiers.Take(t2.CustomModifiers.Length))) t2.CustomModifiers.SequenceEqual(t1.CustomModifiers.Take(t2.CustomModifiers.Length)))
{ {
AddSubstitution(ref substitution, tp2, AddSubstitution(ref substitution, tp2,
TypeSymbolWithAnnotations.Create(t1.TypeSymbol, TypeSymbolWithAnnotations.Create(t1.TypeSymbol,
ImmutableArray.Create(t1.CustomModifiers, t2.CustomModifiers.Length, t1.CustomModifiers.Length - t2.CustomModifiers.Length))); customModifiers: ImmutableArray.Create(t1.CustomModifiers, t2.CustomModifiers.Length, t1.CustomModifiers.Length - t2.CustomModifiers.Length)));
return true; return true;
} }
} }
......
...@@ -5270,12 +5270,12 @@ class B : A ...@@ -5270,12 +5270,12 @@ class B : A
foreach (string memberName in new[] { "M1", "M2" }) foreach (string memberName in new[] { "M1", "M2" })
{ {
var member = b.GetMember<MethodSymbol>(memberName); var member = b.GetMember<MethodSymbol>(memberName);
Assert.False(member.ReturnType.Equals(member.OverriddenMethod.ConstructIfGeneric(member.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)).ReturnType, Assert.False(member.ReturnType.Equals(member.OverriddenMethod.ConstructIfGeneric(member.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t))).ReturnType,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes)); TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
} }
var m3 = b.GetMember<MethodSymbol>("M3"); var m3 = b.GetMember<MethodSymbol>("M3");
Assert.True(m3.ReturnType.Equals(m3.OverriddenMethod.ConstructIfGeneric(m3.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)).ReturnType, Assert.True(m3.ReturnType.Equals(m3.OverriddenMethod.ConstructIfGeneric(m3.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t))).ReturnType,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes)); TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
} }
...@@ -5387,7 +5387,7 @@ class B : IA ...@@ -5387,7 +5387,7 @@ class B : IA
{ {
var member = ia.GetMember<MethodSymbol>(memberName); var member = ia.GetMember<MethodSymbol>(memberName);
var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member); var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member);
var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)); var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t)));
Assert.False(implementing.ReturnType.Equals(implemented.ReturnType, Assert.False(implementing.ReturnType.Equals(implemented.ReturnType,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes)); TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
} }
...@@ -5395,7 +5395,7 @@ class B : IA ...@@ -5395,7 +5395,7 @@ class B : IA
{ {
var member = ia.GetMember<MethodSymbol>("M3"); var member = ia.GetMember<MethodSymbol>("M3");
var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member); var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member);
var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)); var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t)));
Assert.True(implementing.ReturnType.Equals(implemented.ReturnType, Assert.True(implementing.ReturnType.Equals(implemented.ReturnType,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes)); TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
} }
...@@ -5455,7 +5455,7 @@ class B : IA ...@@ -5455,7 +5455,7 @@ class B : IA
{ {
var member = ia.GetMember<MethodSymbol>(memberName); var member = ia.GetMember<MethodSymbol>(memberName);
var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member); var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member);
var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)); var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t)));
Assert.False(implementing.ReturnType.Equals(implemented.ReturnType, Assert.False(implementing.ReturnType.Equals(implemented.ReturnType,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes)); TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
} }
...@@ -5463,7 +5463,7 @@ class B : IA ...@@ -5463,7 +5463,7 @@ class B : IA
{ {
var member = ia.GetMember<MethodSymbol>("M3"); var member = ia.GetMember<MethodSymbol>("M3");
var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member); var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member);
var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)); var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t)));
Assert.True(implementing.ReturnType.Equals(implemented.ReturnType, Assert.True(implementing.ReturnType.Equals(implemented.ReturnType,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes)); TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
} }
...@@ -5620,12 +5620,12 @@ public override void M3<T>(T?[]? x) ...@@ -5620,12 +5620,12 @@ public override void M3<T>(T?[]? x)
foreach (string memberName in new[] { "M1", "M2" }) foreach (string memberName in new[] { "M1", "M2" })
{ {
var member = b.GetMember<MethodSymbol>(memberName); var member = b.GetMember<MethodSymbol>(memberName);
Assert.False(member.Parameters[0].Type.Equals(member.OverriddenMethod.ConstructIfGeneric(member.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)).Parameters[0].Type, Assert.False(member.Parameters[0].Type.Equals(member.OverriddenMethod.ConstructIfGeneric(member.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t))).Parameters[0].Type,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes)); TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
} }
var m3 = b.GetMember<MethodSymbol>("M3"); var m3 = b.GetMember<MethodSymbol>("M3");
Assert.True(m3.Parameters[0].Type.Equals(m3.OverriddenMethod.ConstructIfGeneric(m3.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)).Parameters[0].Type, Assert.True(m3.Parameters[0].Type.Equals(m3.OverriddenMethod.ConstructIfGeneric(m3.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t))).Parameters[0].Type,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes)); TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
} }
...@@ -5839,7 +5839,7 @@ public void M1(string?[] x) ...@@ -5839,7 +5839,7 @@ public void M1(string?[] x)
{ {
var member = ia.GetMember<MethodSymbol>(memberName); var member = ia.GetMember<MethodSymbol>(memberName);
var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member); var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member);
var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)); var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t)));
Assert.False(implementing.Parameters[0].Type.Equals(implemented.Parameters[0].Type, Assert.False(implementing.Parameters[0].Type.Equals(implemented.Parameters[0].Type,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes)); TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
} }
...@@ -5847,7 +5847,7 @@ public void M1(string?[] x) ...@@ -5847,7 +5847,7 @@ public void M1(string?[] x)
{ {
var member = ia.GetMember<MethodSymbol>("M3"); var member = ia.GetMember<MethodSymbol>("M3");
var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member); var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member);
var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)); var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t)));
Assert.True(implementing.Parameters[0].Type.Equals(implemented.Parameters[0].Type, Assert.True(implementing.Parameters[0].Type.Equals(implemented.Parameters[0].Type,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes)); TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
} }
...@@ -5902,7 +5902,7 @@ void IA.M3<T>(T?[]? x) ...@@ -5902,7 +5902,7 @@ void IA.M3<T>(T?[]? x)
{ {
var member = ia.GetMember<MethodSymbol>(memberName); var member = ia.GetMember<MethodSymbol>(memberName);
var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member); var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member);
var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)); var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t)));
Assert.False(implementing.Parameters[0].Type.Equals(implemented.Parameters[0].Type, Assert.False(implementing.Parameters[0].Type.Equals(implemented.Parameters[0].Type,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes)); TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
} }
...@@ -5910,7 +5910,7 @@ void IA.M3<T>(T?[]? x) ...@@ -5910,7 +5910,7 @@ void IA.M3<T>(T?[]? x)
{ {
var member = ia.GetMember<MethodSymbol>("M3"); var member = ia.GetMember<MethodSymbol>("M3");
var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member); var implementing = (MethodSymbol)b.FindImplementationForInterfaceMember(member);
var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)); var implemented = member.ConstructIfGeneric(implementing.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t)));
Assert.True(implementing.Parameters[0].Type.Equals(implemented.Parameters[0].Type, Assert.True(implementing.Parameters[0].Type.Equals(implemented.Parameters[0].Type,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes)); TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
} }
...@@ -6210,7 +6210,7 @@ partial class C1 ...@@ -6210,7 +6210,7 @@ partial class C1
var m1 = c1.GetMember<MethodSymbol>("M1"); var m1 = c1.GetMember<MethodSymbol>("M1");
var m1Impl = m1.PartialImplementationPart; var m1Impl = m1.PartialImplementationPart;
var m1Def = m1.ConstructIfGeneric(m1Impl.TypeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)); var m1Def = m1.ConstructIfGeneric(m1Impl.TypeParameters.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t)));
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
...@@ -19614,15 +19614,11 @@ static void F(object? x) ...@@ -19614,15 +19614,11 @@ static void F(object? x)
var z = y => y ?? x.ToString(); var z = y => y ?? x.ToString();
} }
}"; }";
// PROTOTYPE(NullableReferenceTypes): Should not report HDN_ExpressionIsProbablyNeverNull for `y`.
var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }); var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition });
comp.VerifyDiagnostics( comp.VerifyDiagnostics(
// (5,13): error CS0815: Cannot assign lambda expression to an implicitly-typed variable // (5,13): error CS0815: Cannot assign lambda expression to an implicitly-typed variable
// var z = y => y ?? x.ToString(); // var z = y => y ?? x.ToString();
Diagnostic(ErrorCode.ERR_ImplicitlyTypedVariableAssignedBadValue, "z = y => y ?? x.ToString()").WithArguments("lambda expression").WithLocation(5, 13), Diagnostic(ErrorCode.ERR_ImplicitlyTypedVariableAssignedBadValue, "z = y => y ?? x.ToString()").WithArguments("lambda expression").WithLocation(5, 13),
// (5,22): hidden CS8607: Expression is probably never null.
// var z = y => y ?? x.ToString();
Diagnostic(ErrorCode.HDN_ExpressionIsProbablyNeverNull, "y").WithLocation(5, 22),
// (5,27): warning CS8602: Possible dereference of a null reference. // (5,27): warning CS8602: Possible dereference of a null reference.
// var z = y => y ?? x.ToString(); // var z = y => y ?? x.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x").WithLocation(5, 27)); Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x").WithLocation(5, 27));
...@@ -30947,16 +30943,11 @@ static void G() ...@@ -30947,16 +30943,11 @@ static void G()
F(v).ToString(); F(v).ToString();
} }
}"; }";
// 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 }); var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition });
comp.VerifyDiagnostics( comp.VerifyDiagnostics(
// (12,21): error CS8197: Cannot infer the type of implicitly-typed out variable 'v'. // (12,21): error CS8197: Cannot infer the type of implicitly-typed out variable 'v'.
// d.F(out var v); // d.F(out var v);
Diagnostic(ErrorCode.ERR_TypeInferenceFailedForImplicitlyTypedOutVariable, "v").WithArguments("v").WithLocation(12, 21), Diagnostic(ErrorCode.ERR_TypeInferenceFailedForImplicitlyTypedOutVariable, "v").WithArguments("v").WithLocation(12, 21));
// (13,9): warning CS8602: Possible dereference of a null reference.
// F(v).ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(v)").WithLocation(13, 9));
} }
[Fact] [Fact]
...@@ -35093,8 +35084,6 @@ static void G() ...@@ -35093,8 +35084,6 @@ static void G()
F(default).ToString(); F(default).ToString();
} }
}"; }";
// ErrorCode.WRN_NullReferenceReceiver is reported for F(default).ToString() because F(v)
// has type T from initial binding (see https://github.com/dotnet/roslyn/issues/25778).
var comp = CreateCompilation( var comp = CreateCompilation(
new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition }, new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition },
parseOptions: TestOptions.Regular8); parseOptions: TestOptions.Regular8);
...@@ -35107,10 +35096,7 @@ static void G() ...@@ -35107,10 +35096,7 @@ static void G()
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(default(object))").WithLocation(6, 9), Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(default(object))").WithLocation(6, 9),
// (8,9): warning CS8602: Possible dereference of a null reference. // (8,9): warning CS8602: Possible dereference of a null reference.
// F(default(string)).ToString(); // F(default(string)).ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(default(string))").WithLocation(8, 9), Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(default(string))").WithLocation(8, 9));
// (9,9): warning CS8602: Possible dereference of a null reference.
// F(default).ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(default)").WithLocation(9, 9));
} }
[Fact] [Fact]
...@@ -149,8 +149,8 @@ struct S<T> where T : struct ...@@ -149,8 +149,8 @@ struct S<T> where T : struct
var structType = comp.GlobalNamespace.GetMember<NamedTypeSymbol>("S"); var structType = comp.GlobalNamespace.GetMember<NamedTypeSymbol>("S");
var typeParamType = structType.TypeParameters.Single(); var typeParamType = structType.TypeParameters.Single();
var pointerType = new PointerTypeSymbol(TypeSymbolWithAnnotations.Create(typeParamType, customModifiers)); // NOTE: We're constructing this manually, since it's illegal. var pointerType = new PointerTypeSymbol(TypeSymbolWithAnnotations.Create(typeParamType, customModifiers: customModifiers)); // NOTE: We're constructing this manually, since it's illegal.
var arrayType = ArrayTypeSymbol.CreateCSharpArray(comp.Assembly, TypeSymbolWithAnnotations.Create(typeParamType, customModifiers)); // This is legal, but we're already manually constructing types. var arrayType = ArrayTypeSymbol.CreateCSharpArray(comp.Assembly, TypeSymbolWithAnnotations.Create(typeParamType, customModifiers: customModifiers)); // This is legal, but we're already manually constructing types.
var typeMap = new TypeMap(ImmutableArray.Create(typeParamType), ImmutableArray.Create(TypeSymbolWithAnnotations.Create(intType))); var typeMap = new TypeMap(ImmutableArray.Create(typeParamType), ImmutableArray.Create(TypeSymbolWithAnnotations.Create(intType)));
......
...@@ -90,7 +90,7 @@ private static NamedTypeSymbol DeepConstruct(NamedTypeSymbol type, ImmutableArra ...@@ -90,7 +90,7 @@ private static NamedTypeSymbol DeepConstruct(NamedTypeSymbol type, ImmutableArra
Assert.True(type.IsDefinition); Assert.True(type.IsDefinition);
var allTypeParameters = ArrayBuilder<TypeParameterSymbol>.GetInstance(); var allTypeParameters = ArrayBuilder<TypeParameterSymbol>.GetInstance();
type.GetAllTypeParameters(allTypeParameters); type.GetAllTypeParameters(allTypeParameters);
return new TypeMap(allTypeParameters.ToImmutableAndFree(), typeArguments.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations)).SubstituteNamedType(type); return new TypeMap(allTypeParameters.ToImmutableAndFree(), typeArguments.SelectAsArray(t => TypeSymbolWithAnnotations.Create(t))).SubstituteNamedType(type);
} }
[Fact] [Fact]
......
...@@ -117,7 +117,7 @@ internal override MethodSymbol ConstructMethod(MethodSymbol method, ImmutableArr ...@@ -117,7 +117,7 @@ internal override MethodSymbol ConstructMethod(MethodSymbol method, ImmutableArr
var methodArgumentStartIndex = typeParameters.Length - methodArity; var methodArgumentStartIndex = typeParameters.Length - methodArity;
var typeMap = new TypeMap( var typeMap = new TypeMap(
ImmutableArray.Create(typeParameters, 0, methodArgumentStartIndex), ImmutableArray.Create(typeParameters, 0, methodArgumentStartIndex),
ImmutableArray.CreateRange(typeArguments, 0, methodArgumentStartIndex, TypeMap.AsTypeSymbolWithAnnotations)); ImmutableArray.CreateRange(typeArguments, 0, methodArgumentStartIndex, t => TypeSymbolWithAnnotations.Create(t)));
var substitutedType = typeMap.SubstituteNamedType(method.ContainingType); var substitutedType = typeMap.SubstituteNamedType(method.ContainingType);
method = method.AsMember(substitutedType); method = method.AsMember(substitutedType);
if (methodArity > 0) if (methodArity > 0)
......
...@@ -299,7 +299,7 @@ public override TypeSymbolWithAnnotations ReturnType ...@@ -299,7 +299,7 @@ public override TypeSymbolWithAnnotations ReturnType
public override ImmutableArray<TypeSymbolWithAnnotations> TypeArguments public override ImmutableArray<TypeSymbolWithAnnotations> TypeArguments
{ {
get { return _typeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations); } get { return GetTypeParametersAsTypeArguments(); }
} }
public override ImmutableArray<TypeParameterSymbol> TypeParameters public override ImmutableArray<TypeParameterSymbol> TypeParameters
......
...@@ -122,7 +122,7 @@ public override ImmutableArray<TypeParameterSymbol> TypeParameters ...@@ -122,7 +122,7 @@ public override ImmutableArray<TypeParameterSymbol> TypeParameters
internal override ImmutableArray<TypeSymbolWithAnnotations> TypeArgumentsNoUseSiteDiagnostics internal override ImmutableArray<TypeSymbolWithAnnotations> TypeArgumentsNoUseSiteDiagnostics
{ {
get { return _typeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations); } get { return GetTypeParametersAsTypeArguments(); }
} }
public override NamedTypeSymbol ConstructedFrom public override NamedTypeSymbol ConstructedFrom
......
...@@ -165,7 +165,7 @@ public override ImmutableArray<CustomModifier> RefCustomModifiers ...@@ -165,7 +165,7 @@ public override ImmutableArray<CustomModifier> RefCustomModifiers
public override ImmutableArray<TypeSymbolWithAnnotations> TypeArguments public override ImmutableArray<TypeSymbolWithAnnotations> TypeArguments
{ {
get { return _typeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations); } get { return GetTypeParametersAsTypeArguments(); }
} }
public override ImmutableArray<TypeParameterSymbol> TypeParameters public override ImmutableArray<TypeParameterSymbol> TypeParameters
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册