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

Remove obsolete TypeSymbolWithAnnotations.Create method (#29344)

上级 d37fd83f
......@@ -457,7 +457,7 @@ private static TypeSymbol MakeMergedTupleType(ArrayBuilder<DeconstructionVariabl
int leftLength = lhsVariables.Count;
int rightLength = rhsLiteral.Arguments.Length;
var typesBuilder = ArrayBuilder<TypeSymbol>.GetInstance(leftLength);
var typesBuilder = ArrayBuilder<TypeSymbolWithAnnotations>.GetInstance(leftLength);
var locationsBuilder = ArrayBuilder<Location>.GetInstance(leftLength);
for (int i = 0; i < rightLength; i++)
{
......@@ -498,11 +498,11 @@ private static TypeSymbol MakeMergedTupleType(ArrayBuilder<DeconstructionVariabl
}
}
typesBuilder.Add(mergedType);
typesBuilder.Add(TypeSymbolWithAnnotations.Create(mergedType));
locationsBuilder.Add(element.Syntax.Location);
}
if (typesBuilder.Any(t => t == null))
if (typesBuilder.Any(t => t.IsNull))
{
typesBuilder.Free();
locationsBuilder.Free();
......@@ -514,7 +514,7 @@ private static TypeSymbol MakeMergedTupleType(ArrayBuilder<DeconstructionVariabl
// tree of types used for figuring out natural types in tuple literal.
return TupleTypeSymbol.Create(
locationOpt: null,
elementTypes: typesBuilder.ToImmutableAndFree().SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations), // PROTOTYPE(NullableTypeReferences): Not including nullability.
elementTypes: typesBuilder.ToImmutableAndFree(),
elementLocations: locationsBuilder.ToImmutableAndFree(),
elementNames: default(ImmutableArray<string>),
compilation: compilation,
......
......@@ -779,7 +779,7 @@ private BoundExpression BindTupleExpression(TupleExpressionSyntax node, Diagnost
boundArguments.Add(boundArgument);
var elementType = TypeSymbolWithAnnotations.Create(boundArgument.Type, isNullableIfReferenceType: null);
var elementType = TypeSymbolWithAnnotations.Create(boundArgument.Type);
elementTypes.Add(elementType);
if (elementType.IsNull)
......@@ -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.
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,
sizes: ImmutableArray<BoundExpression>.Empty, boundInitExprOpt: boundInitializerExpressions);
}
......@@ -2747,7 +2747,7 @@ private BoundExpression BindImplicitStackAllocArrayCreationExpression(ImplicitSt
return BindStackAllocWithInitializer(
node,
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,
sizeOpt: null,
diagnostics,
......
......@@ -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)
: operandType ?? CreateErrorType()));
: operandType ?? CreateErrorType();
TypeSymbol pointerType = new PointerTypeSymbol(TypeSymbolWithAnnotations.Create(pointedAtType));
return new BoundAddressOfOperator(node, operand, pointerType, hasErrors);
}
......
......@@ -889,7 +889,7 @@ protected BoundExpression BindInferredVariableInitializer(DiagnosticBag diagnost
TypeSymbol initializerType = initializerOpt?.Type;
if ((object)initializerType != null)
{
declTypeOpt = TypeSymbolWithAnnotations.Create(initializerType, isNullableIfReferenceType: null);
declTypeOpt = TypeSymbolWithAnnotations.Create(initializerType);
if (declTypeOpt.SpecialType == SpecialType.System_Void)
{
......
......@@ -226,7 +226,7 @@ private BoundForEachStatement BindForEachPartsWorker(DiagnosticBag diagnostics,
if (isVar)
{
declType = inferredType.IsNull ? TypeSymbolWithAnnotations.Create(CreateErrorType("var"), isNullableIfReferenceType: null) : inferredType;
declType = inferredType.IsNull ? TypeSymbolWithAnnotations.Create(CreateErrorType("var")) : inferredType;
}
else
{
......@@ -497,7 +497,7 @@ private bool GetEnumeratorInfoAndInferCollectionElementType(ref ForEachEnumerato
else if (collectionExpr.HasDynamicType())
{
// 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)
{
......@@ -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
// 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>.
inferredType = TypeSymbolWithAnnotations.Create(GetSpecialType(SpecialType.System_Char, diagnostics, collectionExpr.Syntax), isNullableIfReferenceType: null);
inferredType = TypeSymbolWithAnnotations.Create(GetSpecialType(SpecialType.System_Char, diagnostics, collectionExpr.Syntax));
}
else
{
......@@ -740,13 +740,12 @@ private ForEachEnumeratorInfo.Builder GetDefaultEnumeratorInfo(ForEachEnumerator
builder.ElementType = TypeSymbolWithAnnotations.Create(
((_syntax as ForEachStatementSyntax)?.Type.IsVar == true) ?
(TypeSymbol)DynamicTypeSymbol.Instance :
GetSpecialType(SpecialType.System_Object, diagnostics, _syntax),
isNullableIfReferenceType: null);
GetSpecialType(SpecialType.System_Object, diagnostics, _syntax));
}
else
{
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;
}
......
......@@ -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,
// which will cause some error to be reported. That's sufficient (i.e. no need to specifically report its absence here).
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 });
......
......@@ -2822,7 +2822,7 @@ private static NamedTypeSymbol GetInterfaceInferenceBound(ImmutableArray<NamedTy
// extension method of x, at least until we have more information.
//
// Clearly it is pointless to run multiple phases
public static ImmutableArray<TypeSymbol> InferTypeArgumentsFromFirstArgument(
public static ImmutableArray<TypeSymbolWithAnnotations> InferTypeArgumentsFromFirstArgument(
ConversionsBase conversions,
MethodSymbol method,
ImmutableArray<BoundExpression> arguments,
......@@ -2835,7 +2835,7 @@ private static NamedTypeSymbol GetInterfaceInferenceBound(ImmutableArray<NamedTy
// We need at least one formal parameter type and at least one argument.
if ((method.ParameterCount < 1) || (arguments.Length < 1))
{
return default(ImmutableArray<TypeSymbol>);
return default(ImmutableArray<TypeSymbolWithAnnotations>);
}
Debug.Assert(!method.ParameterTypes[0].IsDynamic());
......@@ -2853,7 +2853,7 @@ private static NamedTypeSymbol GetInterfaceInferenceBound(ImmutableArray<NamedTy
if (!inferrer.InferTypeArgumentsFromFirstArgument(ref useSiteDiagnostics))
{
return default(ImmutableArray<TypeSymbol>);
return default(ImmutableArray<TypeSymbolWithAnnotations>);
}
return inferrer.GetInferredTypeArguments();
......@@ -2899,14 +2899,9 @@ private bool InferTypeArgumentsFromFirstArgument(ref HashSet<DiagnosticInfo> use
/// Return the inferred type arguments using null
/// for any type arguments that were not inferred.
/// </summary>
private ImmutableArray<TypeSymbol> GetInferredTypeArguments()
private ImmutableArray<TypeSymbolWithAnnotations> GetInferredTypeArguments()
{
var builder = ArrayBuilder<TypeSymbol>.GetInstance();
foreach (var fixedResult in _fixedResults)
{
builder.Add(fixedResult.TypeSymbol);
}
return builder.ToImmutableAndFree();
return _fixedResults.AsImmutable();
}
private static bool IsReallyAType(TypeSymbol type)
......
......@@ -251,9 +251,9 @@ public override BoundNode VisitReturnStatement(BoundReturnStatement node)
{
var expression = node.ExpressionOpt;
var type = (expression is null) ?
TypeSymbolWithAnnotations.Create(NonNullTypesUnusedContext.Instance, NoReturnExpression) :
TypeSymbolWithAnnotations.Create(expression.Type?.SetUnknownNullabilityForReferenceTypes());
_builder.Add((node.RefKind, type));
NoReturnExpression :
expression.Type?.SetUnknownNullabilityForReferenceTypes();
_builder.Add((node.RefKind, TypeSymbolWithAnnotations.Create(type)));
return null;
}
}
......
......@@ -464,7 +464,7 @@ IEnumerable<Cci.TypeReferenceWithAttributes> Cci.ITypeDefinition.Interfaces(Emit
diagnostics: context.Diagnostics,
fromImplements: true);
var type = TypeSymbolWithAnnotations.Create(@interface, isNullableIfReferenceType: null);
var type = TypeSymbolWithAnnotations.Create(@interface);
yield return type.GetTypeRefWithAttributes(
moduleBeingBuilt,
declaringSymbol: this,
......
......@@ -104,7 +104,7 @@ protected override IEnumerable<Cci.TypeReferenceWithAttributes> GetInterfaces(Em
(CSharpSyntaxNode)context.SyntaxNodeOpt,
context.Diagnostics);
var type = TypeSymbolWithAnnotations.Create(@interface, isNullableIfReferenceType: null);
var type = TypeSymbolWithAnnotations.Create(@interface);
yield return type.GetTypeRefWithAttributes(
moduleBeingBuilt,
declaringSymbol: UnderlyingNamedType,
......
......@@ -24,7 +24,7 @@ private class ObjectCreationPlaceholderLocal : LocalSymbol
public ObjectCreationPlaceholderLocal(Symbol containingSymbol, BoundExpression objectCreationExpression)
{
_containingSymbol = containingSymbol;
_type = TypeSymbolWithAnnotations.Create(objectCreationExpression.Type);
_type = TypeSymbolWithAnnotations.Create(objectCreationExpression.Type, isNullableIfReferenceType: false);
ObjectCreationExpression = objectCreationExpression;
}
......
......@@ -1079,7 +1079,7 @@ private void VisitObjectOrDynamicObjectCreation(BoundExpression node, BoundExpre
VisitObjectCreationInitializer(receiver, slot, initializerOpt);
}
_resultType = TypeSymbolWithAnnotations.Create(type);
_resultType = TypeSymbolWithAnnotations.Create(type, isNullableIfReferenceType: false);
}
private void VisitObjectCreationInitializer(Symbol containingSymbol, int containingSlot, BoundExpression node)
......@@ -1227,7 +1227,7 @@ public override BoundNode VisitAnonymousObjectCreationExpression(BoundAnonymousO
// PROTOTYPE(NullableReferenceTypes): _result may need to be a new anonymous
// type since the properties may have distinct nullability from original.
// (See StaticNullChecking_FlowAnalysis.AnonymousObjectCreation_02.)
_resultType = TypeSymbolWithAnnotations.Create(node.Type);
_resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
return null;
}
......@@ -1238,7 +1238,7 @@ public override BoundNode VisitArrayCreation(BoundArrayCreation node)
VisitRvalue(expr);
}
TypeSymbol resultType = (node.InitializerOpt == null) ? node.Type : VisitArrayInitializer(node);
_resultType = TypeSymbolWithAnnotations.Create(resultType);
_resultType = TypeSymbolWithAnnotations.Create(resultType, isNullableIfReferenceType: false);
return null;
}
......@@ -1286,7 +1286,7 @@ private ArrayTypeSymbol VisitArrayInitializer(BoundArrayCreation node)
else
{
// 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
// when InferBestType fails, and avoid reporting conversion warnings for each element in those cases.
......@@ -1374,7 +1374,7 @@ private TypeSymbolWithAnnotations InferResultNullability(BinaryOperatorKind oper
if (operatorKind.IsLifted())
{
// PROTOTYPE(NullableReferenceTypes): Conversions: Lifted operator
return TypeSymbolWithAnnotations.Create(resultType, isNullableIfReferenceType: null);
return TypeSymbolWithAnnotations.Create(resultType);
}
// PROTOTYPE(NullableReferenceTypes): Update method based on operand types.
if ((object)methodOpt != null && methodOpt.ParameterCount == 2)
......@@ -2840,7 +2840,7 @@ private void VisitTupleExpression(BoundTupleExpression node)
var tupleOpt = (TupleTypeSymbol)node.Type;
_resultType = (tupleOpt is null) ?
default :
TypeSymbolWithAnnotations.Create(tupleOpt.WithElementTypes(elementTypes));
TypeSymbolWithAnnotations.Create(tupleOpt.WithElementTypes(elementTypes), isNullableIfReferenceType: false);
}
public override BoundNode VisitTupleBinaryOperator(BoundTupleBinaryOperator node)
......@@ -3153,7 +3153,7 @@ public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationE
}
base.VisitDelegateCreationExpression(node);
SetResult(node);
_resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
return null;
}
......@@ -3221,7 +3221,7 @@ public override BoundNode VisitThisReference(BoundThisReference node)
private void VisitThisOrBaseReference(BoundExpression node)
{
_resultType = TypeSymbolWithAnnotations.Create(node.Type);
_resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
}
public override BoundNode VisitParameter(BoundParameter node)
......@@ -3621,7 +3621,7 @@ public override BoundNode VisitDynamicObjectInitializerMember(BoundDynamicObject
public override BoundNode VisitBadExpression(BoundBadExpression node)
{
var result = base.VisitBadExpression(node);
_resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: null);
_resultType = TypeSymbolWithAnnotations.Create(node.Type);
return result;
}
......@@ -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;
}
......@@ -3704,7 +3704,7 @@ private TypeSymbolWithAnnotations InferResultNullability(BoundUserDefinedConditi
if (node.OperatorKind.IsLifted())
{
// 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.
if ((object)node.LogicalOperator != null && node.LogicalOperator.ParameterCount == 2)
......@@ -3808,7 +3808,7 @@ public override BoundNode VisitAwaitExpression(BoundAwaitExpression node)
public override BoundNode VisitTypeOfOperator(BoundTypeOfOperator node)
{
var result = base.VisitTypeOfOperator(node);
SetResult(node);
_resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
return result;
}
......@@ -4007,7 +4007,7 @@ public override BoundNode VisitDynamicMemberAccess(BoundDynamicMemberAccess node
CheckPossibleNullReceiver(receiver);
Debug.Assert(node.Type.IsDynamic());
_resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: null);
_resultType = TypeSymbolWithAnnotations.Create(node.Type);
return null;
}
......@@ -4085,7 +4085,7 @@ public override BoundNode VisitAnonymousPropertyDeclaration(BoundAnonymousProper
public override BoundNode VisitNoPiaObjectCreationExpression(BoundNoPiaObjectCreationExpression node)
{
var result = base.VisitNoPiaObjectCreationExpression(node);
SetResult(node);
_resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
return result;
}
......@@ -4247,7 +4247,7 @@ public override BoundNode VisitQueryClause(BoundQueryClause node)
public override BoundNode VisitNameOfOperator(BoundNameOfOperator node)
{
var result = base.VisitNameOfOperator(node);
SetResult(node);
_resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
return result;
}
......@@ -4261,7 +4261,7 @@ public override BoundNode VisitNamespaceExpression(BoundNamespaceExpression node
public override BoundNode VisitInterpolatedString(BoundInterpolatedString node)
{
var result = base.VisitInterpolatedString(node);
SetResult(node);
_resultType = TypeSymbolWithAnnotations.Create(node.Type, isNullableIfReferenceType: false);
return result;
}
......
......@@ -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)
{
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);
Debug.Assert(frame.ScopeSyntaxOpt != null);
......@@ -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
Debug.Assert((typeArgumentsOpt.IsDefault && !originalMethod.IsGenericMethod) || (typeArgumentsOpt.Length == originalMethod.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)
{
realTypeArguments = realTypeArguments.Concat(typeArgumentsOpt);
......
......@@ -112,7 +112,7 @@ private set
methodName,
args,
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,
allowUnexpandedForm: allowUnexpandedForm);
}
......
......@@ -126,7 +126,7 @@ internal TypeSymbolWithAnnotations SubstituteType(TypeSymbol previous)
}
// PROTOTYPE(NullableReferenceTypes): we're dropping annotation and context
return TypeSymbolWithAnnotations.Create(result, isNullableIfReferenceType: null);
return TypeSymbolWithAnnotations.Create(result);
}
internal TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotations previous)
......@@ -138,34 +138,11 @@ internal TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotations prev
/// 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.
/// </summary>
internal TypeSymbolWithAnnotations SubstituteTypeWithTupleUnification(TypeSymbol previous)
{
return SubstituteType(previous, withTupleUnification: true);
}
internal TypeSymbolWithAnnotations SubstituteType(TypeSymbol previous, bool withTupleUnification)
{
var result = SubstituteType(previous);
if (withTupleUnification)
{
// 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;
// Make it a tuple if it became compatible with one.
return withTupleUnification ? result.TransformToTupleIfCompatible() : result;
}
internal TypeSymbolWithAnnotations SubstituteTypeWithTupleUnification(TypeSymbolWithAnnotations previous)
......
......@@ -18,7 +18,7 @@ internal AnonymousTypeEqualsMethodSymbol(NamedTypeSymbol container)
: base(container, WellKnownMemberNames.ObjectEquals)
{
_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
......
......@@ -42,7 +42,7 @@ public override RefKind RefKind
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
......
......@@ -39,7 +39,7 @@ internal abstract partial class ErrorTypeSymbol : NamedTypeSymbol, IErrorTypeSym
/// </summary>
internal virtual TypeSymbolWithAnnotations Substitute(AbstractTypeMap typeMap)
{
return TypeSymbolWithAnnotations.Create((ErrorTypeSymbol)typeMap.SubstituteNamedType(this), isNullableIfReferenceType: null);
return TypeSymbolWithAnnotations.Create((ErrorTypeSymbol)typeMap.SubstituteNamedType(this));
}
/// <summary>
......
......@@ -106,7 +106,7 @@ private TupleTypeDecoder(ImmutableArray<string> elementNames)
// bad metadata
if (hasTupleElementNamesAttribute && elementNames.IsDefaultOrEmpty)
{
return TypeSymbolWithAnnotations.Create(new UnsupportedMetadataTypeSymbol(), isNullableIfReferenceType: null);
return TypeSymbolWithAnnotations.Create(new UnsupportedMetadataTypeSymbol());
}
TypeSymbol type = metadataType.TypeSymbol;
......
......@@ -749,6 +749,7 @@ public MethodSymbol Construct(params TypeSymbol[] typeArguments)
return this.Construct(ImmutableArray.Create(typeArguments));
}
// PROTOTYPE(NullableReferenceTypes): Replace with Construct(ImmutableArray<TypeSymbolWithAnnotations>).
/// <summary>
/// Apply type substitution to a generic method to create an method symbol with the given type parameters supplied.
/// </summary>
......
......@@ -81,7 +81,7 @@ public static MethodSymbol InferExtensionMethodTypeArguments(this MethodSymbol m
// This prevents constraint checking from failing for corresponding type parameters.
var notInferredTypeParameters = PooledHashSet<TypeParameterSymbol>.GetInstance();
var typeParams = method.TypeParameters;
var typeArgsForConstraintsCheck = typeArgs.SelectAsArray(a => TypeSymbolWithAnnotations.Create(a));
var typeArgsForConstraintsCheck = typeArgs;
for (int i = 0; i < typeArgsForConstraintsCheck.Length; i++)
{
if (typeArgsForConstraintsCheck[i].IsNull)
......@@ -140,12 +140,13 @@ public static MethodSymbol InferExtensionMethodTypeArguments(this MethodSymbol m
var typeArgsForConstruct = typeArgs;
if (firstNullInTypeArgs != -1)
{
var builder = ArrayBuilder<TypeSymbol>.GetInstance();
var builder = ArrayBuilder<TypeSymbolWithAnnotations>.GetInstance();
builder.AddRange(typeArgs, firstNullInTypeArgs);
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();
......
......@@ -93,7 +93,7 @@ protected override void MethodChecks(DiagnosticBag diagnostics)
diagnostics: diagnostics);
_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];
if (MethodKind == MethodKind.StaticConstructor && (_lazyParameters.Length != 0))
......
......@@ -49,10 +49,10 @@ protected void InitializeParameters(ImmutableArray<ParameterSymbol> parameters)
var returnType = binder.BindType(returnTypeSyntax, diagnostics);
// 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?
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))
{
......
......@@ -373,7 +373,7 @@ private TypeSymbolWithAnnotations ComputeReturnType(DiagnosticBag diagnostics)
else
{
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
public override TypeSymbolWithAnnotations Type
{
get { return TypeSymbolWithAnnotations.Create(_containingType); }
get { return TypeSymbolWithAnnotations.Create(_containingType, isNullableIfReferenceType: false); }
}
public override RefKind RefKind
......
......@@ -147,7 +147,7 @@ public override RefKind RefKind
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
......
......@@ -132,7 +132,7 @@ public override TypeSymbolWithAnnotations ReturnType
{
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
var typeArgumentsBuilder = ArrayBuilder<TypeSymbolWithAnnotations>.GetInstance(RestPosition);
var arguments = tupleCompatibleType.TypeArgumentsNoUseSiteDiagnostics;
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);
return tupleCompatibleType;
......
......@@ -16,8 +16,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// </summary>
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;
internal static ImmutableArray<TypeSymbolWithAnnotations> TypeParametersAsTypeSymbolsWithAnnotations(INonNullTypesContext nonNullTypesContext, ImmutableArray<TypeParameterSymbol> typeParameters)
......
......@@ -1500,7 +1500,7 @@ private static bool NormalizeTaskTypesInType(CSharpCompilation compilation, ref
var type = typeWithAnnotations.TypeSymbol;
if (NormalizeTaskTypesInType(compilation, ref type))
{
typeWithAnnotations = TypeSymbolWithAnnotations.Create(type, typeWithAnnotations.CustomModifiers);
typeWithAnnotations = TypeSymbolWithAnnotations.Create(type, customModifiers: typeWithAnnotations.CustomModifiers);
return true;
}
return false;
......@@ -1524,7 +1524,7 @@ private static bool NormalizeTaskTypesInNamedType(CSharpCompilation compilation,
{
hasChanged = true;
// 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)
......
......@@ -161,13 +161,6 @@ internal static TypeSymbolWithAnnotations Create(INonNullTypesContext nonNullTyp
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
// member signatures visible outside the assembly. Consider overriding, implementing, NoPIA embedding, etc.
......@@ -180,7 +173,7 @@ public static TypeSymbolWithAnnotations Create(TypeSymbol typeSymbol, ImmutableA
/// <see cref="IsNullable"/> is determined by state other than <see cref="IsAnnotated"/>
/// (in flow analysis for instance).
/// </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)
{
......@@ -465,6 +458,8 @@ public bool IsAtLeastAsVisibleAs(Symbol sym, ref HashSet<DiagnosticInfo> useSite
public TypeSymbolWithAnnotations SubstituteTypeWithTupleUnification(AbstractTypeMap typeMap) =>
_extensions.SubstituteType(this, typeMap, withTupleUnification: true);
internal TypeSymbolWithAnnotations TransformToTupleIfCompatible() => _extensions.TransformToTupleIfCompatible(this);
internal TypeSymbolWithAnnotations SubstituteTypeCore(AbstractTypeMap typeMap, bool withTupleUnification)
{
var newCustomModifiers = typeMap.SubstituteCustomModifiers(this.CustomModifiers);
......@@ -758,6 +753,7 @@ internal static Extensions CreateLazy(CSharpCompilation compilation, TypeSymbolW
internal abstract bool TypeSymbolEquals(TypeSymbolWithAnnotations type, TypeSymbolWithAnnotations other, TypeCompareKind comparison);
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);
}
......@@ -844,6 +840,17 @@ internal override TypeSymbolWithAnnotations SubstituteType(TypeSymbolWithAnnotat
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)
{
type.ReportDiagnosticsIfObsoleteCore(binder, syntax, diagnostics);
......@@ -945,7 +952,7 @@ internal override TypeSymbolWithAnnotations WithModifiers(TypeSymbolWithAnnotati
var resolvedType = GetResolvedType();
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);
......@@ -960,7 +967,7 @@ internal override TypeSymbolWithAnnotations WithTypeAndModifiers(TypeSymbolWithA
{
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);
......@@ -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)
{
if ((object)_resolved != null)
......
......@@ -21,9 +21,7 @@ public static bool CanUnify(TypeSymbol t1, TypeSymbol t2)
}
MutableTypeMap substitution = null;
bool result = CanUnifyHelper(TypeSymbolWithAnnotations.Create(t1),
TypeSymbolWithAnnotations.Create(t2),
ref substitution);
bool result = CanUnifyHelper(t1, t2, ref substitution);
#if DEBUG
if (result && ((object)t1 != null && (object)t2 != null))
{
......@@ -54,6 +52,11 @@ private static TypeSymbolWithAnnotations SubstituteAllTypeParameters(AbstractTyp
}
#endif
private static bool CanUnifyHelper(TypeSymbol t1, TypeSymbol t2, ref MutableTypeMap substitution)
{
return CanUnifyHelper(TypeSymbolWithAnnotations.Create(t1), TypeSymbolWithAnnotations.Create(t2), ref substitution);
}
/// <summary>
/// Determine whether there is any substitution of type parameters that will
/// make two types identical.
......@@ -156,7 +159,7 @@ private static bool CanUnifyHelper(TypeSymbolWithAnnotations t1, TypeSymbolWithA
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)
......@@ -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
// 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:
{
......@@ -225,8 +228,8 @@ private static bool CanUnifyHelper(TypeSymbolWithAnnotations t1, TypeSymbolWithA
t1.CustomModifiers.SequenceEqual(t2.CustomModifiers.Take(t1.CustomModifiers.Length)))
{
AddSubstitution(ref substitution, tp1,
TypeSymbolWithAnnotations.Create(t2.TypeSymbol,
ImmutableArray.Create(t2.CustomModifiers, t1.CustomModifiers.Length, t2.CustomModifiers.Length - t1.CustomModifiers.Length)));
TypeSymbolWithAnnotations.Create(t2.TypeSymbol,
customModifiers: ImmutableArray.Create(t2.CustomModifiers, t1.CustomModifiers.Length, t2.CustomModifiers.Length - t1.CustomModifiers.Length)));
return true;
}
......@@ -244,8 +247,8 @@ private static bool CanUnifyHelper(TypeSymbolWithAnnotations t1, TypeSymbolWithA
t2.CustomModifiers.SequenceEqual(t1.CustomModifiers.Take(t2.CustomModifiers.Length)))
{
AddSubstitution(ref substitution, tp2,
TypeSymbolWithAnnotations.Create(t1.TypeSymbol,
ImmutableArray.Create(t1.CustomModifiers, t2.CustomModifiers.Length, t1.CustomModifiers.Length - t2.CustomModifiers.Length)));
TypeSymbolWithAnnotations.Create(t1.TypeSymbol,
customModifiers: ImmutableArray.Create(t1.CustomModifiers, t2.CustomModifiers.Length, t1.CustomModifiers.Length - t2.CustomModifiers.Length)));
return true;
}
}
......
......@@ -5270,12 +5270,12 @@ class B : A
foreach (string memberName in new[] { "M1", "M2" })
{
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));
}
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));
}
......@@ -5387,7 +5387,7 @@ class B : IA
{
var member = ia.GetMember<MethodSymbol>(memberName);
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,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
}
......@@ -5395,7 +5395,7 @@ class B : IA
{
var member = ia.GetMember<MethodSymbol>("M3");
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,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
}
......@@ -5455,7 +5455,7 @@ class B : IA
{
var member = ia.GetMember<MethodSymbol>(memberName);
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,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
}
......@@ -5463,7 +5463,7 @@ class B : IA
{
var member = ia.GetMember<MethodSymbol>("M3");
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,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
}
......@@ -5620,12 +5620,12 @@ public override void M3<T>(T?[]? x)
foreach (string memberName in new[] { "M1", "M2" })
{
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));
}
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));
}
......@@ -5839,7 +5839,7 @@ public void M1(string?[] x)
{
var member = ia.GetMember<MethodSymbol>(memberName);
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,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
}
......@@ -5847,7 +5847,7 @@ public void M1(string?[] x)
{
var member = ia.GetMember<MethodSymbol>("M3");
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,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
}
......@@ -5902,7 +5902,7 @@ void IA.M3<T>(T?[]? x)
{
var member = ia.GetMember<MethodSymbol>(memberName);
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,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
}
......@@ -5910,7 +5910,7 @@ void IA.M3<T>(T?[]? x)
{
var member = ia.GetMember<MethodSymbol>("M3");
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,
TypeCompareKind.AllIgnoreOptions | TypeCompareKind.CompareNullableModifiersForReferenceTypes));
}
......@@ -6210,7 +6210,7 @@ partial class C1
var m1 = c1.GetMember<MethodSymbol>("M1");
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++)
{
......@@ -19614,15 +19614,11 @@ static void F(object? x)
var z = y => y ?? x.ToString();
}
}";
// PROTOTYPE(NullableReferenceTypes): Should not report HDN_ExpressionIsProbablyNeverNull for `y`.
var comp = CreateCompilation(new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition });
comp.VerifyDiagnostics(
// (5,13): error CS0815: Cannot assign lambda expression to an implicitly-typed variable
// var z = y => y ?? x.ToString();
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.
// var z = y => y ?? x.ToString();
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "x").WithLocation(5, 27));
......@@ -30947,16 +30943,11 @@ static void G()
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 });
comp.VerifyDiagnostics(
// (12,21): error CS8197: Cannot infer the type of implicitly-typed out variable 'v'.
// d.F(out var v);
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));
Diagnostic(ErrorCode.ERR_TypeInferenceFailedForImplicitlyTypedOutVariable, "v").WithArguments("v").WithLocation(12, 21));
}
[Fact]
......@@ -35093,8 +35084,6 @@ static void G()
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(
new[] { source, NonNullTypesTrue, NonNullTypesAttributesDefinition },
parseOptions: TestOptions.Regular8);
......@@ -35107,10 +35096,7 @@ static void G()
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(default(object))").WithLocation(6, 9),
// (8,9): warning CS8602: Possible dereference of a null reference.
// F(default(string)).ToString();
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));
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "F(default(string))").WithLocation(8, 9));
}
[Fact]
......@@ -149,8 +149,8 @@ struct S<T> where T : struct
var structType = comp.GlobalNamespace.GetMember<NamedTypeSymbol>("S");
var typeParamType = structType.TypeParameters.Single();
var pointerType = new PointerTypeSymbol(TypeSymbolWithAnnotations.Create(typeParamType, 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 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: customModifiers)); // This is legal, but we're already manually constructing types.
var typeMap = new TypeMap(ImmutableArray.Create(typeParamType), ImmutableArray.Create(TypeSymbolWithAnnotations.Create(intType)));
......
......@@ -90,7 +90,7 @@ private static NamedTypeSymbol DeepConstruct(NamedTypeSymbol type, ImmutableArra
Assert.True(type.IsDefinition);
var allTypeParameters = ArrayBuilder<TypeParameterSymbol>.GetInstance();
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]
......
......@@ -117,7 +117,7 @@ internal override MethodSymbol ConstructMethod(MethodSymbol method, ImmutableArr
var methodArgumentStartIndex = typeParameters.Length - methodArity;
var typeMap = new TypeMap(
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);
method = method.AsMember(substitutedType);
if (methodArity > 0)
......
......@@ -299,7 +299,7 @@ public override TypeSymbolWithAnnotations ReturnType
public override ImmutableArray<TypeSymbolWithAnnotations> TypeArguments
{
get { return _typeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations); }
get { return GetTypeParametersAsTypeArguments(); }
}
public override ImmutableArray<TypeParameterSymbol> TypeParameters
......
......@@ -122,7 +122,7 @@ public override ImmutableArray<TypeParameterSymbol> TypeParameters
internal override ImmutableArray<TypeSymbolWithAnnotations> TypeArgumentsNoUseSiteDiagnostics
{
get { return _typeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations); }
get { return GetTypeParametersAsTypeArguments(); }
}
public override NamedTypeSymbol ConstructedFrom
......
......@@ -165,7 +165,7 @@ public override ImmutableArray<CustomModifier> RefCustomModifiers
public override ImmutableArray<TypeSymbolWithAnnotations> TypeArguments
{
get { return _typeParameters.SelectAsArray(TypeMap.AsTypeSymbolWithAnnotations); }
get { return GetTypeParametersAsTypeArguments(); }
}
public override ImmutableArray<TypeParameterSymbol> TypeParameters
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册