diff --git a/src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs b/src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs index 34e249d2cccbc..c7f492be599fc 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder.ValueChecks.cs @@ -416,7 +416,7 @@ private BoundExpression CheckValue(BoundExpression expr, BindValueKind valueKind } break; - case BoundKind.UnconvertedCollectionLiteralExpression: + case BoundKind.UnconvertedCollectionExpression: if (valueKind == BindValueKind.RValue) { return expr; @@ -3959,7 +3959,7 @@ internal uint GetValEscape(BoundExpression expr, uint scopeOfTheContainingExpres var switchExpr = (BoundSwitchExpression)expr; return GetValEscape(switchExpr.SwitchArms.SelectAsArray(a => a.Value), scopeOfTheContainingExpression); - case BoundKind.CollectionLiteralExpression: + case BoundKind.CollectionExpression: return CallingMethodScope; default: @@ -4488,7 +4488,7 @@ internal bool CheckValEscape(SyntaxNode node, BoundExpression expr, uint escapeF return true; - case BoundKind.CollectionLiteralExpression: + case BoundKind.CollectionExpression: return true; default: diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs index 1bd27ff7f174e..86b10051e8e49 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Conversions.cs @@ -82,7 +82,7 @@ static bool filterConversion(Conversion conversion) return !conversion.IsInterpolatedString && !conversion.IsInterpolatedStringHandler && !conversion.IsSwitchExpression && - !conversion.IsCollectionLiteral && + !conversion.IsCollectionExpression && !(conversion.IsTupleLiteralConversion || (conversion.IsNullable && conversion.UnderlyingConversions[0].IsTupleLiteralConversion)) && (!conversion.IsUserDefined || filterConversion(conversion.UserDefinedFromConversion)); } @@ -231,11 +231,11 @@ BoundExpression createConversion( return ConvertObjectCreationExpression(syntax, (BoundUnconvertedObjectCreationExpression)source, conversion, isCast, destination, conversionGroupOpt, wasCompilerGenerated, diagnostics); } - if (source.Kind == BoundKind.UnconvertedCollectionLiteralExpression) + if (source.Kind == BoundKind.UnconvertedCollectionExpression) { - Debug.Assert(conversion.IsCollectionLiteral || !conversion.Exists); - source = ConvertCollectionLiteralExpression( - (BoundUnconvertedCollectionLiteralExpression)source, + Debug.Assert(conversion.IsCollectionExpression || !conversion.Exists); + source = ConvertCollectionExpression( + (BoundUnconvertedCollectionExpression)source, destination, wasCompilerGenerated, diagnostics); @@ -526,36 +526,36 @@ static BoundExpression bindObjectCreationExpression( } } - private BoundExpression ConvertCollectionLiteralExpression( - BoundUnconvertedCollectionLiteralExpression node, + private BoundExpression ConvertCollectionExpression( + BoundUnconvertedCollectionExpression node, TypeSymbol targetType, bool wasCompilerGenerated, BindingDiagnosticBag diagnostics) { TypeSymbol? elementType; - var collectionTypeKind = ConversionsBase.GetCollectionLiteralTypeKind(Compilation, targetType, out elementType); + var collectionTypeKind = ConversionsBase.GetCollectionExpressionTypeKind(Compilation, targetType, out elementType); switch (collectionTypeKind) { - case CollectionLiteralTypeKind.CollectionInitializer: - return BindCollectionInitializerCollectionLiteral(node, collectionTypeKind, targetType, wasCompilerGenerated: wasCompilerGenerated, diagnostics); - case CollectionLiteralTypeKind.Array: - case CollectionLiteralTypeKind.Span: - case CollectionLiteralTypeKind.ReadOnlySpan: - return BindArrayOrSpanCollectionLiteral(node, targetType, wasCompilerGenerated: wasCompilerGenerated, collectionTypeKind, elementType!, diagnostics); - case CollectionLiteralTypeKind.ListInterface: - return BindListInterfaceCollectionLiteral(node, targetType, wasCompilerGenerated: wasCompilerGenerated, elementType!, diagnostics); - case CollectionLiteralTypeKind.None: - return BindCollectionLiteralForErrorRecovery(node, targetType, diagnostics); + case CollectionExpressionTypeKind.CollectionInitializer: + return BindCollectionInitializerCollectionExpression(node, collectionTypeKind, targetType, wasCompilerGenerated: wasCompilerGenerated, diagnostics); + case CollectionExpressionTypeKind.Array: + case CollectionExpressionTypeKind.Span: + case CollectionExpressionTypeKind.ReadOnlySpan: + return BindArrayOrSpanCollectionExpression(node, targetType, wasCompilerGenerated: wasCompilerGenerated, collectionTypeKind, elementType!, diagnostics); + case CollectionExpressionTypeKind.ListInterface: + return BindListInterfaceCollectionExpression(node, targetType, wasCompilerGenerated: wasCompilerGenerated, elementType!, diagnostics); + case CollectionExpressionTypeKind.None: + return BindCollectionExpressionForErrorRecovery(node, targetType, diagnostics); default: throw ExceptionUtilities.UnexpectedValue(collectionTypeKind); } } - private BoundCollectionLiteralExpression BindArrayOrSpanCollectionLiteral( - BoundUnconvertedCollectionLiteralExpression node, + private BoundCollectionExpression BindArrayOrSpanCollectionExpression( + BoundUnconvertedCollectionExpression node, TypeSymbol targetType, bool wasCompilerGenerated, - CollectionLiteralTypeKind collectionTypeKind, + CollectionExpressionTypeKind collectionTypeKind, TypeSymbol elementType, BindingDiagnosticBag diagnostics) { @@ -563,21 +563,21 @@ private BoundCollectionLiteralExpression BindArrayOrSpanCollectionLiteral( switch (collectionTypeKind) { - case CollectionLiteralTypeKind.Span: + case CollectionExpressionTypeKind.Span: _ = GetWellKnownTypeMember(WellKnownMember.System_Span_T__ctor_Array, diagnostics, syntax: syntax); break; - case CollectionLiteralTypeKind.ReadOnlySpan: + case CollectionExpressionTypeKind.ReadOnlySpan: _ = GetWellKnownTypeMember(WellKnownMember.System_ReadOnlySpan_T__ctor_Array, diagnostics, syntax: syntax); break; } var elements = node.Elements; - if (elements.Any(e => e is BoundCollectionLiteralSpreadElement)) + if (elements.Any(e => e is BoundCollectionExpressionSpreadElement)) { // The array initializer includes at least one spread element, so we'll create an intermediate List instance. // https://github.com/dotnet/roslyn/issues/68785: Avoid intermediate List if all spread elements have Length property. _ = GetWellKnownTypeMember(WellKnownMember.System_Collections_Generic_List_T__ToArray, diagnostics, syntax: syntax); - var result = BindCollectionInitializerCollectionLiteral( + var result = BindCollectionInitializerCollectionExpression( node, collectionTypeKind, GetWellKnownType(WellKnownType.System_Collections_Generic_List_T, diagnostics, syntax).Construct(elementType), @@ -592,7 +592,7 @@ private BoundCollectionLiteralExpression BindArrayOrSpanCollectionLiteral( { builder.Add(convertArrayElement(element, elementType, diagnostics)); } - return new BoundCollectionLiteralExpression( + return new BoundCollectionExpression( syntax, collectionTypeKind, implicitReceiver, @@ -628,9 +628,9 @@ BoundExpression convertArrayElement(BoundExpression element, TypeSymbol elementT } } - private BoundCollectionLiteralExpression BindCollectionInitializerCollectionLiteral( - BoundUnconvertedCollectionLiteralExpression node, - CollectionLiteralTypeKind collectionTypeKind, + private BoundCollectionExpression BindCollectionInitializerCollectionExpression( + BoundUnconvertedCollectionExpression node, + CollectionExpressionTypeKind collectionTypeKind, TypeSymbol targetType, bool wasCompilerGenerated, BindingDiagnosticBag diagnostics, @@ -666,7 +666,7 @@ private BoundCollectionLiteralExpression BindCollectionInitializerCollectionLite var result = element switch { BoundBadExpression => element, - BoundCollectionLiteralSpreadElement spreadElement => BindCollectionInitializerSpreadElementAddMethod( + BoundCollectionExpressionSpreadElement spreadElement => BindCollectionInitializerSpreadElementAddMethod( (SpreadElementSyntax)spreadElement.Syntax, spreadElement, collectionInitializerAddMethodBinder, @@ -683,7 +683,7 @@ private BoundCollectionLiteralExpression BindCollectionInitializerCollectionLite result.WasCompilerGenerated = true; builder.Add(result); } - return new BoundCollectionLiteralExpression( + return new BoundCollectionExpression( syntax, collectionTypeKind, implicitReceiver, @@ -694,25 +694,25 @@ private BoundCollectionLiteralExpression BindCollectionInitializerCollectionLite { WasCompilerGenerated = wasCompilerGenerated }; } - private BoundCollectionLiteralExpression BindListInterfaceCollectionLiteral( - BoundUnconvertedCollectionLiteralExpression node, + private BoundCollectionExpression BindListInterfaceCollectionExpression( + BoundUnconvertedCollectionExpression node, TypeSymbol targetType, bool wasCompilerGenerated, TypeSymbol elementType, BindingDiagnosticBag diagnostics) { // https://github.com/dotnet/roslyn/issues/68785: Emit [] as Array.Empty() rather than a List. - var result = BindCollectionInitializerCollectionLiteral( + var result = BindCollectionInitializerCollectionExpression( node, - CollectionLiteralTypeKind.ListInterface, + CollectionExpressionTypeKind.ListInterface, GetWellKnownType(WellKnownType.System_Collections_Generic_List_T, diagnostics, node.Syntax).Construct(elementType), wasCompilerGenerated: wasCompilerGenerated, diagnostics); return result.Update(result.CollectionTypeKind, result.Placeholder, result.CollectionCreation, result.Elements, targetType); } - private BoundCollectionLiteralExpression BindCollectionLiteralForErrorRecovery( - BoundUnconvertedCollectionLiteralExpression node, + private BoundCollectionExpression BindCollectionExpressionForErrorRecovery( + BoundUnconvertedCollectionExpression node, TypeSymbol targetType, BindingDiagnosticBag diagnostics) { @@ -722,9 +722,9 @@ private BoundCollectionLiteralExpression BindCollectionLiteralForErrorRecovery( { builder.Add(BindToNaturalType(element, diagnostics, reportNoTargetType: !targetType.IsErrorType())); } - return new BoundCollectionLiteralExpression( + return new BoundCollectionExpression( syntax, - collectionTypeKind: CollectionLiteralTypeKind.None, + collectionTypeKind: CollectionExpressionTypeKind.None, placeholder: null, collectionCreation: null, elements: builder.ToImmutableAndFree(), diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs index cc8f364c8de0b..75d6b0f91f6e3 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs @@ -389,13 +389,13 @@ internal BoundExpression BindToNaturalType(BoundExpression expression, BindingDi result = RebindSimpleBinaryOperatorAsConverted(unconvertedBinaryOperator, diagnostics); } break; - case BoundUnconvertedCollectionLiteralExpression expr: + case BoundUnconvertedCollectionExpression expr: { if (reportNoTargetType && !expr.HasAnyErrors) { - diagnostics.Add(ErrorCode.ERR_CollectionLiteralNoTargetType, expr.Syntax.GetLocation()); + diagnostics.Add(ErrorCode.ERR_CollectionExpressionNoTargetType, expr.Syntax.GetLocation()); } - result = BindCollectionLiteralForErrorRecovery(expr, CreateErrorType(), diagnostics); + result = BindCollectionExpressionForErrorRecovery(expr, CreateErrorType(), diagnostics); } break; default: @@ -774,7 +774,7 @@ private BoundExpression BindExpressionInternal(ExpressionSyntax node, BindingDia return BadExpression(node); case SyntaxKind.CollectionExpression: - return BindCollectionLiteralExpression((CollectionExpressionSyntax)node, diagnostics); + return BindCollectionExpression((CollectionExpressionSyntax)node, diagnostics); case SyntaxKind.NullableType: // Not reachable during method body binding, but @@ -2747,11 +2747,11 @@ private void GenerateExplicitConversionErrors( GenerateImplicitConversionError(diagnostics, operand.Syntax, conversion, operand, targetType); return; } - case BoundKind.UnconvertedCollectionLiteralExpression: + case BoundKind.UnconvertedCollectionExpression: { if (operand.Type is null) { - Error(diagnostics, ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, syntax, targetType); + Error(diagnostics, ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, syntax, targetType); return; } break; @@ -4650,16 +4650,16 @@ BoundExpression bindObjectCreationExpression(ObjectCreationExpressionSyntax node } #nullable enable - private BoundExpression BindCollectionLiteralExpression(CollectionExpressionSyntax syntax, BindingDiagnosticBag diagnostics) + private BoundExpression BindCollectionExpression(CollectionExpressionSyntax syntax, BindingDiagnosticBag diagnostics) { - MessageID.IDS_FeatureCollectionLiterals.CheckFeatureAvailability(diagnostics, syntax, syntax.OpenBracketToken.GetLocation()); + MessageID.IDS_FeatureCollectionExpressions.CheckFeatureAvailability(diagnostics, syntax, syntax.OpenBracketToken.GetLocation()); var builder = ArrayBuilder.GetInstance(syntax.Elements.Count); foreach (var element in syntax.Elements) { builder.Add(bindElement(element, diagnostics)); } - return new BoundUnconvertedCollectionLiteralExpression(syntax, builder.ToImmutableAndFree(), this); + return new BoundUnconvertedCollectionExpression(syntax, builder.ToImmutableAndFree(), this); BoundExpression bindElement(CollectionElementSyntax syntax, BindingDiagnosticBag diagnostics) { @@ -4679,7 +4679,7 @@ BoundExpression bindSpreadElement(SpreadElementSyntax syntax, BindingDiagnosticB builder.IsIncomplete; if (hasErrors) { - return new BoundCollectionLiteralSpreadElement( + return new BoundCollectionExpressionSpreadElement( syntax, expression, enumeratorInfoOpt: null, @@ -4698,7 +4698,7 @@ BoundExpression bindSpreadElement(SpreadElementSyntax syntax, BindingDiagnosticB diagnostics.Add(syntax.Expression, useSiteInfo); expression = ConvertForEachCollection(expression, conversion, collectionType, diagnostics); var elementPlaceholder = new BoundValuePlaceholder(syntax.Expression, enumeratorInfo.ElementType); - return new BoundCollectionLiteralSpreadElement( + return new BoundCollectionExpressionSpreadElement( syntax, expression, enumeratorInfo, @@ -5809,9 +5809,9 @@ private BoundExpression BindCollectionInitializerElementAddMethod( } #nullable enable - private BoundCollectionLiteralSpreadElement BindCollectionInitializerSpreadElementAddMethod( + private BoundCollectionExpressionSpreadElement BindCollectionInitializerSpreadElementAddMethod( SpreadElementSyntax syntax, - BoundCollectionLiteralSpreadElement element, + BoundCollectionExpressionSpreadElement element, Binder collectionInitializerAddMethodBinder, BoundObjectOrCollectionValuePlaceholder implicitReceiver, BindingDiagnosticBag diagnostics) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs index 74c006d5c5f6b..3bb76247d1cb9 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs @@ -2362,10 +2362,10 @@ protected void GenerateImplicitConversionError( Debug.Assert(reportedError); return; } - case BoundKind.UnconvertedCollectionLiteralExpression: + case BoundKind.UnconvertedCollectionExpression: { Debug.Assert(operand.Type is null); - Error(diagnostics, ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, syntax, targetType); + Error(diagnostics, ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, syntax, targetType); return; } case BoundKind.AddressOfOperator when targetType.IsFunctionPointer(): diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/CollectionLiteralTypeKind.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/CollectionLiteralTypeKind.cs index 87e7e47a7fa25..a50bebe361cff 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/CollectionLiteralTypeKind.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/CollectionLiteralTypeKind.cs @@ -4,7 +4,7 @@ namespace Microsoft.CodeAnalysis.CSharp { - internal enum CollectionLiteralTypeKind + internal enum CollectionExpressionTypeKind { None = 0, Array, diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversion.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversion.cs index 9046015a3a0a7..7b3e97ae35e1a 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversion.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/Conversion.cs @@ -241,7 +241,7 @@ internal static Conversion GetTrivialConversion(ConversionKind kind) internal static Conversion ImplicitEnumeration => new Conversion(ConversionKind.ImplicitEnumeration); internal static Conversion ImplicitThrow => new Conversion(ConversionKind.ImplicitThrow); internal static Conversion ObjectCreation => new Conversion(ConversionKind.ObjectCreation); - internal static Conversion CollectionLiteral => new Conversion(ConversionKind.CollectionLiteral); + internal static Conversion CollectionExpression => new Conversion(ConversionKind.CollectionExpression); internal static Conversion AnonymousFunction => new Conversion(ConversionKind.AnonymousFunction); internal static Conversion Boxing => new Conversion(ConversionKind.Boxing); internal static Conversion NullLiteral => new Conversion(ConversionKind.NullLiteral); @@ -656,9 +656,9 @@ public bool IsObjectCreation } /// - /// Returns true if the conversion is an implicit collection literal expression conversion. + /// Returns true if the conversion is an implicit collection expression conversion. /// - public bool IsCollectionLiteral => Kind == ConversionKind.CollectionLiteral; + public bool IsCollectionExpression => Kind == ConversionKind.CollectionExpression; /// /// Returns true if the conversion is an implicit switch expression conversion. diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKind.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKind.cs index 47af64956263d..69ad0370f5ca2 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKind.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKind.cs @@ -63,7 +63,7 @@ internal enum ConversionKind : byte DefaultLiteral, // a conversion from a `default` literal to any type ObjectCreation, // a conversion from a `new()` expression to any type - CollectionLiteral, // a conversion from a collection literal to any type + CollectionExpression, // a conversion from a collection expression to any type InterpolatedStringHandler, // A conversion from an interpolated string literal to a type attributed with InterpolatedStringBuilderAttribute diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKindExtensions.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKindExtensions.cs index d77d417df2edc..e0d3c4578f7b6 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKindExtensions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionKindExtensions.cs @@ -52,7 +52,7 @@ public static bool IsImplicitConversion(this ConversionKind conversionKind) case ImplicitPointer: case ObjectCreation: case InlineArray: - case CollectionLiteral: + case CollectionExpression: return true; case ExplicitNumeric: diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs index 1d73f6b58d3af..10eec9d0eabc5 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/Conversions/ConversionsBase.cs @@ -657,12 +657,12 @@ private Conversion ClassifyStandardImplicitConversion(BoundExpression sourceExpr // We extend the definition of standard implicit conversions to include // all of the implicit conversions that are allowed based on an expression, // with the exception of switch expression, interpolated string builder, - // and collection literal conversions. + // and collection expression conversions. Conversion conversion = ClassifyImplicitBuiltInConversionFromExpression(sourceExpression, source, destination, ref useSiteInfo); if (conversion.Exists && !conversion.IsInterpolatedStringHandler && - !conversion.IsCollectionLiteral) + !conversion.IsCollectionExpression) { Debug.Assert(IsStandardImplicitConversionFromExpression(conversion.Kind)); return conversion; @@ -1101,10 +1101,10 @@ private Conversion ClassifyImplicitBuiltInConversionFromExpression(BoundExpressi case BoundKind.UnconvertedObjectCreationExpression: return Conversion.ObjectCreation; - case BoundKind.UnconvertedCollectionLiteralExpression: - if (GetCollectionLiteralTypeKind(Compilation, destination, out _) != CollectionLiteralTypeKind.None) + case BoundKind.UnconvertedCollectionExpression: + if (GetCollectionExpressionTypeKind(Compilation, destination, out _) != CollectionExpressionTypeKind.None) { - return Conversion.CollectionLiteral; + return Conversion.CollectionExpression; } break; } @@ -1599,7 +1599,7 @@ private static bool HasAnonymousFunctionConversion(BoundExpression source, TypeS return IsAnonymousFunctionCompatibleWithType((UnboundLambda)source, destination) == LambdaConversionResult.Success; } - internal static CollectionLiteralTypeKind GetCollectionLiteralTypeKind(CSharpCompilation compilation, TypeSymbol destination, out TypeSymbol? elementType) + internal static CollectionExpressionTypeKind GetCollectionExpressionTypeKind(CSharpCompilation compilation, TypeSymbol destination, out TypeSymbol? elementType) { Debug.Assert(compilation is { }); @@ -1608,29 +1608,29 @@ internal static CollectionLiteralTypeKind GetCollectionLiteralTypeKind(CSharpCom if (arrayType.IsSZArray) { elementType = arrayType.ElementType; - return CollectionLiteralTypeKind.Array; + return CollectionExpressionTypeKind.Array; } } else if (isSpanType(compilation, destination, WellKnownType.System_Span_T, out elementType)) { - return CollectionLiteralTypeKind.Span; + return CollectionExpressionTypeKind.Span; } else if (isSpanType(compilation, destination, WellKnownType.System_ReadOnlySpan_T, out elementType)) { - return CollectionLiteralTypeKind.ReadOnlySpan; + return CollectionExpressionTypeKind.ReadOnlySpan; } else if (implementsIEnumerable(compilation, destination)) { elementType = null; - return CollectionLiteralTypeKind.CollectionInitializer; + return CollectionExpressionTypeKind.CollectionInitializer; } else if (isListInterface(compilation, destination, out elementType)) { - return CollectionLiteralTypeKind.ListInterface; + return CollectionExpressionTypeKind.ListInterface; } elementType = null; - return CollectionLiteralTypeKind.None; + return CollectionExpressionTypeKind.None; static bool isSpanType(CSharpCompilation compilation, TypeSymbol targetType, WellKnownType spanType, [NotNullWhen(true)] out TypeSymbol? elementType) { diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs index 1009364f73991..71f5769d1486b 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/MethodTypeInference.cs @@ -611,9 +611,9 @@ private void MakeExplicitParameterTypeInferences(Binder binder, BoundExpression ExplicitParameterTypeInference(argument, target, ref useSiteInfo); ExplicitReturnTypeInference(argument, target, ref useSiteInfo); } - else if (argument.Kind == BoundKind.UnconvertedCollectionLiteralExpression) + else if (argument.Kind == BoundKind.UnconvertedCollectionExpression) { - MakeCollectionLiteralTypeInferences(binder, (BoundUnconvertedCollectionLiteralExpression)argument, target, kind, ref useSiteInfo); + MakeCollectionExpressionTypeInferences(binder, (BoundUnconvertedCollectionExpression)argument, target, kind, ref useSiteInfo); } else if (argument.Kind != BoundKind.TupleLiteral || !MakeExplicitParameterTypeInferences(binder, (BoundTupleLiteral)argument, target, kind, ref useSiteInfo)) @@ -632,9 +632,9 @@ private void MakeExplicitParameterTypeInferences(Binder binder, BoundExpression } } - private void MakeCollectionLiteralTypeInferences( + private void MakeCollectionExpressionTypeInferences( Binder binder, - BoundUnconvertedCollectionLiteralExpression argument, + BoundUnconvertedCollectionExpression argument, TypeWithAnnotations target, ExactOrBoundsKind kind, ref CompoundUseSiteInfo useSiteInfo) @@ -836,9 +836,9 @@ private void MakeOutputTypeInferences(Binder binder, BoundExpression argument, T { MakeOutputTypeInferences(binder, (BoundTupleLiteral)argument, formalType, ref useSiteInfo); } - else if (argument.Kind == BoundKind.UnconvertedCollectionLiteralExpression) + else if (argument.Kind == BoundKind.UnconvertedCollectionExpression) { - MakeOutputTypeInferences(binder, (BoundUnconvertedCollectionLiteralExpression)argument, formalType, ref useSiteInfo); + MakeOutputTypeInferences(binder, (BoundUnconvertedCollectionExpression)argument, formalType, ref useSiteInfo); } else { @@ -853,7 +853,7 @@ private void MakeOutputTypeInferences(Binder binder, BoundExpression argument, T } } - private void MakeOutputTypeInferences(Binder binder, BoundUnconvertedCollectionLiteralExpression argument, TypeWithAnnotations formalType, ref CompoundUseSiteInfo useSiteInfo) + private void MakeOutputTypeInferences(Binder binder, BoundUnconvertedCollectionExpression argument, TypeWithAnnotations formalType, ref CompoundUseSiteInfo useSiteInfo) { if (argument.Elements.Length == 0) { diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs b/src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs index 891f017763792..cb75a522bf33b 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundExpression.cs @@ -61,7 +61,7 @@ internal bool NeedsToBeConverted() case BoundKind.UnconvertedConditionalOperator: case BoundKind.DefaultLiteral: case BoundKind.UnconvertedInterpolatedString: - case BoundKind.UnconvertedCollectionLiteralExpression: + case BoundKind.UnconvertedCollectionExpression: return true; case BoundKind.StackAllocArrayCreation: // A BoundStackAllocArrayCreation is given a null type when it is in a diff --git a/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml b/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml index e7a06f099f35e..45557576804ec 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml +++ b/src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml @@ -36,7 +36,7 @@ - + @@ -1869,30 +1869,30 @@ - + - + - + - + - + - + diff --git a/src/Compilers/CSharp/Portable/BoundTree/Formatting.cs b/src/Compilers/CSharp/Portable/BoundTree/Formatting.cs index 7938cffe78b3b..a3f7e05139976 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/Formatting.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/Formatting.cs @@ -167,10 +167,10 @@ public override object Display => (Type is null) ? MessageID.IDS_FeatureTargetTypedConditional.Localize() : base.Display; } - internal partial class BoundUnconvertedCollectionLiteralExpression + internal partial class BoundUnconvertedCollectionExpression { public override object Display - => (Type is null) ? MessageID.IDS_FeatureCollectionLiterals.Localize() : base.Display; + => (Type is null) ? MessageID.IDS_FeatureCollectionExpressions.Localize() : base.Display; } internal partial class BoundPassByCopy diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index bfb19b064a5fa..1b98bedfaf01c 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6789,17 +6789,17 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ variance safety for static interface members - - collection literals + + collection expressions - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. - - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. - - There is no target type for the collection literal. + + There is no target type for the collection expression. Record equality contract property '{0}' must have a get accessor. diff --git a/src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs b/src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs index b96a220765602..2135a242b024a 100644 --- a/src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs +++ b/src/Compilers/CSharp/Portable/Compilation/CSharpSemanticModel.cs @@ -2183,10 +2183,10 @@ internal CSharpTypeInfo GetTypeInfoForNode( conversion = Conversion.Identity; } } - else if (boundExpr is BoundCollectionLiteralExpression convertedCollection) + else if (boundExpr is BoundCollectionExpression convertedCollection) { type = null; - if (highestBoundExpr is BoundConversion { ConversionKind: ConversionKind.CollectionLiteral or ConversionKind.NoConversion, Conversion: var convertedCollectionConversion }) + if (highestBoundExpr is BoundConversion { ConversionKind: ConversionKind.CollectionExpression or ConversionKind.NoConversion, Conversion: var convertedCollectionConversion }) { convertedType = highestBoundExpr.Type; convertedNullability = convertedCollection.TopLevelNullability; @@ -2196,9 +2196,9 @@ internal CSharpTypeInfo GetTypeInfoForNode( { // There was an explicit cast on top of this. (convertedType, convertedNullability) = (convertedCollection.Type, nullability); - conversion = convertedCollection.CollectionTypeKind == CollectionLiteralTypeKind.None + conversion = convertedCollection.CollectionTypeKind == CollectionExpressionTypeKind.None ? Conversion.NoConversion - : Conversion.CollectionLiteral; + : Conversion.CollectionExpression; } } else if (highestBoundExpr != null && highestBoundExpr != boundExpr && highestBoundExpr.HasExpressionType()) diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 54b6c3999a3c1..308f8bd22b5da 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -2233,9 +2233,9 @@ internal enum ErrorCode ERR_InlineArrayBadIndex = 9172, ERR_NamedArgumentForInlineArray = 9173, - ERR_CollectionLiteralTargetTypeNotConstructible = 9174, - ERR_ExpressionTreeContainsCollectionLiteral = 9175, - ERR_CollectionLiteralNoTargetType = 9176, + ERR_CollectionExpressionTargetTypeNotConstructible = 9174, + ERR_ExpressionTreeContainsCollectionExpression = 9175, + ERR_CollectionExpressionNoTargetType = 9176, ERR_InterceptorArityNotCompatible = 9177, ERR_InterceptorCannotBeGeneric = 9178, diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs index 3e1f560edf292..42157b77b81a6 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs @@ -2361,9 +2361,9 @@ internal static bool IsBuildOnlyDiagnostic(ErrorCode code) case ErrorCode.ERR_RuntimeDoesNotSupportInlineArrayTypes: case ErrorCode.ERR_InlineArrayBadIndex: case ErrorCode.ERR_NamedArgumentForInlineArray: - case ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible: - case ErrorCode.ERR_ExpressionTreeContainsCollectionLiteral: - case ErrorCode.ERR_CollectionLiteralNoTargetType: + case ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible: + case ErrorCode.ERR_ExpressionTreeContainsCollectionExpression: + case ErrorCode.ERR_CollectionExpressionNoTargetType: case ErrorCode.WRN_PrimaryConstructorParameterIsShadowedAndNotPassedToBase: case ErrorCode.ERR_InlineArrayUnsupportedElementFieldModifier: case ErrorCode.WRN_InlineArrayIndexerNotUsed: diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs index bb0db09864944..01353d107fcc4 100644 --- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs +++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs @@ -274,7 +274,7 @@ internal enum MessageID IDS_FeatureInstanceMemberInNameof = MessageBase + 12835, IDS_FeatureInlineArrays = MessageBase + 12836, - IDS_FeatureCollectionLiterals = MessageBase + 12837, + IDS_FeatureCollectionExpressions = MessageBase + 12837, } // Message IDs may refer to strings that need to be localized. @@ -461,7 +461,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature) case MessageID.IDS_FeatureUsingTypeAlias: // semantic check case MessageID.IDS_FeatureInstanceMemberInNameof: // semantic check case MessageID.IDS_FeatureInlineArrays: // semantic check - case MessageID.IDS_FeatureCollectionLiterals: // semantic check + case MessageID.IDS_FeatureCollectionExpressions: // semantic check return LanguageVersion.Preview; // C# 11.0 features. diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs index 6024414d9514b..f6ad3e6b993ba 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/AbstractFlowPass.cs @@ -1969,19 +1969,19 @@ public override BoundNode VisitObjectCreationExpression(BoundObjectCreationExpre return null; } - public override BoundNode VisitCollectionLiteralExpression(BoundCollectionLiteralExpression node) + public override BoundNode VisitCollectionExpression(BoundCollectionExpression node) { - VisitCollectionLiteralExpression(node.Elements); + VisitCollectionExpression(node.Elements); return null; } - public override BoundNode VisitUnconvertedCollectionLiteralExpression(BoundUnconvertedCollectionLiteralExpression node) + public override BoundNode VisitUnconvertedCollectionExpression(BoundUnconvertedCollectionExpression node) { - VisitCollectionLiteralExpression(node.Elements); + VisitCollectionExpression(node.Elements); return null; } - private void VisitCollectionLiteralExpression(ImmutableArray elements) + private void VisitCollectionExpression(ImmutableArray elements) { foreach (var element in elements) { @@ -1989,7 +1989,7 @@ private void VisitCollectionLiteralExpression(ImmutableArray el } } - public override BoundNode VisitCollectionLiteralSpreadElement(BoundCollectionLiteralSpreadElement node) + public override BoundNode VisitCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement node) { VisitRvalue(node.Expression); return null; diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index 13ca8d9ef39bf..db06fb4f934c4 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -3471,12 +3471,12 @@ protected override void VisitStatement(BoundStatement statement) return null; } - public override BoundNode? VisitCollectionLiteralExpression(BoundCollectionLiteralExpression node) + public override BoundNode? VisitCollectionExpression(BoundCollectionExpression node) { // https://github.com/dotnet/roslyn/issues/68786: Use inferInitialObjectState() to set the initial // state of the instance: see the call to InheritNullableStateOfTrackableStruct() in particular. int containerSlot = GetOrCreatePlaceholderSlot(node); - bool delayCompletionForType = false; // https://github.com/dotnet/roslyn/issues/68786: Should be true if the collection literal is target typed. + bool delayCompletionForType = false; // https://github.com/dotnet/roslyn/issues/68786: Should be true if the collection expression is target typed. // https://github.com/dotnet/roslyn/issues/68786: Set nullability of elements from the inferred target type nullability. foreach (var element in node.Elements) @@ -3502,7 +3502,7 @@ protected override void VisitStatement(BoundStatement statement) return null; } - public override BoundNode? VisitUnconvertedCollectionLiteralExpression(BoundUnconvertedCollectionLiteralExpression node) + public override BoundNode? VisitUnconvertedCollectionExpression(BoundUnconvertedCollectionExpression node) { foreach (var element in node.Elements) { @@ -7251,7 +7251,7 @@ private static NullableAnnotation GetNullableAnnotation(BoundExpression expr) case BoundKind.UnboundLambda: case BoundKind.UnconvertedObjectCreationExpression: case BoundKind.ConvertedTupleLiteral: - case BoundKind.UnconvertedCollectionLiteralExpression: + case BoundKind.UnconvertedCollectionExpression: return NullableAnnotation.NotAnnotated; default: Debug.Assert(false); // unexpected value @@ -8207,7 +8207,7 @@ private TypeWithState VisitConversion( break; case ConversionKind.ObjectCreation: - case ConversionKind.CollectionLiteral: + case ConversionKind.CollectionExpression: case ConversionKind.SwitchExpression: case ConversionKind.ConditionalExpression: resultState = getConversionResultState(operandType); diff --git a/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs b/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs index c14e46d72bbba..07092aab9961b 100644 --- a/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/BoundNodes.xml.Generated.cs @@ -184,9 +184,9 @@ internal enum BoundKind : byte Attribute, UnconvertedObjectCreationExpression, ObjectCreationExpression, - UnconvertedCollectionLiteralExpression, - CollectionLiteralExpression, - CollectionLiteralSpreadElement, + UnconvertedCollectionExpression, + CollectionExpression, + CollectionExpressionSpreadElement, TupleLiteral, ConvertedTupleLiteral, DynamicObjectCreationExpression, @@ -6280,10 +6280,10 @@ public BoundObjectCreationExpression Update(MethodSymbol constructor, ImmutableA } } - internal sealed partial class BoundUnconvertedCollectionLiteralExpression : BoundExpression + internal sealed partial class BoundUnconvertedCollectionExpression : BoundExpression { - public BoundUnconvertedCollectionLiteralExpression(SyntaxNode syntax, ImmutableArray elements, Binder binder, bool hasErrors = false) - : base(BoundKind.UnconvertedCollectionLiteralExpression, syntax, null, hasErrors || elements.HasErrors()) + public BoundUnconvertedCollectionExpression(SyntaxNode syntax, ImmutableArray elements, Binder binder, bool hasErrors = false) + : base(BoundKind.UnconvertedCollectionExpression, syntax, null, hasErrors || elements.HasErrors()) { RoslynDebug.Assert(!elements.IsDefault, "Field 'elements' cannot be null (use Null=\"allow\" in BoundNodes.xml to remove this check)"); @@ -6298,13 +6298,13 @@ public BoundUnconvertedCollectionLiteralExpression(SyntaxNode syntax, ImmutableA public Binder Binder { get; } [DebuggerStepThrough] - public override BoundNode? Accept(BoundTreeVisitor visitor) => visitor.VisitUnconvertedCollectionLiteralExpression(this); + public override BoundNode? Accept(BoundTreeVisitor visitor) => visitor.VisitUnconvertedCollectionExpression(this); - public BoundUnconvertedCollectionLiteralExpression Update(ImmutableArray elements, Binder binder) + public BoundUnconvertedCollectionExpression Update(ImmutableArray elements, Binder binder) { if (elements != this.Elements || binder != this.Binder) { - var result = new BoundUnconvertedCollectionLiteralExpression(this.Syntax, elements, binder, this.HasErrors); + var result = new BoundUnconvertedCollectionExpression(this.Syntax, elements, binder, this.HasErrors); result.CopyAttributes(this); return result; } @@ -6312,10 +6312,10 @@ public BoundUnconvertedCollectionLiteralExpression Update(ImmutableArray elements, TypeSymbol type, bool hasErrors = false) - : base(BoundKind.CollectionLiteralExpression, syntax, type, hasErrors || placeholder.HasErrors() || collectionCreation.HasErrors() || elements.HasErrors()) + public BoundCollectionExpression(SyntaxNode syntax, CollectionExpressionTypeKind collectionTypeKind, BoundObjectOrCollectionValuePlaceholder? placeholder, BoundExpression? collectionCreation, ImmutableArray elements, TypeSymbol type, bool hasErrors = false) + : base(BoundKind.CollectionExpression, syntax, type, hasErrors || placeholder.HasErrors() || collectionCreation.HasErrors() || elements.HasErrors()) { RoslynDebug.Assert(!elements.IsDefault, "Field 'elements' cannot be null (use Null=\"allow\" in BoundNodes.xml to remove this check)"); @@ -6328,19 +6328,19 @@ public BoundCollectionLiteralExpression(SyntaxNode syntax, CollectionLiteralType } public new TypeSymbol Type => base.Type!; - public CollectionLiteralTypeKind CollectionTypeKind { get; } + public CollectionExpressionTypeKind CollectionTypeKind { get; } public BoundObjectOrCollectionValuePlaceholder? Placeholder { get; } public BoundExpression? CollectionCreation { get; } public ImmutableArray Elements { get; } [DebuggerStepThrough] - public override BoundNode? Accept(BoundTreeVisitor visitor) => visitor.VisitCollectionLiteralExpression(this); + public override BoundNode? Accept(BoundTreeVisitor visitor) => visitor.VisitCollectionExpression(this); - public BoundCollectionLiteralExpression Update(CollectionLiteralTypeKind collectionTypeKind, BoundObjectOrCollectionValuePlaceholder? placeholder, BoundExpression? collectionCreation, ImmutableArray elements, TypeSymbol type) + public BoundCollectionExpression Update(CollectionExpressionTypeKind collectionTypeKind, BoundObjectOrCollectionValuePlaceholder? placeholder, BoundExpression? collectionCreation, ImmutableArray elements, TypeSymbol type) { if (collectionTypeKind != this.CollectionTypeKind || placeholder != this.Placeholder || collectionCreation != this.CollectionCreation || elements != this.Elements || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything)) { - var result = new BoundCollectionLiteralExpression(this.Syntax, collectionTypeKind, placeholder, collectionCreation, elements, type, this.HasErrors); + var result = new BoundCollectionExpression(this.Syntax, collectionTypeKind, placeholder, collectionCreation, elements, type, this.HasErrors); result.CopyAttributes(this); return result; } @@ -6348,10 +6348,10 @@ public BoundCollectionLiteralExpression Update(CollectionLiteralTypeKind collect } } - internal sealed partial class BoundCollectionLiteralSpreadElement : BoundExpression + internal sealed partial class BoundCollectionExpressionSpreadElement : BoundExpression { - public BoundCollectionLiteralSpreadElement(SyntaxNode syntax, BoundExpression expression, ForEachEnumeratorInfo? enumeratorInfoOpt, BoundValuePlaceholder? elementPlaceholder, BoundValuePlaceholder? addElementPlaceholder, BoundStatement? addMethodInvocation, TypeSymbol type, bool hasErrors = false) - : base(BoundKind.CollectionLiteralSpreadElement, syntax, type, hasErrors || expression.HasErrors() || elementPlaceholder.HasErrors() || addElementPlaceholder.HasErrors() || addMethodInvocation.HasErrors()) + public BoundCollectionExpressionSpreadElement(SyntaxNode syntax, BoundExpression expression, ForEachEnumeratorInfo? enumeratorInfoOpt, BoundValuePlaceholder? elementPlaceholder, BoundValuePlaceholder? addElementPlaceholder, BoundStatement? addMethodInvocation, TypeSymbol type, bool hasErrors = false) + : base(BoundKind.CollectionExpressionSpreadElement, syntax, type, hasErrors || expression.HasErrors() || elementPlaceholder.HasErrors() || addElementPlaceholder.HasErrors() || addMethodInvocation.HasErrors()) { RoslynDebug.Assert(expression is object, "Field 'expression' cannot be null (make the type nullable in BoundNodes.xml to remove this check)"); @@ -6372,13 +6372,13 @@ public BoundCollectionLiteralSpreadElement(SyntaxNode syntax, BoundExpression ex public BoundStatement? AddMethodInvocation { get; } [DebuggerStepThrough] - public override BoundNode? Accept(BoundTreeVisitor visitor) => visitor.VisitCollectionLiteralSpreadElement(this); + public override BoundNode? Accept(BoundTreeVisitor visitor) => visitor.VisitCollectionExpressionSpreadElement(this); - public BoundCollectionLiteralSpreadElement Update(BoundExpression expression, ForEachEnumeratorInfo? enumeratorInfoOpt, BoundValuePlaceholder? elementPlaceholder, BoundValuePlaceholder? addElementPlaceholder, BoundStatement? addMethodInvocation, TypeSymbol type) + public BoundCollectionExpressionSpreadElement Update(BoundExpression expression, ForEachEnumeratorInfo? enumeratorInfoOpt, BoundValuePlaceholder? elementPlaceholder, BoundValuePlaceholder? addElementPlaceholder, BoundStatement? addMethodInvocation, TypeSymbol type) { if (expression != this.Expression || enumeratorInfoOpt != this.EnumeratorInfoOpt || elementPlaceholder != this.ElementPlaceholder || addElementPlaceholder != this.AddElementPlaceholder || addMethodInvocation != this.AddMethodInvocation || !TypeSymbol.Equals(type, this.Type, TypeCompareKind.ConsiderEverything)) { - var result = new BoundCollectionLiteralSpreadElement(this.Syntax, expression, enumeratorInfoOpt, elementPlaceholder, addElementPlaceholder, addMethodInvocation, type, this.HasErrors); + var result = new BoundCollectionExpressionSpreadElement(this.Syntax, expression, enumeratorInfoOpt, elementPlaceholder, addElementPlaceholder, addMethodInvocation, type, this.HasErrors); result.CopyAttributes(this); return result; } @@ -8992,12 +8992,12 @@ internal R VisitInternal(BoundNode node, A arg) return VisitUnconvertedObjectCreationExpression((BoundUnconvertedObjectCreationExpression)node, arg); case BoundKind.ObjectCreationExpression: return VisitObjectCreationExpression((BoundObjectCreationExpression)node, arg); - case BoundKind.UnconvertedCollectionLiteralExpression: - return VisitUnconvertedCollectionLiteralExpression((BoundUnconvertedCollectionLiteralExpression)node, arg); - case BoundKind.CollectionLiteralExpression: - return VisitCollectionLiteralExpression((BoundCollectionLiteralExpression)node, arg); - case BoundKind.CollectionLiteralSpreadElement: - return VisitCollectionLiteralSpreadElement((BoundCollectionLiteralSpreadElement)node, arg); + case BoundKind.UnconvertedCollectionExpression: + return VisitUnconvertedCollectionExpression((BoundUnconvertedCollectionExpression)node, arg); + case BoundKind.CollectionExpression: + return VisitCollectionExpression((BoundCollectionExpression)node, arg); + case BoundKind.CollectionExpressionSpreadElement: + return VisitCollectionExpressionSpreadElement((BoundCollectionExpressionSpreadElement)node, arg); case BoundKind.TupleLiteral: return VisitTupleLiteral((BoundTupleLiteral)node, arg); case BoundKind.ConvertedTupleLiteral: @@ -9292,9 +9292,9 @@ internal abstract partial class BoundTreeVisitor public virtual R VisitAttribute(BoundAttribute node, A arg) => this.DefaultVisit(node, arg); public virtual R VisitUnconvertedObjectCreationExpression(BoundUnconvertedObjectCreationExpression node, A arg) => this.DefaultVisit(node, arg); public virtual R VisitObjectCreationExpression(BoundObjectCreationExpression node, A arg) => this.DefaultVisit(node, arg); - public virtual R VisitUnconvertedCollectionLiteralExpression(BoundUnconvertedCollectionLiteralExpression node, A arg) => this.DefaultVisit(node, arg); - public virtual R VisitCollectionLiteralExpression(BoundCollectionLiteralExpression node, A arg) => this.DefaultVisit(node, arg); - public virtual R VisitCollectionLiteralSpreadElement(BoundCollectionLiteralSpreadElement node, A arg) => this.DefaultVisit(node, arg); + public virtual R VisitUnconvertedCollectionExpression(BoundUnconvertedCollectionExpression node, A arg) => this.DefaultVisit(node, arg); + public virtual R VisitCollectionExpression(BoundCollectionExpression node, A arg) => this.DefaultVisit(node, arg); + public virtual R VisitCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement node, A arg) => this.DefaultVisit(node, arg); public virtual R VisitTupleLiteral(BoundTupleLiteral node, A arg) => this.DefaultVisit(node, arg); public virtual R VisitConvertedTupleLiteral(BoundConvertedTupleLiteral node, A arg) => this.DefaultVisit(node, arg); public virtual R VisitDynamicObjectCreationExpression(BoundDynamicObjectCreationExpression node, A arg) => this.DefaultVisit(node, arg); @@ -9524,9 +9524,9 @@ internal abstract partial class BoundTreeVisitor public virtual BoundNode? VisitAttribute(BoundAttribute node) => this.DefaultVisit(node); public virtual BoundNode? VisitUnconvertedObjectCreationExpression(BoundUnconvertedObjectCreationExpression node) => this.DefaultVisit(node); public virtual BoundNode? VisitObjectCreationExpression(BoundObjectCreationExpression node) => this.DefaultVisit(node); - public virtual BoundNode? VisitUnconvertedCollectionLiteralExpression(BoundUnconvertedCollectionLiteralExpression node) => this.DefaultVisit(node); - public virtual BoundNode? VisitCollectionLiteralExpression(BoundCollectionLiteralExpression node) => this.DefaultVisit(node); - public virtual BoundNode? VisitCollectionLiteralSpreadElement(BoundCollectionLiteralSpreadElement node) => this.DefaultVisit(node); + public virtual BoundNode? VisitUnconvertedCollectionExpression(BoundUnconvertedCollectionExpression node) => this.DefaultVisit(node); + public virtual BoundNode? VisitCollectionExpression(BoundCollectionExpression node) => this.DefaultVisit(node); + public virtual BoundNode? VisitCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement node) => this.DefaultVisit(node); public virtual BoundNode? VisitTupleLiteral(BoundTupleLiteral node) => this.DefaultVisit(node); public virtual BoundNode? VisitConvertedTupleLiteral(BoundConvertedTupleLiteral node) => this.DefaultVisit(node); public virtual BoundNode? VisitDynamicObjectCreationExpression(BoundDynamicObjectCreationExpression node) => this.DefaultVisit(node); @@ -10296,17 +10296,17 @@ internal abstract partial class BoundTreeWalker : BoundTreeVisitor this.Visit(node.InitializerExpressionOpt); return null; } - public override BoundNode? VisitUnconvertedCollectionLiteralExpression(BoundUnconvertedCollectionLiteralExpression node) + public override BoundNode? VisitUnconvertedCollectionExpression(BoundUnconvertedCollectionExpression node) { this.VisitList(node.Elements); return null; } - public override BoundNode? VisitCollectionLiteralExpression(BoundCollectionLiteralExpression node) + public override BoundNode? VisitCollectionExpression(BoundCollectionExpression node) { this.VisitList(node.Elements); return null; } - public override BoundNode? VisitCollectionLiteralSpreadElement(BoundCollectionLiteralSpreadElement node) + public override BoundNode? VisitCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement node) { this.Visit(node.Expression); return null; @@ -11563,13 +11563,13 @@ internal abstract partial class BoundTreeRewriter : BoundTreeVisitor TypeSymbol? type = this.VisitType(node.Type); return node.Update(node.Constructor, node.ConstructorsGroup, arguments, node.ArgumentNamesOpt, node.ArgumentRefKindsOpt, node.Expanded, node.ArgsToParamsOpt, node.DefaultArguments, node.ConstantValueOpt, initializerExpressionOpt, node.WasTargetTyped, type); } - public override BoundNode? VisitUnconvertedCollectionLiteralExpression(BoundUnconvertedCollectionLiteralExpression node) + public override BoundNode? VisitUnconvertedCollectionExpression(BoundUnconvertedCollectionExpression node) { ImmutableArray elements = this.VisitList(node.Elements); TypeSymbol? type = this.VisitType(node.Type); return node.Update(elements, node.Binder); } - public override BoundNode? VisitCollectionLiteralExpression(BoundCollectionLiteralExpression node) + public override BoundNode? VisitCollectionExpression(BoundCollectionExpression node) { BoundObjectOrCollectionValuePlaceholder? placeholder = node.Placeholder; BoundExpression? collectionCreation = node.CollectionCreation; @@ -11577,7 +11577,7 @@ internal abstract partial class BoundTreeRewriter : BoundTreeVisitor TypeSymbol? type = this.VisitType(node.Type); return node.Update(node.CollectionTypeKind, placeholder, collectionCreation, elements, type); } - public override BoundNode? VisitCollectionLiteralSpreadElement(BoundCollectionLiteralSpreadElement node) + public override BoundNode? VisitCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement node) { BoundExpression expression = (BoundExpression)this.Visit(node.Expression); BoundValuePlaceholder? elementPlaceholder = node.ElementPlaceholder; @@ -13773,10 +13773,10 @@ public NullabilityRewriter(ImmutableDictionary elements = this.VisitList(node.Elements); - BoundUnconvertedCollectionLiteralExpression updatedNode; + BoundUnconvertedCollectionExpression updatedNode; if (_updatedNullabilities.TryGetValue(node, out (NullabilityInfo Info, TypeSymbol? Type) infoAndType)) { @@ -13790,12 +13790,12 @@ public NullabilityRewriter(ImmutableDictionary elements = this.VisitList(node.Elements); - BoundCollectionLiteralExpression updatedNode; + BoundCollectionExpression updatedNode; if (_updatedNullabilities.TryGetValue(node, out (NullabilityInfo Info, TypeSymbol? Type) infoAndType)) { @@ -13809,13 +13809,13 @@ public NullabilityRewriter(ImmutableDictionary new TreeDumperNode("unconvertedCollectionLiteralExpression", null, new TreeDumperNode[] + public override TreeDumperNode VisitUnconvertedCollectionExpression(BoundUnconvertedCollectionExpression node, object? arg) => new TreeDumperNode("unconvertedCollectionExpression", null, new TreeDumperNode[] { new TreeDumperNode("elements", null, from x in node.Elements select Visit(x, null)), new TreeDumperNode("binder", node.Binder, null), @@ -16199,7 +16199,7 @@ private BoundTreeDumperNodeProducer() new TreeDumperNode("hasErrors", node.HasErrors, null) } ); - public override TreeDumperNode VisitCollectionLiteralExpression(BoundCollectionLiteralExpression node, object? arg) => new TreeDumperNode("collectionLiteralExpression", null, new TreeDumperNode[] + public override TreeDumperNode VisitCollectionExpression(BoundCollectionExpression node, object? arg) => new TreeDumperNode("collectionExpression", null, new TreeDumperNode[] { new TreeDumperNode("collectionTypeKind", node.CollectionTypeKind, null), new TreeDumperNode("placeholder", null, new TreeDumperNode[] { Visit(node.Placeholder, null) }), @@ -16210,7 +16210,7 @@ private BoundTreeDumperNodeProducer() new TreeDumperNode("hasErrors", node.HasErrors, null) } ); - public override TreeDumperNode VisitCollectionLiteralSpreadElement(BoundCollectionLiteralSpreadElement node, object? arg) => new TreeDumperNode("collectionLiteralSpreadElement", null, new TreeDumperNode[] + public override TreeDumperNode VisitCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement node, object? arg) => new TreeDumperNode("collectionExpressionSpreadElement", null, new TreeDumperNode[] { new TreeDumperNode("expression", null, new TreeDumperNode[] { Visit(node.Expression, null) }), new TreeDumperNode("enumeratorInfoOpt", node.EnumeratorInfoOpt, null), diff --git a/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs b/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs index 2c79218eac088..4f189d184026c 100644 --- a/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs +++ b/src/Compilers/CSharp/Portable/Lowering/DiagnosticsPass_ExpressionTrees.cs @@ -1032,14 +1032,14 @@ public override BoundNode VisitFunctionPointerInvocation(BoundFunctionPointerInv return base.VisitFunctionPointerInvocation(node); } - public override BoundNode VisitCollectionLiteralExpression(BoundCollectionLiteralExpression node) + public override BoundNode VisitCollectionExpression(BoundCollectionExpression node) { if (_inExpressionLambda) { - Error(ErrorCode.ERR_ExpressionTreeContainsCollectionLiteral, node); + Error(ErrorCode.ERR_ExpressionTreeContainsCollectionExpression, node); } - return base.VisitCollectionLiteralExpression(node); + return base.VisitCollectionExpression(node); } } } diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionLiteral.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionLiteral.cs index 073f4b60b73d9..9afe50d83838f 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionLiteral.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionLiteral.cs @@ -13,29 +13,29 @@ namespace Microsoft.CodeAnalysis.CSharp { internal sealed partial class LocalRewriter { - public override BoundNode? VisitCollectionLiteralExpression(BoundCollectionLiteralExpression node) + public override BoundNode? VisitCollectionExpression(BoundCollectionExpression node) { Debug.Assert(!_inExpressionLambda); Debug.Assert(node.Type is { }); - var collectionTypeKind = ConversionsBase.GetCollectionLiteralTypeKind(_compilation, node.Type, out var elementType); + var collectionTypeKind = ConversionsBase.GetCollectionExpressionTypeKind(_compilation, node.Type, out var elementType); switch (collectionTypeKind) { - case CollectionLiteralTypeKind.CollectionInitializer: - return VisitCollectionInitializerCollectionLiteralExpression(node); - case CollectionLiteralTypeKind.Array: - case CollectionLiteralTypeKind.Span: - case CollectionLiteralTypeKind.ReadOnlySpan: + case CollectionExpressionTypeKind.CollectionInitializer: + return VisitCollectionInitializerCollectionExpression(node); + case CollectionExpressionTypeKind.Array: + case CollectionExpressionTypeKind.Span: + case CollectionExpressionTypeKind.ReadOnlySpan: Debug.Assert(elementType is { }); - return VisitArrayOrSpanCollectionLiteralExpression(node, elementType); - case CollectionLiteralTypeKind.ListInterface: - return VisitListInterfaceCollectionLiteralExpression(node); + return VisitArrayOrSpanCollectionExpression(node, elementType); + case CollectionExpressionTypeKind.ListInterface: + return VisitListInterfaceCollectionExpression(node); default: throw ExceptionUtilities.UnexpectedValue(collectionTypeKind); } } - private BoundExpression VisitArrayOrSpanCollectionLiteralExpression(BoundCollectionLiteralExpression node, TypeSymbol elementType) + private BoundExpression VisitArrayOrSpanCollectionExpression(BoundCollectionExpression node, TypeSymbol elementType) { Debug.Assert(!_inExpressionLambda); Debug.Assert(node.Type is { }); @@ -58,14 +58,14 @@ private BoundExpression VisitArrayOrSpanCollectionLiteralExpression(BoundCollect var elements = node.Elements; BoundExpression array; - if (elements.Any(i => i is BoundCollectionLiteralSpreadElement)) + if (elements.Any(i => i is BoundCollectionExpressionSpreadElement)) { // The array initializer includes at least one spread element, so we'll create an intermediate List instance. // https://github.com/dotnet/roslyn/issues/68785: Avoid intermediate List if all spread elements have Length property. // https://github.com/dotnet/roslyn/issues/68785: Emit Enumerable.TryGetNonEnumeratedCount() and avoid intermediate List at runtime. var listType = _compilation.GetWellKnownType(WellKnownType.System_Collections_Generic_List_T).Construct(elementType); var listToArray = ((MethodSymbol)_compilation.GetWellKnownTypeMember(WellKnownMember.System_Collections_Generic_List_T__ToArray)!).AsMember(listType); - var list = VisitCollectionInitializerCollectionLiteralExpression(node); + var list = VisitCollectionInitializerCollectionExpression(node); array = _factory.Call(list, listToArray); } else @@ -99,7 +99,7 @@ private BoundExpression VisitArrayOrSpanCollectionLiteralExpression(BoundCollect return new BoundObjectCreationExpression(syntax, spanConstructor, array); } - private BoundExpression VisitCollectionInitializerCollectionLiteralExpression(BoundCollectionLiteralExpression node) + private BoundExpression VisitCollectionInitializerCollectionExpression(BoundCollectionExpression node) { Debug.Assert(!_inExpressionLambda); Debug.Assert(node.Type is { }); @@ -125,7 +125,7 @@ private BoundExpression VisitCollectionInitializerCollectionLiteralExpression(Bo { BoundCollectionElementInitializer collectionInitializer => MakeCollectionInitializer(temp, collectionInitializer), BoundDynamicCollectionElementInitializer dynamicInitializer => MakeDynamicCollectionInitializer(temp, dynamicInitializer), - BoundCollectionLiteralSpreadElement spreadElement => MakeCollectionLiteralSpreadElement(spreadElement), + BoundCollectionExpressionSpreadElement spreadElement => MakeCollectionExpressionSpreadElement(spreadElement), _ => throw ExceptionUtilities.UnexpectedValue(element) }; if (rewrittenElement != null) @@ -144,17 +144,17 @@ private BoundExpression VisitCollectionInitializerCollectionLiteralExpression(Bo node.Type); } - private BoundExpression VisitListInterfaceCollectionLiteralExpression(BoundCollectionLiteralExpression node) + private BoundExpression VisitListInterfaceCollectionExpression(BoundCollectionExpression node) { Debug.Assert(!_inExpressionLambda); Debug.Assert(node.Type is { }); // https://github.com/dotnet/roslyn/issues/68785: Emit [] as Array.Empty() rather than a List. - var list = VisitCollectionInitializerCollectionLiteralExpression(node); + var list = VisitCollectionInitializerCollectionExpression(node); return _factory.Convert(node.Type, list); } - private BoundExpression MakeCollectionLiteralSpreadElement(BoundCollectionLiteralSpreadElement initializer) + private BoundExpression MakeCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement initializer) { var enumeratorInfo = initializer.EnumeratorInfoOpt; var addElementPlaceholder = initializer.AddElementPlaceholder; diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs index e6fe91ea178c2..c74cd4f9f5e8a 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_Conversion.cs @@ -58,8 +58,8 @@ public override BoundNode VisitConversion(BoundConversion node) return objectCreation; - case ConversionKind.CollectionLiteral: - // Skip through target-typed collection literals + case ConversionKind.CollectionExpression: + // Skip through target-typed collection expressions Debug.Assert(node.Type.Equals(node.Operand.Type, TypeCompareKind.AllIgnoreOptions)); return VisitExpression(node.Operand)!; } diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForStatement.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForStatement.cs index 5118830560802..1ac1cdd3d013b 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForStatement.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_ForStatement.cs @@ -48,7 +48,7 @@ private BoundStatement RewriteForStatementWithoutInnerLocals( GeneratedLabelSymbol continueLabel, bool hasErrors) { - Debug.Assert(original.Kind is BoundKind.ForStatement or BoundKind.ForEachStatement or BoundKind.CollectionLiteralSpreadElement); + Debug.Assert(original.Kind is BoundKind.ForStatement or BoundKind.ForEachStatement or BoundKind.CollectionExpressionSpreadElement); Debug.Assert(rewrittenBody != null); // The sequence point behavior exhibited here is different from that of the native compiler. In the native @@ -151,7 +151,7 @@ private BoundStatement RewriteForStatementWithoutInnerLocals( case BoundKind.ForStatement: branchBack = Instrumenter.InstrumentForStatementConditionalGotoStartOrBreak((BoundForStatement)original, branchBack); break; - case BoundKind.CollectionLiteralSpreadElement: + case BoundKind.CollectionExpressionSpreadElement: // No instrumentation needed since the loop for the spread expression // was generated in lowering, and not explicit in the source. break; diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_WhileStatement.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_WhileStatement.cs index 5ea8e4761b89a..910a0c4e3f7f5 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_WhileStatement.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_WhileStatement.cs @@ -46,7 +46,7 @@ private BoundStatement RewriteWhileStatement( GeneratedLabelSymbol continueLabel, bool hasErrors) { - Debug.Assert(loop.Kind is BoundKind.WhileStatement or BoundKind.ForEachStatement or BoundKind.CollectionLiteralSpreadElement); + Debug.Assert(loop.Kind is BoundKind.WhileStatement or BoundKind.ForEachStatement or BoundKind.CollectionExpressionSpreadElement); // while (condition) // body; @@ -79,7 +79,7 @@ private BoundStatement RewriteWhileStatement( ifConditionGotoStart = Instrumenter.InstrumentForEachStatementConditionalGotoStart((BoundForEachStatement)loop, ifConditionGotoStart); break; - case BoundKind.CollectionLiteralSpreadElement: + case BoundKind.CollectionExpressionSpreadElement: // No instrumentation needed since the loop for the spread expression // was generated in lowering, and not explicit in the source. break; diff --git a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs index a09e5851da179..1c65fe6d4534e 100644 --- a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs +++ b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs @@ -100,10 +100,10 @@ public CSharpOperationFactory(SemanticModel semanticModel) return CreateBoundArrayCreationOperation((BoundArrayCreation)boundNode); case BoundKind.ArrayInitialization: return CreateBoundArrayInitializationOperation((BoundArrayInitialization)boundNode); - case BoundKind.CollectionLiteralExpression: - return CreateBoundCollectionLiteralExpression((BoundCollectionLiteralExpression)boundNode); - case BoundKind.CollectionLiteralSpreadElement: - return CreateBoundCollectionLiteralSpreadElement((BoundCollectionLiteralSpreadElement)boundNode); + case BoundKind.CollectionExpression: + return CreateBoundCollectionExpression((BoundCollectionExpression)boundNode); + case BoundKind.CollectionExpressionSpreadElement: + return CreateBoundCollectionExpressionSpreadElement((BoundCollectionExpressionSpreadElement)boundNode); case BoundKind.DefaultLiteral: return CreateBoundDefaultLiteralOperation((BoundDefaultLiteral)boundNode); case BoundKind.DefaultExpression: @@ -306,7 +306,7 @@ public CSharpOperationFactory(SemanticModel semanticModel) case BoundKind.StackAllocArrayCreation: case BoundKind.TypeExpression: case BoundKind.TypeOrValueExpression: - case BoundKind.UnconvertedCollectionLiteralExpression: + case BoundKind.UnconvertedCollectionExpression: ConstantValue? constantValue = (boundNode as BoundExpression)?.ConstantValueOpt; bool isImplicit = boundNode.WasCompilerGenerated; @@ -1221,12 +1221,12 @@ private IArrayInitializerOperation CreateBoundArrayInitializationOperation(Bound return new ArrayInitializerOperation(elementValues, _semanticModel, syntax, isImplicit); } - private IOperation CreateBoundCollectionLiteralExpression(BoundCollectionLiteralExpression boundCollectionLiteralExpression) + private IOperation CreateBoundCollectionExpression(BoundCollectionExpression boundCollectionExpression) { - ImmutableArray elements = createChildren(boundCollectionLiteralExpression.Elements); - SyntaxNode syntax = boundCollectionLiteralExpression.Syntax; - ITypeSymbol? type = boundCollectionLiteralExpression.GetPublicTypeSymbol(); - bool isImplicit = boundCollectionLiteralExpression.WasCompilerGenerated; + ImmutableArray elements = createChildren(boundCollectionExpression.Elements); + SyntaxNode syntax = boundCollectionExpression.Syntax; + ITypeSymbol? type = boundCollectionExpression.GetPublicTypeSymbol(); + bool isImplicit = boundCollectionExpression.WasCompilerGenerated; return new NoneOperation(elements, _semanticModel, syntax, type: type, constantValue: null, isImplicit); ImmutableArray createChildren(ImmutableArray elements) @@ -1254,7 +1254,7 @@ ImmutableArray createChildren(ImmutableArray elemen } } - private IOperation CreateBoundCollectionLiteralSpreadElement(BoundCollectionLiteralSpreadElement boundSpreadExpression) + private IOperation CreateBoundCollectionExpressionSpreadElement(BoundCollectionExpressionSpreadElement boundSpreadExpression) { SyntaxNode syntax = boundSpreadExpression.Syntax; ITypeSymbol? type = boundSpreadExpression.GetPublicTypeSymbol(); diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index f8a07092d4007..18d5b486a2e65 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -532,7 +532,7 @@ private void ParseNamespaceBody( case SyntaxKind.OpenBracketToken: if (this.IsPossibleGlobalAttributeDeclaration()) { - // Could be an attribute, or it could be a collection literal at the top level. e.g. + // Could be an attribute, or it could be a collection expression at the top level. e.g. // `[assembly: 1].XYZ();`. While this is definitely odd code, it is totally legal (as // `assembly` is just an identifier). var attribute = this.TryParseAttributeDeclaration(inExpressionContext: parentKind == SyntaxKind.CompilationUnit); @@ -916,7 +916,7 @@ private bool IsAttributeDeclarationTerminator() return (AttributeListSyntax)this.EatNode(); } - // May have to reset if we discover this is not an attribute but is instead a collection literal. + // May have to reset if we discover this is not an attribute but is instead a collection expression. using var resetPoint = GetDisposableResetPoint(resetOnDispose: false); var openBracket = this.EatToken(SyntaxKind.OpenBracketToken); @@ -937,9 +937,9 @@ private bool IsAttributeDeclarationTerminator() allowSemicolonAsSeparator: false); var closeBracket = this.EatToken(SyntaxKind.CloseBracketToken); - if (inExpressionContext && shouldParseAsCollectionLiteral()) + if (inExpressionContext && shouldParseAsCollectionExpression()) { - // we're in an expression and we've seen `[A, B].` This is actually the start of a collection literal + // we're in an expression and we've seen `[A, B].` This is actually the start of a collection expression // that someone is explicitly accessing a member off of. resetPoint.Reset(); return null; @@ -947,19 +947,19 @@ private bool IsAttributeDeclarationTerminator() return _syntaxFactory.AttributeList(openBracket, location, attributes, closeBracket); - bool shouldParseAsCollectionLiteral() + bool shouldParseAsCollectionExpression() { - // `[A, B].` is a member access off of a collection literal. + // `[A, B].` is a member access off of a collection expression. if (this.CurrentToken.Kind == SyntaxKind.DotToken) return true; - // `[A, B]->` is a member access off of a collection literal. Note: this will always be illegal - // semantically (as a collection literal has the natural type List<> which is not a pointer type). But + // `[A, B]->` is a member access off of a collection expression. Note: this will always be illegal + // semantically (as a collection expression has the natural type List<> which is not a pointer type). But // we leave that check to binding. if (this.CurrentToken.Kind == SyntaxKind.MinusGreaterThanToken) return true; - // `[A, B]?.` The `?` is unnecessary (as a collection literal is always non-null), but is still + // `[A, B]?.` The `?` is unnecessary (as a collection expression is always non-null), but is still // syntactically legal. if (this.CurrentToken.Kind == SyntaxKind.QuestionToken && this.PeekToken(1).Kind == SyntaxKind.DotToken) @@ -7470,7 +7470,7 @@ or SyntaxKind.MinusMinusToken { // There are a few things that could be happening here: // - // First is that we have an actual collection literal that we're invoking. For example: + // First is that we have an actual collection expression that we're invoking. For example: // // `[() => {}][rand.NextInt() % x]();` // @@ -7489,7 +7489,7 @@ or SyntaxKind.MinusMinusToken // // etc. // - // Note: we do not accept the naked `[...](...)` as an invocation of a collection literal. Collection + // Note: we do not accept the naked `[...](...)` as an invocation of a collection expression. Collection // literals never have a type that itself could possibly be invoked, so this ensures a more natural parse // with what users may be expecting here. var returnType = this.ParseReturnType(); @@ -10119,7 +10119,7 @@ private bool IsPossibleExpression(bool allowBinaryExpressions, bool allowAssignm case SyntaxKind.StackAllocKeyword: case SyntaxKind.DotDotToken: case SyntaxKind.RefKeyword: - case SyntaxKind.OpenBracketToken: // attributes on a lambda, or a collection literal. + case SyntaxKind.OpenBracketToken: // attributes on a lambda, or a collection expression. return true; case SyntaxKind.StaticKeyword: return IsPossibleAnonymousMethodExpression() || IsPossibleLambdaExpression(Precedence.Expression); @@ -11849,18 +11849,18 @@ var tk case ScanTypeFlags.GenericTypeOrMethod: case ScanTypeFlags.TupleType: - // If we have `(X)[...` then we know this must be a cast of a collection literal, not an index + // If we have `(X)[...` then we know this must be a cast of a collection expression, not an index // into some expr. As most collections are generic, the common case is not ambiguous. // // Things are still ambiguous if you have `(X)[...` and for back compat we still parse that as // indexing into an expression. The user can still write `(X)([...` in this case though to get cast - // parsing. As non-generic casts are the rare case for collection literals, this gives a good + // parsing. As non-generic casts are the rare case for collection expressions, this gives a good // balance of back compat and user ease for the normal case. return this.CurrentToken.Kind == SyntaxKind.OpenBracketToken || CanFollowCast(this.CurrentToken.Kind); case ScanTypeFlags.GenericTypeOrExpression: case ScanTypeFlags.NonGenericTypeOrExpression: - // if we have `(A)[]` then treat that always as a cast of an empty collection literal. `[]` is not + // if we have `(A)[]` then treat that always as a cast of an empty collection expression. `[]` is not // legal on the RHS in any other circumstances for a parenthesized expr. if (this.CurrentToken.Kind == SyntaxKind.OpenBracketToken && this.PeekToken(1).Kind == SyntaxKind.CloseBracketToken) diff --git a/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt b/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt index 225bc3b4430ca..63f7b02b42d09 100644 --- a/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt @@ -1,5 +1,5 @@ Microsoft.CodeAnalysis.CSharp.Conversion.IsInlineArray.get -> bool -Microsoft.CodeAnalysis.CSharp.Conversion.IsCollectionLiteral.get -> bool +Microsoft.CodeAnalysis.CSharp.Conversion.IsCollectionExpression.get -> bool Microsoft.CodeAnalysis.CSharp.Syntax.CollectionExpressionSyntax Microsoft.CodeAnalysis.CSharp.Syntax.CollectionExpressionSyntax.AddElements(params Microsoft.CodeAnalysis.CSharp.Syntax.CollectionElementSyntax![]! items) -> Microsoft.CodeAnalysis.CSharp.Syntax.CollectionExpressionSyntax! Microsoft.CodeAnalysis.CSharp.Syntax.CollectionExpressionSyntax.CloseBracketToken.get -> Microsoft.CodeAnalysis.SyntaxToken diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index ca900a502a84b..3b2e3e7d119e4 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -397,14 +397,14 @@ {0} neimplementuje člen rozhraní {1}. {2} nemůže implementovat {1}. - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ Strom výrazů nesmí obsahovat přístup statického virtuálního člena nebo člena abstraktního rozhraní. - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ zaškrtnuté uživatelem definované operátory - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index f37e5f17b75f2..f8b3e452ec1e1 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -397,14 +397,14 @@ Der Schnittstellenmember "{1}" wird von "{0}" nicht implementiert. "{1}" kann von "{2}" nicht implementiert werden. - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ Eine Ausdrucksbaumstruktur darf keinen Zugriff auf einen statischen virtuellen oder abstrakten Schnittstellenmember enthalten. - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ Überprüfte benutzerdefinierte Operatoren - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 650e58162ae80..c0b336176da20 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -397,14 +397,14 @@ "{0}" no implementa el miembro de interfaz "{1}". "{2}" no puede implementar "{1}". - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ Un árbol de (la) expresión no puede contener un acceso de miembro de interfaz abstracta o virtual estática - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ operadores definidos por el usuario comprobados - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index c46f8ad4fdf00..abf6080bb4a75 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -397,14 +397,14 @@ '{0}' n'implémente pas le membre d'interface '{1}'. '{2}' ne peut pas implémenter '{1}'. - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ Une arborescence d’expressions ne peut pas contenir d’accès à un membre d’interface virtuelle ou abstraite statique - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ opérateurs définis par l’utilisateur vérifiés - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 740293753934a..07440c389a402 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -397,14 +397,14 @@ '{0}' non implementa il membro di interfaccia '{1}'. '{2}' non può implementare '{1}'. - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ Un albero delle espressioni può non contenere un accesso del membro di interfaccia statico astratto o virtuale - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ operatori definiti dall'utente controllati - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 2c2762b3958e6..b256ada13eb3a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -397,14 +397,14 @@ '{0}' は、インターフェイス メンバー '{1}' を実装していません。'{2}' は '{1}' を実装できません。 - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ 式ツリーに静的仮想または抽象インターフェイス メンバーへのアクセス権を含めることはできません - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ チェックされたユーザー定義演算子 - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index a9424d06530a2..d61685b9ac12f 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -397,14 +397,14 @@ '{0}'은(는) 인터페이스 멤버 '{1}'을(를) 구현하지 않습니다. '{2}'은(는) '{1}'을(를) 구현할 수 없습니다. - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ 식 트리는 정적 가상 또는 추상 인터페이스 구성원에 대한 액세스를 포함할 수 없습니다. - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ 확인된 사용자 정의 연산자 - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 27f2ead1d61a5..cddf0e5277014 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -397,14 +397,14 @@ Element „{0}” nie implementuje składowej interfejsu „{1}”. Element „{2}” nie może implementować elementu „{1}”. - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ Drzewo wyrażenia nie może zawierać dostępu do statycznej składowej abstrakcyjnej lub wirtualnej w interfejsie - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ zaznaczone operatory zdefiniowane przez użytkownika - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 759d6d68e0605..c13d872d443aa 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -397,14 +397,14 @@ '{0}' não implementa o membro de interface '{1}'. '{2}' não pode implementar '{1}'. - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ Uma árvore de expressão pode não conter um acesso de membro de interface de abstrato estático ou virtual - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ operadores verificados, definidos pelo usuário - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index da6c8057b9b59..19cc3b6f61019 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -397,14 +397,14 @@ "{0}" не реализует элемент интерфейса "{1}". "{2}" не может реализовывать "{1}". - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ Дерево выражения не может содержать доступ к статическому виртуальному или абстрактному элементу интерфейса. - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ проверенные операторы, определяемые пользователем - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 0c09ed70c5c61..d02d57383a7ce 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -397,14 +397,14 @@ '{0}, '{1}' arabirim üyesini uygulamıyor. '{2}', '{1}' üyesini uygulayamaz. - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ İfade ağacı statik sanal veya soyut arabirim üyesi erişimi içermeyebilir - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ kullanıcı tanımlı işleçler işaretlendi - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 62561e73f621a..c904adddbc9c2 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -397,14 +397,14 @@ “{0}”不实现接口成员“{1}”。“{2}”无法实现“{1}”。 - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ 表达式树可能不包含静态虚拟或抽象接口成员的访问权限 - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ 选中的用户定义运算符 - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index dabf7c3d56aae..cdba81d752b35 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -397,14 +397,14 @@ '{0}' 未實作介面成員 '{1}'。'{2}' 無法實作 '{1}'。 - - There is no target type for the collection literal. - There is no target type for the collection literal. + + There is no target type for the collection expression. + There is no target type for the collection expression. - - Cannot initialize type '{0}' with a collection literal because the type is not constructible. - Cannot initialize type '{0}' with a collection literal because the type is not constructible. + + Cannot initialize type '{0}' with a collection expression because the type is not constructible. + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -592,9 +592,9 @@ 運算式樹狀架構不可包含靜態虛擬或抽象介面成員的存取權 - - An expression tree may not contain a collection literal. - An expression tree may not contain a collection literal. + + An expression tree may not contain a collection expression. + An expression tree may not contain a collection expression. @@ -2052,9 +2052,9 @@ 已檢查使用者定義的運算子 - - collection literals - collection literals + + collection expressions + collection expressions diff --git a/src/Compilers/CSharp/Test/Emit2/Semantics/CollectionLiteralTests.cs b/src/Compilers/CSharp/Test/Emit2/Semantics/CollectionLiteralTests.cs index 067b7e2f4c6b6..de0d18e16893d 100644 --- a/src/Compilers/CSharp/Test/Emit2/Semantics/CollectionLiteralTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/Semantics/CollectionLiteralTests.cs @@ -13,7 +13,7 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests { - public class CollectionLiteralTests : CSharpTestBase + public class CollectionExpressionTests : CSharpTestBase { private const string s_collectionExtensions = """ using System; @@ -124,18 +124,18 @@ static void Main() if (languageVersion == LanguageVersion.CSharp11) { comp.VerifyEmitDiagnostics( - // (6,22): error CS8652: The feature 'collection literals' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. + // (6,22): error CS8652: The feature 'collection expressions' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. // object[] x = []; - Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection literals").WithLocation(6, 22), - // (7,26): error CS8652: The feature 'collection literals' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. + Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection expressions").WithLocation(6, 22), + // (7,26): error CS8652: The feature 'collection expressions' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. // List y = [1, 2, 3]; - Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection literals").WithLocation(7, 26), - // (8,28): error CS8652: The feature 'collection literals' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. + Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection expressions").WithLocation(7, 26), + // (8,28): error CS8652: The feature 'collection expressions' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. // List z = [[]]; - Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection literals").WithLocation(8, 28), - // (8,29): error CS8652: The feature 'collection literals' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. + Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection expressions").WithLocation(8, 28), + // (8,29): error CS8652: The feature 'collection expressions' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. // List z = [[]]; - Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection literals").WithLocation(8, 29)); + Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection expressions").WithLocation(8, 29)); } else { @@ -159,15 +159,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,20): error CS9174: Cannot initialize type 'object' with a collection literal because the type is not constructible. + // (5,20): error CS9174: Cannot initialize type 'object' with a collection expression because the type is not constructible. // object x = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("object").WithLocation(5, 20), - // (6,21): error CS9174: Cannot initialize type 'dynamic' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("object").WithLocation(5, 20), + // (6,21): error CS9174: Cannot initialize type 'dynamic' with a collection expression because the type is not constructible. // dynamic y = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("dynamic").WithLocation(6, 21), - // (7,17): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("dynamic").WithLocation(6, 21), + // (7,17): error CS9176: There is no target type for the collection expression. // var z = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(7, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(7, 17)); var tree = comp.SyntaxTrees[0]; var model = comp.GetSemanticModel(tree); @@ -194,15 +194,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,20): error CS9174: Cannot initialize type 'object' with a collection literal because the type is not constructible. + // (5,20): error CS9174: Cannot initialize type 'object' with a collection expression because the type is not constructible. // object x = [1]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1]").WithArguments("object").WithLocation(5, 20), - // (6,21): error CS9174: Cannot initialize type 'dynamic' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1]").WithArguments("object").WithLocation(5, 20), + // (6,21): error CS9174: Cannot initialize type 'dynamic' with a collection expression because the type is not constructible. // dynamic y = [2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[2]").WithArguments("dynamic").WithLocation(6, 21), - // (7,17): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[2]").WithArguments("dynamic").WithLocation(6, 21), + // (7,17): error CS9176: There is no target type for the collection expression. // var z = [3]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[3]").WithLocation(7, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[3]").WithLocation(7, 17)); var tree = comp.SyntaxTrees[0]; var model = comp.GetSemanticModel(tree); @@ -229,15 +229,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,20): error CS9174: Cannot initialize type 'object' with a collection literal because the type is not constructible. + // (5,20): error CS9174: Cannot initialize type 'object' with a collection expression because the type is not constructible. // object x = [1, ""]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, @"[1, """"]").WithArguments("object").WithLocation(5, 20), - // (6,21): error CS9174: Cannot initialize type 'dynamic' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, @"[1, """"]").WithArguments("object").WithLocation(5, 20), + // (6,21): error CS9174: Cannot initialize type 'dynamic' with a collection expression because the type is not constructible. // dynamic y = [2, ""]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, @"[2, """"]").WithArguments("dynamic").WithLocation(6, 21), - // (7,17): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, @"[2, """"]").WithArguments("dynamic").WithLocation(6, 21), + // (7,17): error CS9176: There is no target type for the collection expression. // var z = [3, ""]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, @"[3, """"]").WithLocation(7, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, @"[3, """"]").WithLocation(7, 17)); } [Fact] @@ -257,15 +257,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,20): error CS9174: Cannot initialize type 'object' with a collection literal because the type is not constructible. + // (5,20): error CS9174: Cannot initialize type 'object' with a collection expression because the type is not constructible. // object x = [null]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[null]").WithArguments("object").WithLocation(5, 20), - // (6,21): error CS9174: Cannot initialize type 'dynamic' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[null]").WithArguments("object").WithLocation(5, 20), + // (6,21): error CS9174: Cannot initialize type 'dynamic' with a collection expression because the type is not constructible. // dynamic y = [null]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[null]").WithArguments("dynamic").WithLocation(6, 21), - // (7,17): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[null]").WithArguments("dynamic").WithLocation(6, 21), + // (7,17): error CS9176: There is no target type for the collection expression. // var z = [null]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[null]").WithLocation(7, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[null]").WithLocation(7, 17)); } [Fact] @@ -285,15 +285,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,17): error CS9176: There is no target type for the collection literal. + // (5,17): error CS9176: There is no target type for the collection expression. // var x = [1, 2, null]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[1, 2, null]").WithLocation(5, 17), - // (6,20): error CS9174: Cannot initialize type 'object' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[1, 2, null]").WithLocation(5, 17), + // (6,20): error CS9174: Cannot initialize type 'object' with a collection expression because the type is not constructible. // object y = [1, 2, null]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1, 2, null]").WithArguments("object").WithLocation(6, 20), - // (7,21): error CS9174: Cannot initialize type 'dynamic' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1, 2, null]").WithArguments("object").WithLocation(6, 20), + // (7,21): error CS9174: Cannot initialize type 'dynamic' with a collection expression because the type is not constructible. // dynamic z = [1, 2, null]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1, 2, null]").WithArguments("dynamic").WithLocation(7, 21)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1, 2, null]").WithArguments("dynamic").WithLocation(7, 21)); } [Fact] @@ -310,9 +310,9 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,23): error CS9174: Cannot initialize type 'object' with a collection literal because the type is not constructible. + // (5,23): error CS9174: Cannot initialize type 'object' with a collection expression because the type is not constructible. // object[] x = [[]]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("object").WithLocation(5, 23)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("object").WithLocation(5, 23)); } [Fact] @@ -329,9 +329,9 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,23): error CS9174: Cannot initialize type 'object' with a collection literal because the type is not constructible. + // (5,23): error CS9174: Cannot initialize type 'object' with a collection expression because the type is not constructible. // object[] y = [[2]]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[2]").WithArguments("object").WithLocation(5, 23)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[2]").WithArguments("object").WithLocation(5, 23)); } [Fact] @@ -348,9 +348,9 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,17): error CS9176: There is no target type for the collection literal. + // (5,17): error CS9176: There is no target type for the collection expression. // var z = [[3]]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[[3]]").WithLocation(5, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[[3]]").WithLocation(5, 17)); } [Fact] @@ -442,15 +442,15 @@ static void Main() """; var comp = CreateCompilation(new[] { source, s_collectionExtensions }); comp.VerifyEmitDiagnostics( - // 0.cs(6,25): error CS9174: Cannot initialize type 'IEnumerable' with a collection literal because the type is not constructible. + // 0.cs(6,25): error CS9174: Cannot initialize type 'IEnumerable' with a collection expression because the type is not constructible. // IEnumerable a = [1]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1]").WithArguments("System.Collections.IEnumerable").WithLocation(6, 25), - // 0.cs(7,25): error CS9174: Cannot initialize type 'ICollection' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1]").WithArguments("System.Collections.IEnumerable").WithLocation(6, 25), + // 0.cs(7,25): error CS9174: Cannot initialize type 'ICollection' with a collection expression because the type is not constructible. // ICollection b = [2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[2]").WithArguments("System.Collections.ICollection").WithLocation(7, 25), - // 0.cs(8,19): error CS9174: Cannot initialize type 'IList' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[2]").WithArguments("System.Collections.ICollection").WithLocation(7, 25), + // 0.cs(8,19): error CS9174: Cannot initialize type 'IList' with a collection expression because the type is not constructible. // IList c = [3]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[3]").WithArguments("System.Collections.IList").WithLocation(8, 19)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[3]").WithArguments("System.Collections.IList").WithLocation(8, 19)); } [Fact] @@ -523,12 +523,12 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,17): error CS9176: There is no target type for the collection literal. + // (5,17): error CS9176: There is no target type for the collection expression. // var x = [null, 1]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[null, 1]").WithLocation(5, 17), - // (6,20): error CS9174: Cannot initialize type 'object' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[null, 1]").WithLocation(5, 17), + // (6,20): error CS9174: Cannot initialize type 'object' with a collection expression because the type is not constructible. // object y = [null, 2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[null, 2]").WithArguments("object").WithLocation(6, 20)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[null, 2]").WithArguments("object").WithLocation(6, 20)); } [Fact] @@ -556,18 +556,18 @@ static void F2(int i) var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (12,18): error CS9176: There is no target type for the collection literal. + // (12,18): error CS9176: There is no target type for the collection expression. // var x2 = [(null, default)]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[(null, default)]").WithLocation(12, 18), - // (13,18): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[(null, default)]").WithLocation(12, 18), + // (13,18): error CS9176: There is no target type for the collection expression. // var y2 = [i switch { _ => default }]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[i switch { _ => default }]").WithLocation(13, 18), + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[i switch { _ => default }]").WithLocation(13, 18), // (13,21): error CS8506: No best type was found for the switch expression. // var y2 = [i switch { _ => default }]; Diagnostic(ErrorCode.ERR_SwitchExpressionNoBestType, "switch").WithLocation(13, 21), - // (14,18): error CS9176: There is no target type for the collection literal. + // (14,18): error CS9176: There is no target type for the collection expression. // var z2 = [i == 0 ? null : default]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[i == 0 ? null : default]").WithLocation(14, 18), + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[i == 0 ? null : default]").WithLocation(14, 18), // (14,19): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between '' and 'default' // var z2 = [i == 0 ? null : default]; Diagnostic(ErrorCode.ERR_InvalidQM, "i == 0 ? null : default").WithArguments("", "default").WithLocation(14, 19)); @@ -1045,9 +1045,9 @@ static void Main(string[] args) """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (6,17): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'collection literals' and 'collection literals' + // (6,17): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'collection expressions' and 'collection expressions' // var y = b ? [new int[0]] : [[1, 2, 3]]; - Diagnostic(ErrorCode.ERR_InvalidQM, "b ? [new int[0]] : [[1, 2, 3]]").WithArguments("collection literals", "collection literals").WithLocation(6, 17)); + Diagnostic(ErrorCode.ERR_InvalidQM, "b ? [new int[0]] : [[1, 2, 3]]").WithArguments("collection expressions", "collection expressions").WithLocation(6, 17)); } [Fact] @@ -1170,9 +1170,9 @@ static void Main() """; var comp = CreateCompilation(new[] { source, s_collectionExtensions }); comp.VerifyEmitDiagnostics( - // 0.cs(9,29): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'collection literals' and 'collection literals' + // 0.cs(9,29): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'collection expressions' and 'collection expressions' // var a = AsArray([.. b ? [x] : [y]]); - Diagnostic(ErrorCode.ERR_InvalidQM, "b ? [x] : [y]").WithArguments("collection literals", "collection literals").WithLocation(9, 29)); + Diagnostic(ErrorCode.ERR_InvalidQM, "b ? [x] : [y]").WithArguments("collection expressions", "collection expressions").WithLocation(9, 29)); } [Fact] @@ -1194,9 +1194,9 @@ static void Main() """; var comp = CreateCompilation(new[] { source, s_collectionExtensions }); comp.VerifyEmitDiagnostics( - // 0.cs(9,17): error CS9176: There is no target type for the collection literal. + // 0.cs(9,17): error CS9176: There is no target type for the collection expression. // var a = [1, 2, 3].AsArray(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[1, 2, 3]").WithLocation(9, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[1, 2, 3]").WithLocation(9, 17)); } [Fact] @@ -1235,9 +1235,9 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (27,17): error CS9176: There is no target type for the collection literal. + // (27,17): error CS9176: There is no target type for the collection expression. // var b = [4].AsCollection(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[4]").WithLocation(27, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[4]").WithLocation(27, 17)); } [Fact] @@ -1268,9 +1268,9 @@ static void Main() // (15,13): error CS0411: The type arguments for method 'Program.AsCollection(S)' cannot be inferred from the usage. Try specifying the type arguments explicitly. // _ = AsCollection([1, 2, 3]); Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs, "AsCollection").WithArguments("Program.AsCollection(S)").WithLocation(15, 13), - // (16,13): error CS9176: There is no target type for the collection literal. + // (16,13): error CS9176: There is no target type for the collection expression. // _ = [4].AsCollection(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[4]").WithLocation(16, 13)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[4]").WithLocation(16, 13)); } [Fact] @@ -1687,9 +1687,9 @@ static void Main() // (6,9): error CS0411: The type arguments for method 'Program.F(T[*,*])' cannot be inferred from the usage. Try specifying the type arguments explicitly. // F([]); Diagnostic(ErrorCode.ERR_CantInferMethTypeArgs, "F").WithArguments("Program.F(T[*,*])").WithLocation(6, 9), - // (7,11): error CS1503: Argument 1: cannot convert from 'collection literals' to 'int[*,*]' + // (7,11): error CS1503: Argument 1: cannot convert from 'collection expressions' to 'int[*,*]' // F([null, default, 0]); - Diagnostic(ErrorCode.ERR_BadArgType, "[null, default, 0]").WithArguments("1", "collection literals", "int[*,*]").WithLocation(7, 11)); + Diagnostic(ErrorCode.ERR_BadArgType, "[null, default, 0]").WithArguments("1", "collection expressions", "int[*,*]").WithLocation(7, 11)); } [Fact] @@ -1747,15 +1747,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (10,12): error CS1503: Argument 1: cannot convert from 'collection literals' to 'dynamic' + // (10,12): error CS1503: Argument 1: cannot convert from 'collection expressions' to 'dynamic' // F1([1], [2]); - Diagnostic(ErrorCode.ERR_BadArgType, "[1]").WithArguments("1", "collection literals", "dynamic").WithLocation(10, 12), - // (11,12): error CS1503: Argument 1: cannot convert from 'collection literals' to 'D' + Diagnostic(ErrorCode.ERR_BadArgType, "[1]").WithArguments("1", "collection expressions", "dynamic").WithLocation(10, 12), + // (11,12): error CS1503: Argument 1: cannot convert from 'collection expressions' to 'D' // F2([3], [4]); - Diagnostic(ErrorCode.ERR_BadArgType, "[3]").WithArguments("1", "collection literals", "D").WithLocation(11, 12), - // (12,12): error CS1503: Argument 1: cannot convert from 'collection literals' to 'E' + Diagnostic(ErrorCode.ERR_BadArgType, "[3]").WithArguments("1", "collection expressions", "D").WithLocation(11, 12), + // (12,12): error CS1503: Argument 1: cannot convert from 'collection expressions' to 'E' // F3([5], [6]); - Diagnostic(ErrorCode.ERR_BadArgType, "[5]").WithArguments("1", "collection literals", "E").WithLocation(12, 12)); + Diagnostic(ErrorCode.ERR_BadArgType, "[5]").WithArguments("1", "collection expressions", "E").WithLocation(12, 12)); } [Fact] @@ -2071,15 +2071,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,9): error CS9176: There is no target type for the collection literal. + // (5,9): error CS9176: There is no target type for the collection expression. // [].GetHashCode(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(5, 9), - // (6,9): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(5, 9), + // (6,9): error CS9176: There is no target type for the collection expression. // []?.GetHashCode(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(6, 9), - // (7,9): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(6, 9), + // (7,9): error CS9176: There is no target type for the collection expression. // [][0].GetHashCode(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(7, 9)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(7, 9)); } [Fact] @@ -2098,15 +2098,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,9): error CS9176: There is no target type for the collection literal. + // (5,9): error CS9176: There is no target type for the collection expression. // [1].GetHashCode(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[1]").WithLocation(5, 9), - // (6,9): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[1]").WithLocation(5, 9), + // (6,9): error CS9176: There is no target type for the collection expression. // [2]?.GetHashCode(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[2]").WithLocation(6, 9), - // (7,9): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[2]").WithLocation(6, 9), + // (7,9): error CS9176: There is no target type for the collection expression. // [3][0].GetHashCode(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[3]").WithLocation(7, 9)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[3]").WithLocation(7, 9)); } [Fact] @@ -2125,15 +2125,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,13): error CS9176: There is no target type for the collection literal. + // (5,13): error CS9176: There is no target type for the collection expression. // _ = [].GetHashCode(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(5, 13), - // (6,13): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(5, 13), + // (6,13): error CS9176: There is no target type for the collection expression. // _ = []?.GetHashCode(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(6, 13), - // (7,13): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(6, 13), + // (7,13): error CS9176: There is no target type for the collection expression. // _ = [][0].GetHashCode(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(7, 13)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(7, 13)); } [Fact] @@ -2152,15 +2152,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,13): error CS9176: There is no target type for the collection literal. + // (5,13): error CS9176: There is no target type for the collection expression. // _ = [1].GetHashCode(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[1]").WithLocation(5, 13), - // (6,13): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[1]").WithLocation(5, 13), + // (6,13): error CS9176: There is no target type for the collection expression. // _ = [2]?.GetHashCode(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[2]").WithLocation(6, 13), - // (7,13): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[2]").WithLocation(6, 13), + // (7,13): error CS9176: There is no target type for the collection expression. // _ = [3][0].GetHashCode(); - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[3]").WithLocation(7, 13)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[3]").WithLocation(7, 13)); } [Fact] @@ -2272,15 +2272,15 @@ static void Main() comp.VerifyEmitDiagnostics( // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1), - // 1.cs(7,16): error CS9174: Cannot initialize type 'IA' with a collection literal because the type is not constructible. + // 1.cs(7,16): error CS9174: Cannot initialize type 'IA' with a collection expression because the type is not constructible. // IA a = [2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[2]").WithArguments("System.Collections.Generic.IA").WithLocation(7, 16), - // 1.cs(9,24): error CS9174: Cannot initialize type 'IC' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[2]").WithArguments("System.Collections.Generic.IA").WithLocation(7, 16), + // 1.cs(9,24): error CS9174: Cannot initialize type 'IC' with a collection expression because the type is not constructible. // IC c = [4]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[4]").WithArguments("System.Collections.Generic.IC").WithLocation(9, 24), - // 1.cs(10,32): error CS9174: Cannot initialize type 'ID' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[4]").WithArguments("System.Collections.Generic.IC").WithLocation(9, 24), + // 1.cs(10,32): error CS9174: Cannot initialize type 'ID' with a collection expression because the type is not constructible. // ID d = [5]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[5]").WithArguments("System.Collections.Generic.ID").WithLocation(10, 32)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[5]").WithArguments("System.Collections.Generic.ID").WithLocation(10, 32)); } [Fact] @@ -2330,9 +2330,9 @@ static void Main() comp.VerifyEmitDiagnostics( // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1), - // 1.cs(8,29): error CS9174: Cannot initialize type 'IEquatable' with a collection literal because the type is not constructible. + // 1.cs(8,29): error CS9174: Cannot initialize type 'IEquatable' with a collection expression because the type is not constructible. // IEquatable e = [2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[2]").WithArguments("System.IEquatable").WithLocation(8, 29)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[2]").WithArguments("System.IEquatable").WithLocation(8, 29)); } [Fact] @@ -2374,12 +2374,12 @@ static void Main() comp.VerifyEmitDiagnostics( // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1), - // 1.cs(7,23): error CS9174: Cannot initialize type 'List' with a collection literal because the type is not constructible. + // 1.cs(7,23): error CS9174: Cannot initialize type 'List' with a collection expression because the type is not constructible. // List l = [1]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1]").WithArguments("System.Collections.Generic.List").WithLocation(7, 23), - // 1.cs(8,30): error CS9174: Cannot initialize type 'IEnumerable' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1]").WithArguments("System.Collections.Generic.List").WithLocation(7, 23), + // 1.cs(8,30): error CS9174: Cannot initialize type 'IEnumerable' with a collection expression because the type is not constructible. // IEnumerable e = [2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[2]").WithArguments("System.Collections.Generic.IEnumerable").WithLocation(8, 30)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[2]").WithArguments("System.Collections.Generic.IEnumerable").WithLocation(8, 30)); } [Fact] @@ -2402,21 +2402,21 @@ static void Main() var comp = CreateCompilation(source); comp.MakeTypeMissing(WellKnownType.System_Collections_Generic_List_T); comp.VerifyEmitDiagnostics( - // (6,30): error CS9174: Cannot initialize type 'IEnumerable' with a collection literal because the type is not constructible. + // (6,30): error CS9174: Cannot initialize type 'IEnumerable' with a collection expression because the type is not constructible. // IEnumerable a = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("System.Collections.Generic.IEnumerable").WithLocation(6, 30), - // (7,30): error CS9174: Cannot initialize type 'ICollection' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("System.Collections.Generic.IEnumerable").WithLocation(6, 30), + // (7,30): error CS9174: Cannot initialize type 'ICollection' with a collection expression because the type is not constructible. // ICollection b = [2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[2]").WithArguments("System.Collections.Generic.ICollection").WithLocation(7, 30), - // (8,24): error CS9174: Cannot initialize type 'IList' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[2]").WithArguments("System.Collections.Generic.ICollection").WithLocation(7, 30), + // (8,24): error CS9174: Cannot initialize type 'IList' with a collection expression because the type is not constructible. // IList c = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("System.Collections.Generic.IList").WithLocation(8, 24), - // (9,38): error CS9174: Cannot initialize type 'IReadOnlyCollection' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("System.Collections.Generic.IList").WithLocation(8, 24), + // (9,38): error CS9174: Cannot initialize type 'IReadOnlyCollection' with a collection expression because the type is not constructible. // IReadOnlyCollection d = [3]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[3]").WithArguments("System.Collections.Generic.IReadOnlyCollection").WithLocation(9, 38), - // (10,32): error CS9174: Cannot initialize type 'IReadOnlyList' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[3]").WithArguments("System.Collections.Generic.IReadOnlyCollection").WithLocation(9, 38), + // (10,32): error CS9174: Cannot initialize type 'IReadOnlyList' with a collection expression because the type is not constructible. // IReadOnlyList e = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("System.Collections.Generic.IReadOnlyList").WithLocation(10, 32)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("System.Collections.Generic.IReadOnlyList").WithLocation(10, 32)); } [Fact] @@ -2623,12 +2623,12 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,23): error CS9174: Cannot initialize type 'object[*,*]' with a collection literal because the type is not constructible. + // (5,23): error CS9174: Cannot initialize type 'object[*,*]' with a collection expression because the type is not constructible. // object[,] x = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("object[*,*]").WithLocation(5, 23), - // (6,20): error CS9174: Cannot initialize type 'int[*,*]' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("object[*,*]").WithLocation(5, 23), + // (6,20): error CS9174: Cannot initialize type 'int[*,*]' with a collection expression because the type is not constructible. // int[,] y = [null, 2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[null, 2]").WithArguments("int[*,*]").WithLocation(6, 20)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[null, 2]").WithArguments("int[*,*]").WithLocation(6, 20)); } [Fact] @@ -2645,9 +2645,9 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,20): error CS9174: Cannot initialize type 'int[*,*]' with a collection literal because the type is not constructible. + // (5,20): error CS9174: Cannot initialize type 'int[*,*]' with a collection expression because the type is not constructible. // int[,] z = [[1, 2], [3, 4]]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[[1, 2], [3, 4]]").WithArguments("int[*,*]").WithLocation(5, 20)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[[1, 2], [3, 4]]").WithArguments("int[*,*]").WithLocation(5, 20)); } [ConditionalTheory(typeof(CoreClrOnly))] @@ -2909,12 +2909,12 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (26,13): error CS9174: Cannot initialize type 'I' with a collection literal because the type is not constructible. + // (26,13): error CS9174: Cannot initialize type 'I' with a collection expression because the type is not constructible. // i = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("I").WithLocation(26, 13), - // (27,13): error CS9174: Cannot initialize type 'I' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("I").WithLocation(26, 13), + // (27,13): error CS9174: Cannot initialize type 'I' with a collection expression because the type is not constructible. // i = [3, 4]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[3, 4]").WithArguments("I").WithLocation(27, 13)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[3, 4]").WithArguments("I").WithLocation(27, 13)); } [Fact] @@ -2934,12 +2934,12 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (7,13): error CS9174: Cannot initialize type 'E' with a collection literal because the type is not constructible. + // (7,13): error CS9174: Cannot initialize type 'E' with a collection expression because the type is not constructible. // e = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("E").WithLocation(7, 13), - // (8,13): error CS9174: Cannot initialize type 'E' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("E").WithLocation(7, 13), + // (8,13): error CS9174: Cannot initialize type 'E' with a collection expression because the type is not constructible. // e = [1, 2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1, 2]").WithArguments("E").WithLocation(8, 13)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1, 2]").WithArguments("E").WithLocation(8, 13)); } [Fact] @@ -2985,12 +2985,12 @@ static void Main() comp.VerifyEmitDiagnostics( // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1), - // 1.cs(7,13): error CS9174: Cannot initialize type 'E' with a collection literal because the type is not constructible. + // 1.cs(7,13): error CS9174: Cannot initialize type 'E' with a collection expression because the type is not constructible. // e = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("E").WithLocation(7, 13), - // 1.cs(8,13): error CS9174: Cannot initialize type 'E' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("E").WithLocation(7, 13), + // 1.cs(8,13): error CS9174: Cannot initialize type 'E' with a collection expression because the type is not constructible. // e = [1, 2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1, 2]").WithArguments("E").WithLocation(8, 13)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1, 2]").WithArguments("E").WithLocation(8, 13)); } [Fact] @@ -3010,12 +3010,12 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (7,13): error CS9174: Cannot initialize type 'D' with a collection literal because the type is not constructible. + // (7,13): error CS9174: Cannot initialize type 'D' with a collection expression because the type is not constructible. // d = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("D").WithLocation(7, 13), - // (8,13): error CS9174: Cannot initialize type 'D' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("D").WithLocation(7, 13), + // (8,13): error CS9174: Cannot initialize type 'D' with a collection expression because the type is not constructible. // d = [1, 2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1, 2]").WithArguments("D").WithLocation(8, 13)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1, 2]").WithArguments("D").WithLocation(8, 13)); } [Fact] @@ -3063,12 +3063,12 @@ static void Main() comp.VerifyEmitDiagnostics( // warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. Diagnostic(ErrorCode.WRN_NoRuntimeMetadataVersion).WithLocation(1, 1), - // 1.cs(7,13): error CS9174: Cannot initialize type 'D' with a collection literal because the type is not constructible. + // 1.cs(7,13): error CS9174: Cannot initialize type 'D' with a collection expression because the type is not constructible. // d = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("D").WithLocation(7, 13), - // 1.cs(8,13): error CS9174: Cannot initialize type 'D' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("D").WithLocation(7, 13), + // 1.cs(8,13): error CS9174: Cannot initialize type 'D' with a collection expression because the type is not constructible. // d = [1, 2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1, 2]").WithArguments("D").WithLocation(8, 13)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1, 2]").WithArguments("D").WithLocation(8, 13)); } [Fact] @@ -3087,15 +3087,15 @@ unsafe static void Main() """; var comp = CreateCompilation(source, options: TestOptions.UnsafeReleaseExe); comp.VerifyEmitDiagnostics( - // (5,18): error CS9174: Cannot initialize type 'int*' with a collection literal because the type is not constructible. + // (5,18): error CS9174: Cannot initialize type 'int*' with a collection expression because the type is not constructible. // int* x = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("int*").WithLocation(5, 18), - // (6,18): error CS9174: Cannot initialize type 'int*' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("int*").WithLocation(5, 18), + // (6,18): error CS9174: Cannot initialize type 'int*' with a collection expression because the type is not constructible. // int* y = [1, 2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1, 2]").WithArguments("int*").WithLocation(6, 18), - // (7,17): error CS9174: Cannot initialize type 'int*' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1, 2]").WithArguments("int*").WithLocation(6, 18), + // (7,17): error CS9174: Cannot initialize type 'int*' with a collection expression because the type is not constructible. // var z = (int*)[3]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "(int*)[3]").WithArguments("int*").WithLocation(7, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "(int*)[3]").WithArguments("int*").WithLocation(7, 17)); } [Fact] @@ -3114,15 +3114,15 @@ unsafe static void Main() """; var comp = CreateCompilation(source, options: TestOptions.UnsafeReleaseExe); comp.VerifyEmitDiagnostics( - // (5,29): error CS9174: Cannot initialize type 'delegate*' with a collection literal because the type is not constructible. + // (5,29): error CS9174: Cannot initialize type 'delegate*' with a collection expression because the type is not constructible. // delegate* x = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("delegate*").WithLocation(5, 29), - // (6,29): error CS9174: Cannot initialize type 'delegate*' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("delegate*").WithLocation(5, 29), + // (6,29): error CS9174: Cannot initialize type 'delegate*' with a collection expression because the type is not constructible. // delegate* y = [1, 2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1, 2]").WithArguments("delegate*").WithLocation(6, 29), - // (7,17): error CS9174: Cannot initialize type 'delegate*' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1, 2]").WithArguments("delegate*").WithLocation(6, 29), + // (7,17): error CS9174: Cannot initialize type 'delegate*' with a collection expression because the type is not constructible. // var z = (delegate*)[3]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "(delegate*)[3]").WithArguments("delegate*").WithLocation(7, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "(delegate*)[3]").WithArguments("delegate*").WithLocation(7, 17)); } [Fact] @@ -3142,12 +3142,12 @@ unsafe static void Main() """; var comp = CreateCompilation(source, options: TestOptions.UnsafeReleaseExe); comp.VerifyEmitDiagnostics( - // (7,17): error CS9176: There is no target type for the collection literal. + // (7,17): error CS9176: There is no target type for the collection expression. // var x = [p]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[p]").WithLocation(7, 17), - // (8,17): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[p]").WithLocation(7, 17), + // (8,17): error CS9176: There is no target type for the collection expression. // var y = [d]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[d]").WithLocation(8, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[d]").WithLocation(8, 17)); } [Fact] @@ -3289,15 +3289,15 @@ struct S { } """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (2,5): error CS9174: Cannot initialize type 'S' with a collection literal because the type is not constructible. + // (2,5): error CS9174: Cannot initialize type 'S' with a collection expression because the type is not constructible. // s = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("S").WithLocation(2, 5), - // (3,5): error CS9174: Cannot initialize type 'S' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("S").WithLocation(2, 5), + // (3,5): error CS9174: Cannot initialize type 'S' with a collection expression because the type is not constructible. // s = [1, 2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1, 2]").WithArguments("S").WithLocation(3, 5), - // (4,5): error CS9174: Cannot initialize type 'S' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1, 2]").WithArguments("S").WithLocation(3, 5), + // (4,5): error CS9174: Cannot initialize type 'S' with a collection expression because the type is not constructible. // s = [default]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[default]").WithArguments("S").WithLocation(4, 5), + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[default]").WithArguments("S").WithLocation(4, 5), // (5,6): error CS0103: The name 'Unknown' does not exist in the current context // s = [Unknown]; Diagnostic(ErrorCode.ERR_NameNotInContext, "Unknown").WithArguments("Unknown").WithLocation(5, 6)); @@ -4062,9 +4062,9 @@ class Program """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (16,57): error CS9174: Cannot initialize type 'T?' with a collection literal because the type is not constructible. + // (16,57): error CS9174: Cannot initialize type 'T?' with a collection expression because the type is not constructible. // static T? Create2() where T : struct, I => []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("T?").WithLocation(16, 57)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("T?").WithLocation(16, 57)); } [Fact] @@ -4136,12 +4136,12 @@ static void Main() var comp = CreateCompilation(source); comp.MakeTypeMissing(SpecialType.System_Collections_IEnumerable); comp.VerifyEmitDiagnostics( - // (8,15): error CS9174: Cannot initialize type 'S' with a collection literal because the type is not constructible. + // (8,15): error CS9174: Cannot initialize type 'S' with a collection expression because the type is not constructible. // S s = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("S").WithLocation(8, 15), - // (9,20): error CS9174: Cannot initialize type 'S' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("S").WithLocation(8, 15), + // (9,20): error CS9174: Cannot initialize type 'S' with a collection expression because the type is not constructible. // object o = (S)([1, 2]); - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "(S)([1, 2])").WithArguments("S").WithLocation(9, 20)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "(S)([1, 2])").WithArguments("S").WithLocation(9, 20)); } [Fact] @@ -4676,9 +4676,9 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,26): error CS9176: There is no target type for the collection literal. + // (5,26): error CS9176: There is no target type for the collection expression. // var a = [1, 2, ..[]]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(5, 26)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(5, 26)); } [Fact] @@ -4697,12 +4697,12 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (6,21): error CS9176: There is no target type for the collection literal. + // (6,21): error CS9176: There is no target type for the collection expression. // a = [..a, ..[]]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(6, 21), - // (7,16): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(6, 21), + // (7,16): error CS9176: There is no target type for the collection expression. // a = [..[default]]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[default]").WithLocation(7, 16)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[default]").WithLocation(7, 16)); } [Fact] @@ -4719,9 +4719,9 @@ static string[] Append(string a, string b, bool c) """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (5,26): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'collection literals' and 'collection literals' + // (5,26): error CS0173: Type of conditional expression cannot be determined because there is no implicit conversion between 'collection expressions' and 'collection expressions' // return [a, b, .. c ? [null] : []]; - Diagnostic(ErrorCode.ERR_InvalidQM, "c ? [null] : []").WithArguments("collection literals", "collection literals").WithLocation(5, 26)); + Diagnostic(ErrorCode.ERR_InvalidQM, "c ? [null] : []").WithArguments("collection expressions", "collection expressions").WithLocation(5, 26)); } [Fact] @@ -5009,9 +5009,9 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (6,11): error CS1503: Argument 1: cannot convert from 'collection literals' to 'System.Collections.IEnumerable' + // (6,11): error CS1503: Argument 1: cannot convert from 'collection expressions' to 'System.Collections.IEnumerable' // F([1, 2, 3]); - Diagnostic(ErrorCode.ERR_BadArgType, "[1, 2, 3]").WithArguments("1", "collection literals", "System.Collections.IEnumerable").WithLocation(6, 11), + Diagnostic(ErrorCode.ERR_BadArgType, "[1, 2, 3]").WithArguments("1", "collection expressions", "System.Collections.IEnumerable").WithLocation(6, 11), // (8,39): error CS1950: The best overloaded Add method 'List.Add(int)' for the collection initializer has some invalid arguments // static int[] F(IEnumerable s) => [..s]; Diagnostic(ErrorCode.ERR_BadArgTypesForCollectionAdd, "..s").WithArguments("System.Collections.Generic.List.Add(int)").WithLocation(8, 39), @@ -5289,18 +5289,18 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (13,24): error CS9174: Cannot initialize type 'S?' with a collection literal because the type is not constructible. + // (13,24): error CS9174: Cannot initialize type 'S?' with a collection expression because the type is not constructible. // S? x = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("S?").WithLocation(13, 24), - // (14,13): error CS9174: Cannot initialize type 'S?' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("S?").WithLocation(13, 24), + // (14,13): error CS9174: Cannot initialize type 'S?' with a collection expression because the type is not constructible. // x = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("S?").WithLocation(14, 13), - // (15,24): error CS9174: Cannot initialize type 'S?' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("S?").WithLocation(14, 13), + // (15,24): error CS9174: Cannot initialize type 'S?' with a collection expression because the type is not constructible. // S? y = [1]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1]").WithArguments("S?").WithLocation(15, 24), - // (16,13): error CS9174: Cannot initialize type 'S?' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1]").WithArguments("S?").WithLocation(15, 24), + // (16,13): error CS9174: Cannot initialize type 'S?' with a collection expression because the type is not constructible. // y = [2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[2]").WithArguments("S?").WithLocation(16, 13)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[2]").WithArguments("S?").WithLocation(16, 13)); } [Fact] @@ -5350,7 +5350,7 @@ Add C`1[System.Int32] """); } - // Ensure collection literal conversions are not standard implicit conversions + // Ensure collection expression conversions are not standard implicit conversions // and, as a result, are ignored when determining user-defined conversions. [Fact] public void UserDefinedConversions_01() @@ -5372,15 +5372,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (9,15): error CS9174: Cannot initialize type 'S' with a collection literal because the type is not constructible. + // (9,15): error CS9174: Cannot initialize type 'S' with a collection expression because the type is not constructible. // S s = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("S").WithLocation(9, 15), - // (10,13): error CS9174: Cannot initialize type 'S' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("S").WithLocation(9, 15), + // (10,13): error CS9174: Cannot initialize type 'S' with a collection expression because the type is not constructible. // s = [1, 2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1, 2]").WithArguments("S").WithLocation(10, 13), - // (11,13): error CS9174: Cannot initialize type 'S' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1, 2]").WithArguments("S").WithLocation(10, 13), + // (11,13): error CS9174: Cannot initialize type 'S' with a collection expression because the type is not constructible. // s = (S)([3, 4]); - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "(S)([3, 4])").WithArguments("S").WithLocation(11, 13)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "(S)([3, 4])").WithArguments("S").WithLocation(11, 13)); } [Fact] @@ -5403,15 +5403,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (9,15): error CS9174: Cannot initialize type 'S' with a collection literal because the type is not constructible. + // (9,15): error CS9174: Cannot initialize type 'S' with a collection expression because the type is not constructible. // S s = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("S").WithLocation(9, 15), - // (10,13): error CS9174: Cannot initialize type 'S' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("S").WithLocation(9, 15), + // (10,13): error CS9174: Cannot initialize type 'S' with a collection expression because the type is not constructible. // s = [1, 2]; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[1, 2]").WithArguments("S").WithLocation(10, 13), - // (11,13): error CS9174: Cannot initialize type 'S' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[1, 2]").WithArguments("S").WithLocation(10, 13), + // (11,13): error CS9174: Cannot initialize type 'S' with a collection expression because the type is not constructible. // s = (S)([3, 4]); - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "(S)([3, 4])").WithArguments("S").WithLocation(11, 13)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "(S)([3, 4])").WithArguments("S").WithLocation(11, 13)); } [Fact] @@ -5610,28 +5610,28 @@ static void Main() """; var comp = CreateCompilation(source, targetFramework: TargetFramework.Net70); comp.VerifyEmitDiagnostics( - // (20,17): error CS9174: Cannot initialize type 'S2' with a collection literal because the type is not constructible. + // (20,17): error CS9174: Cannot initialize type 'S2' with a collection expression because the type is not constructible. // S2 v6 = []; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("S2").WithLocation(20, 17), - // (26,19): error CS9174: Cannot initialize type 'S2' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("S2").WithLocation(20, 17), + // (26,19): error CS9174: Cannot initialize type 'S2' with a collection expression because the type is not constructible. // var v12 = (S2)([]); - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "(S2)([])").WithArguments("S2").WithLocation(26, 19)); + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "(S2)([])").WithArguments("S2").WithLocation(26, 19)); var tree = comp.SyntaxTrees[0]; var model = comp.GetSemanticModel(tree); var collections = tree.GetRoot().DescendantNodes().OfType().ToArray(); Assert.Equal(12, collections.Length); - VerifyTypes(model, collections[0], expectedType: null, expectedConvertedType: "System.Int32[]", ConversionKind.CollectionLiteral); - VerifyTypes(model, collections[1], expectedType: null, expectedConvertedType: "System.Collections.Generic.List", ConversionKind.CollectionLiteral); - VerifyTypes(model, collections[2], expectedType: null, expectedConvertedType: "System.Span", ConversionKind.CollectionLiteral); - VerifyTypes(model, collections[3], expectedType: null, expectedConvertedType: "System.ReadOnlySpan", ConversionKind.CollectionLiteral); - VerifyTypes(model, collections[4], expectedType: null, expectedConvertedType: "S1", ConversionKind.CollectionLiteral); + VerifyTypes(model, collections[0], expectedType: null, expectedConvertedType: "System.Int32[]", ConversionKind.CollectionExpression); + VerifyTypes(model, collections[1], expectedType: null, expectedConvertedType: "System.Collections.Generic.List", ConversionKind.CollectionExpression); + VerifyTypes(model, collections[2], expectedType: null, expectedConvertedType: "System.Span", ConversionKind.CollectionExpression); + VerifyTypes(model, collections[3], expectedType: null, expectedConvertedType: "System.ReadOnlySpan", ConversionKind.CollectionExpression); + VerifyTypes(model, collections[4], expectedType: null, expectedConvertedType: "S1", ConversionKind.CollectionExpression); VerifyTypes(model, collections[5], expectedType: null, expectedConvertedType: "S2", ConversionKind.NoConversion); - VerifyTypes(model, collections[6], expectedType: null, expectedConvertedType: "System.Int32[]", ConversionKind.CollectionLiteral); - VerifyTypes(model, collections[7], expectedType: null, expectedConvertedType: "System.Collections.Generic.List", ConversionKind.CollectionLiteral); - VerifyTypes(model, collections[8], expectedType: null, expectedConvertedType: "System.Span", ConversionKind.CollectionLiteral); - VerifyTypes(model, collections[9], expectedType: null, expectedConvertedType: "System.ReadOnlySpan", ConversionKind.CollectionLiteral); - VerifyTypes(model, collections[10], expectedType: null, expectedConvertedType: "S1", ConversionKind.CollectionLiteral); + VerifyTypes(model, collections[6], expectedType: null, expectedConvertedType: "System.Int32[]", ConversionKind.CollectionExpression); + VerifyTypes(model, collections[7], expectedType: null, expectedConvertedType: "System.Collections.Generic.List", ConversionKind.CollectionExpression); + VerifyTypes(model, collections[8], expectedType: null, expectedConvertedType: "System.Span", ConversionKind.CollectionExpression); + VerifyTypes(model, collections[9], expectedType: null, expectedConvertedType: "System.ReadOnlySpan", ConversionKind.CollectionExpression); + VerifyTypes(model, collections[10], expectedType: null, expectedConvertedType: "S1", ConversionKind.CollectionExpression); VerifyTypes(model, collections[11], expectedType: null, expectedConvertedType: "S2", ConversionKind.NoConversion); } @@ -5661,15 +5661,15 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (6,17): error CS9176: There is no target type for the collection literal. + // (6,17): error CS9176: There is no target type for the collection expression. // var x = [default(TypedReference)]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[default(TypedReference)]").WithLocation(6, 17), - // (7,17): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[default(TypedReference)]").WithLocation(6, 17), + // (7,17): error CS9176: There is no target type for the collection expression. // var y = [default(ArgIterator)]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[default(ArgIterator)]").WithLocation(7, 17), - // (8,17): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[default(ArgIterator)]").WithLocation(7, 17), + // (8,17): error CS9176: There is no target type for the collection expression. // var z = [default(RuntimeArgumentHandle)]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[default(RuntimeArgumentHandle)]").WithLocation(8, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[default(RuntimeArgumentHandle)]").WithLocation(8, 17)); } [Fact] @@ -5692,12 +5692,12 @@ static void Main() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (10,17): error CS9176: There is no target type for the collection literal. + // (10,17): error CS9176: There is no target type for the collection expression. // var x = [default(R)]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[default(R)]").WithLocation(10, 17), - // (11,17): error CS9176: There is no target type for the collection literal. + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[default(R)]").WithLocation(10, 17), + // (11,17): error CS9176: There is no target type for the collection expression. // var y = [new R(ref i)]; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[new R(ref i)]").WithLocation(11, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[new R(ref i)]").WithLocation(11, 17)); } [Fact] @@ -5784,15 +5784,15 @@ static Expression>> Create2() """; var comp = CreateCompilation(source); comp.VerifyEmitDiagnostics( - // (13,22): error CS9175: An expression tree may not contain a collection literal. + // (13,22): error CS9175: An expression tree may not contain a collection expression. // return () => []; - Diagnostic(ErrorCode.ERR_ExpressionTreeContainsCollectionLiteral, "[]").WithLocation(13, 22), - // (17,22): error CS9175: An expression tree may not contain a collection literal. + Diagnostic(ErrorCode.ERR_ExpressionTreeContainsCollectionExpression, "[]").WithLocation(13, 22), + // (17,22): error CS9175: An expression tree may not contain a collection expression. // return () => [1, 2]; - Diagnostic(ErrorCode.ERR_ExpressionTreeContainsCollectionLiteral, "[1, 2]").WithLocation(17, 22), - // (21,22): error CS9175: An expression tree may not contain a collection literal. + Diagnostic(ErrorCode.ERR_ExpressionTreeContainsCollectionExpression, "[1, 2]").WithLocation(17, 22), + // (21,22): error CS9175: An expression tree may not contain a collection expression. // return () => [a, b]; - Diagnostic(ErrorCode.ERR_ExpressionTreeContainsCollectionLiteral, "[a, b]").WithLocation(21, 22)); + Diagnostic(ErrorCode.ERR_ExpressionTreeContainsCollectionExpression, "[a, b]").WithLocation(21, 22)); } [Fact] @@ -5832,7 +5832,7 @@ static T[] Create(T a, T b) Next (Return) Block[B2] IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: T[], IsImplicit) (Syntax: '[a, b]') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) - (CollectionLiteral) + (CollectionExpression) Operand: IOperation: (OperationKind.None, Type: T[]) (Syntax: '[a, b]') Children(2): @@ -5882,7 +5882,7 @@ static Span Create(T a, T b) Next (Return) Block[B2] IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: System.Span, IsImplicit) (Syntax: '[a, b]') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) - (CollectionLiteral) + (CollectionExpression) Operand: IOperation: (OperationKind.None, Type: System.Span) (Syntax: '[a, b]') Children(2): @@ -5943,7 +5943,7 @@ static S Create(T a, T b) Next (Return) Block[B2] IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: S, IsImplicit) (Syntax: '[a, b]') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) - (CollectionLiteral) + (CollectionExpression) Operand: IOperation: (OperationKind.None, Type: S) (Syntax: '[a, b]') Children(2): @@ -6004,7 +6004,7 @@ class Program Next (Return) Block[B2] IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: T, IsImplicit) (Syntax: '[a, b]') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) - (CollectionLiteral) + (CollectionExpression) Operand: IOperation: (OperationKind.None, Type: T) (Syntax: '[a, b]') Children(2): @@ -6073,13 +6073,13 @@ static void Main() Right: IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: System.Collections.Generic.List>, IsImplicit) (Syntax: '[[Get(1)]]') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) - (CollectionLiteral) + (CollectionExpression) Operand: IOperation: (OperationKind.None, Type: System.Collections.Generic.List>) (Syntax: '[[Get(1)]]') Children(1): IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: System.Collections.Generic.List, IsImplicit) (Syntax: '[Get(1)]') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) - (CollectionLiteral) + (CollectionExpression) Operand: IOperation: (OperationKind.None, Type: System.Collections.Generic.List) (Syntax: '[Get(1)]') Children(1): @@ -6141,7 +6141,7 @@ static int[] Append(int[] a) Next (Return) Block[B2] IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: System.Int32[], IsImplicit) (Syntax: '[..a]') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) - (CollectionLiteral) + (CollectionExpression) Operand: IOperation: (OperationKind.None, Type: System.Int32[]) (Syntax: '[..a]') Children(1): @@ -6200,7 +6200,7 @@ static List Append(int[] a) Next (Return) Block[B2] IConversionOperation (TryCast: False, Unchecked) (OperationKind.Conversion, Type: System.Collections.Generic.List, IsImplicit) (Syntax: '[..a]') Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) - (CollectionLiteral) + (CollectionExpression) Operand: IOperation: (OperationKind.None, Type: System.Collections.Generic.List) (Syntax: '[..a]') Children(1): @@ -6317,9 +6317,9 @@ static void Main() } """; CreateCompilation(source).VerifyEmitDiagnostics( - // (7,17): error CS9503: There is no target type for the collection literal. + // (7,17): error CS9503: There is no target type for the collection expression. // var v = []->Count; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(7, 17)); + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(7, 17)); } [Fact] @@ -6380,9 +6380,9 @@ static void Main(List list) } """; CreateCompilationWithIndexAndRangeAndSpan(source).VerifyEmitDiagnostics( - // (7,9): error CS9500: Cannot initialize type 'Index' with a collection literal because the type is not constructible. + // (7,9): error CS9500: Cannot initialize type 'Index' with a collection expression because the type is not constructible. // []..; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[]").WithArguments("System.Index").WithLocation(7, 9), + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[]").WithArguments("System.Index").WithLocation(7, 9), // (7,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement // []..; Diagnostic(ErrorCode.ERR_IllegalStatement, "[]..").WithLocation(7, 9)); @@ -6403,9 +6403,9 @@ static void Main(List list) } """; CreateCompilation(source).VerifyEmitDiagnostics( - // (7,9): error CS9503: There is no target type for the collection literal. + // (7,9): error CS9503: There is no target type for the collection expression. // [] switch - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(7, 9), + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(7, 9), // (7,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement // [] switch Diagnostic(ErrorCode.ERR_IllegalStatement, "[] switch { null => 0 }").WithLocation(7, 9)); @@ -6426,9 +6426,9 @@ static void Main(List list) } """; CreateCompilation(source).VerifyEmitDiagnostics( - // (7,9): error CS9503: There is no target type for the collection literal. + // (7,9): error CS9503: There is no target type for the collection expression. // [] with { Count = 1, }; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(7, 9), + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(7, 9), // (7,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement // [] with { Count = 1, }; Diagnostic(ErrorCode.ERR_IllegalStatement, "[] with { Count = 1, }").WithLocation(7, 9)); @@ -6449,9 +6449,9 @@ static void Main(List list) } """; CreateCompilation(source).VerifyEmitDiagnostics( - // (7,9): error CS9503: There is no target type for the collection literal. + // (7,9): error CS9503: There is no target type for the collection expression. // [] is object; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(7, 9), + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(7, 9), // (7,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement // [] is object; Diagnostic(ErrorCode.ERR_IllegalStatement, "[] is object").WithLocation(7, 9)); @@ -6472,9 +6472,9 @@ static void Main(List list) } """; CreateCompilation(source).VerifyEmitDiagnostics( - // (7,9): error CS9503: There is no target type for the collection literal. + // (7,9): error CS9503: There is no target type for the collection expression. // [] as List; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[]").WithLocation(7, 9), + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[]").WithLocation(7, 9), // (7,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement // [] as List; Diagnostic(ErrorCode.ERR_IllegalStatement, "[] as List").WithLocation(7, 9)); diff --git a/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArrayElementReferenceExpression.cs b/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArrayElementReferenceExpression.cs index 283925bba23e6..163a86cbcdb64 100644 --- a/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArrayElementReferenceExpression.cs +++ b/src/Compilers/CSharp/Test/IOperation/IOperation/IOperationTests_IArrayElementReferenceExpression.cs @@ -525,9 +525,9 @@ public void F() "; var expectedDiagnostics = new DiagnosticDescription[] { - // (6,27): error CS9176: There is no target type for the collection literal. + // (6,27): error CS9176: There is no target type for the collection expression. // var a = /**/[0]/**/; - Diagnostic(ErrorCode.ERR_CollectionLiteralNoTargetType, "[0]").WithLocation(6, 27) + Diagnostic(ErrorCode.ERR_CollectionExpressionNoTargetType, "[0]").WithLocation(6, 27) }; VerifyOperationTreeAndDiagnosticsForTest(source, expectedOperationTree, expectedDiagnostics); diff --git a/src/Compilers/CSharp/Test/Syntax/IncrementalParsing/IncrementalParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/IncrementalParsing/IncrementalParsingTests.cs index 20a8d40fad54b..6673c199fa691 100644 --- a/src/Compilers/CSharp/Test/Syntax/IncrementalParsing/IncrementalParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/IncrementalParsing/IncrementalParsingTests.cs @@ -473,7 +473,7 @@ public void TestStatementToGlobalStatementChange() } [Fact] - public void TestAttributeToCollectionLiteral1() + public void TestAttributeToCollectionExpression1() { var source = @" using System; @@ -505,7 +505,7 @@ void M() } [Fact] - public void TestCollectionLiteralToAttribute1() + public void TestCollectionExpressionToAttribute1() { var source = @" using System; diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionLiteralParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionLiteralParsingTests.cs index a2969afb3d823..25df4bbd4eb59 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionLiteralParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionLiteralParsingTests.cs @@ -8,14 +8,14 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests; -public class CollectionLiteralParsingTests : ParsingTests +public class CollectionExpressionParsingTests : ParsingTests { - public CollectionLiteralParsingTests(ITestOutputHelper output) : base(output) { } + public CollectionExpressionParsingTests(ITestOutputHelper output) : base(output) { } [Theory] [InlineData(LanguageVersion.CSharp11)] [InlineData(LanguageVersion.Preview)] - public void CollectionLiteralParsingDoesNotProduceLangVersionError(LanguageVersion languageVersion) + public void CollectionExpressionParsingDoesNotProduceLangVersionError(LanguageVersion languageVersion) { UsingExpression("[A, B]", TestOptions.Regular.WithLanguageVersion(languageVersion)); @@ -5360,7 +5360,7 @@ public void CastVersusIndexAmbiguity24_C() public void CastVersusIndexAmbiguity24_D() { // No errors here syntactically. But user will likely get one semantically. Specifically, this - // could look like a case of a collection literal with a spread element in it, or as indexing into a + // could look like a case of a collection expression with a spread element in it, or as indexing into a // parenthesized expression with a range expression. // // We may want a dedicated error to tell them to parenthesize the brackets if they're trying to cast this as a list. @@ -5698,7 +5698,7 @@ public void SpreadOfQuery() } [Fact] - public void InvokedCollectionLiteral1() + public void InvokedCollectionExpression1() { UsingExpression("[A, B]()"); @@ -5734,7 +5734,7 @@ public void InvokedCollectionLiteral1() } [Fact] - public void InvokedCollectionLiteral2() + public void InvokedCollectionExpression2() { UsingExpression("++[A, B]()"); diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/StatementAttributeParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/StatementAttributeParsingTests.cs index 15b49186b4855..961e4e7bdb363 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/StatementAttributeParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/StatementAttributeParsingTests.cs @@ -5593,9 +5593,9 @@ void Goo(int i) EOF(); CreateCompilation(test).GetDiagnostics().Verify( - // (5,9): error CS8652: The feature 'collection literals' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. + // (5,9): error CS8652: The feature 'collection expressions' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. // [A]++i; - Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection literals").WithLocation(5, 9), + Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection expressions").WithLocation(5, 9), // (5,10): error CS0103: The name 'A' does not exist in the current context // [A]++i; Diagnostic(ErrorCode.ERR_NameNotInContext, "A").WithArguments("A").WithLocation(5, 10), @@ -6015,12 +6015,12 @@ void Goo(int a, int b) EOF(); CreateCompilationWithIndexAndRangeAndSpan(test).VerifyDiagnostics( - // (6,9): error CS8652: The feature 'collection literals' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. + // (6,9): error CS8652: The feature 'collection expressions' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. // [A]..b; - Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection literals").WithLocation(6, 9), - // (6,9): error CS9500: Cannot initialize type 'Index' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection expressions").WithLocation(6, 9), + // (6,9): error CS9500: Cannot initialize type 'Index' with a collection expression because the type is not constructible. // [A]..b; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[A]").WithArguments("System.Index").WithLocation(6, 9), + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[A]").WithArguments("System.Index").WithLocation(6, 9), // (6,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement // [A]..b; Diagnostic(ErrorCode.ERR_IllegalStatement, "[A]..b").WithLocation(6, 9), @@ -6110,12 +6110,12 @@ void Goo(int a, int b) EOF(); CreateCompilationWithIndexAndRangeAndSpan(test).VerifyDiagnostics( - // (6,9): error CS8652: The feature 'collection literals' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. + // (6,9): error CS8652: The feature 'collection expressions' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version. // [A]..; - Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection literals").WithLocation(6, 9), - // (6,9): error CS9500: Cannot initialize type 'Index' with a collection literal because the type is not constructible. + Diagnostic(ErrorCode.ERR_FeatureInPreview, "[").WithArguments("collection expressions").WithLocation(6, 9), + // (6,9): error CS9500: Cannot initialize type 'Index' with a collection expression because the type is not constructible. // [A]..; - Diagnostic(ErrorCode.ERR_CollectionLiteralTargetTypeNotConstructible, "[A]").WithArguments("System.Index").WithLocation(6, 9), + Diagnostic(ErrorCode.ERR_CollectionExpressionTargetTypeNotConstructible, "[A]").WithArguments("System.Index").WithLocation(6, 9), // (6,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement // [A]..; Diagnostic(ErrorCode.ERR_IllegalStatement, "[A]..").WithLocation(6, 9), diff --git a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs index a87476a25ffae..c0711645cc879 100644 --- a/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs +++ b/src/EditorFeatures/CSharpTest/Formatting/FormattingEngineTests.cs @@ -2585,7 +2585,7 @@ class C } [WpfFact] - public void FormatCollectionLiteralAfterEquals() + public void FormatCollectionExpressionAfterEquals() { var code = @"$$ var v = [ 1 , 2 , 3 ] ;";