-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-CompilersConcept-APIThis issue involves adding, removing, clarification, or modification of an API.This issue involves adding, removing, clarification, or modification of an API.Feature - Collection ExpressionsFeature Requestapi-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementation
Milestone
Description
Background and Motivation
Span<int> numbers = [1, 2, 3]; // expression elements
int[] more = [..numbers, 4, 5]; // spread elementProposed API
Syntax
namespace Microsoft.CodeAnalysis.CSharp
{
public enum SyntaxKind : ushort
{
+ CollectionExpression = 9076,
+ ExpressionElement = 9077,
+ SpreadElement = 9078,
}
public static class SyntaxFactory
{
+ public static CollectionExpressionSyntax CollectionExpression(
+ SyntaxToken openBracketToken,
+ SeparatedSyntaxList<CollectionElementSyntax> elements,
+ SyntaxToken closeBracketToken);
+ public static CollectionExpressionSyntax CollectionExpression(
+ SeparatedSyntaxList<CollectionElementSyntax> elements = default);
+ public static ExpressionElementSyntax ExpressionElement(
+ ExpressionSyntax expression);
+ public static SpreadElementSyntax SpreadElement(
+ SyntaxToken operatorToken,
+ ExpressionSyntax expression);
+ public static SpreadElementSyntax SpreadElement(
+ ExpressionSyntax expression);
}
}
namespace Microsoft.CodeAnalysis.CSharp.Syntax
{
+ public sealed class CollectionExpressionSyntax : ExpressionSyntax
+ {
+ public SyntaxToken OpenBracketToken { get; }
+ public SeparatedSyntaxList<CollectionElementSyntax> Elements { get; }
+ public SyntaxToken CloseBracketToken { get; }
+ public CollectionExpressionSyntax Update(
+ SyntaxToken openBracketToken,
+ SeparatedSyntaxList<CollectionElementSyntax> elements,
+ SyntaxToken closeBracketToken);
+ public CollectionExpressionSyntax WithOpenBracketToken(
+ SyntaxToken openBracketToken);
+ public CollectionExpressionSyntax WithElements(
+ SeparatedSyntaxList<CollectionElementSyntax> elements);
+ public CollectionExpressionSyntax WithCloseBracketToken(
+ SyntaxToken closeBracketToken);
+ public CollectionExpressionSyntax AddElements(
+ params CollectionElementSyntax[] items);
+ }
+ public abstract class CollectionElementSyntax : CSharpSyntaxNode
+ {
+ }
+ public sealed class ExpressionElementSyntax : CollectionElementSyntax
+ {
+ public ExpressionSyntax Expression { get; }
+ public ExpressionElementSyntax Update(
+ ExpressionSyntax expression);
+ public ExpressionElementSyntax WithExpression(
+ ExpressionSyntax expression);
+ }
+ public sealed class SpreadElementSyntax : CollectionElementSyntax
+ {
+ public SyntaxToken OperatorToken { get; }
+ public ExpressionSyntax Expression { get; }
+ public SpreadElementSyntax Update(
+ SyntaxToken operatorToken,
+ ExpressionSyntax expression);
+ public SpreadElementSyntax WithOperatorToken(
+ SyntaxToken operatorToken);
+ public SpreadElementSyntax WithExpression(
+ ExpressionSyntax expression);
+ }
}Conversions
Conversions moved to #70631.
~~namespace Microsoft.CodeAnalysis.CSharp~~
{
public readonly struct Conversion
{
+ public bool IsCollectionLiteral { get; }
}
}IOperation
IOperation moved to #70631.
namespace Microsoft.CodeAnalysis.Operations
{
+ /// <summary>
+ /// Represents a collection literal.
+ /// <para>
+ /// Current usage:
+ /// (1) C# collection literal expression.
+ /// </para>
+ /// </summary>
+ public interface ICollectionLiteralOperation : IOperation
+ {
+ /// <summary>
+ /// Method to construct the collection instance.
+ /// </summary>
+ IMethodSymbol? ConstructMethod { get; }
+ /// <summary>
+ /// Collection literal elements.
+ /// </summary>
+ ImmutableArray<IOperation> Elements { get; }
+ }
+ /// <summary>
+ /// Represents a collection literal spread element.
+ /// <para>
+ /// Current usage:
+ /// (1) C# spread element.
+ /// </para>
+ /// </summary>
+ public interface ISpreadOperation : IOperation
+ {
+ /// <summary>
+ /// Collection value being spread.
+ /// </summary>
+ IOperation Collection { get; }
+ }
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-CompilersConcept-APIThis issue involves adding, removing, clarification, or modification of an API.This issue involves adding, removing, clarification, or modification of an API.Feature - Collection ExpressionsFeature Requestapi-needs-workAPI needs work before it is approved, it is NOT ready for implementationAPI needs work before it is approved, it is NOT ready for implementation