diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs index 6763a986a7f4..610ce71faa5b 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs @@ -5199,6 +5199,16 @@ private BoundExpression BindCollectionExpression(CollectionExpressionSyntax synt MessageID.IDS_FeatureCollectionExpressions.CheckFeatureAvailability(diagnostics, syntax, syntax.OpenBracketToken.GetLocation()); + for (int i = 1, n = syntax.Elements.Count - 1; i < n; i++) + { + var element = syntax.Elements[i]; + if (element is WithElementSyntax withElement) + { + Error(diagnostics, ErrorCode.ERR_WithElementMustBeFirst, withElement.WithKeyword.GetLocation()); + break; + } + } + foreach (var element in syntax.Elements) { if (element is KeyValuePairElementSyntax keyValuePairElement) @@ -5209,6 +5219,14 @@ private BoundExpression BindCollectionExpression(CollectionExpressionSyntax synt Error(diagnostics, ErrorCode.ERR_SyntaxError, keyValuePairElement.ColonToken, ","); return new BoundBadExpression(syntax, LookupResultKind.Empty, symbols: [], childBoundNodes: [], CreateErrorType()); } + else if (element is WithElementSyntax withElement) + { + MessageID.IDS_FeatureCollectionExpressionConstructionArguments.CheckFeatureAvailability(diagnostics, syntax, withElement.WithKeyword.GetLocation()); + + // PROTOTYPE: Error for now. Flesh this out when we do the binding for `with(...)` arguments. + Error(diagnostics, ErrorCode.ERR_SyntaxError, withElement.WithKeyword, ","); + return new BoundBadExpression(syntax, LookupResultKind.Empty, symbols: [], childBoundNodes: [], CreateErrorType()); + } } var builder = ArrayBuilder.GetInstance(syntax.Elements.Count); diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 8510e0649b1e..25ff7c5d2b87 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6832,6 +6832,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ dictionary expressions + + collection expression construction arguments + Cannot initialize type '{0}' with a collection expression because the type is not constructible. @@ -8020,4 +8023,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Element type of an iterator may not be a ref struct or a type parameter allowing ref structs + + 'with(...)' element must be first element in collection expression + diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 90e45ee89de3..764ee8066f20 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -2350,6 +2350,7 @@ internal enum ErrorCode WRN_AccessorDoesNotUseBackingField = 9266, ERR_IteratorRefLikeElementType = 9267, + ERR_WithElementMustBeFirst = 9268, // Note: you will need to do the following after adding errors: // 1) Update ErrorFacts.IsBuildOnlyDiagnostic (src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs) diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs index b3c03386122f..d2a6f0230d5b 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs @@ -2467,6 +2467,7 @@ or ErrorCode.WRN_UninitializedNonNullableBackingField or ErrorCode.WRN_UnassignedInternalRefField or ErrorCode.WRN_AccessorDoesNotUseBackingField or ErrorCode.ERR_IteratorRefLikeElementType + or ErrorCode.ERR_WithElementMustBeFirst => false, }; #pragma warning restore CS8524 // The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs index 3b536795db22..dacda977fe38 100644 --- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs +++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs @@ -295,6 +295,7 @@ internal enum MessageID IDS_FeatureFirstClassSpan = MessageBase + 12849, IDS_FeatureDictionaryExpressions = MessageBase + 12850, + IDS_FeatureCollectionExpressionConstructionArguments = MessageBase + 12851, } // Message IDs may refer to strings that need to be localized. diff --git a/src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4 b/src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4 index dcd40a3b913a..671ab82c5a5f 100644 --- a/src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4 +++ b/src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4 @@ -859,6 +859,7 @@ collection_element : expression_element | key_value_pair_element | spread_element + | with_element ; expression_element @@ -873,6 +874,10 @@ spread_element : '..' expression ; +with_element + : 'with' argument_list + ; + conditional_access_expression : expression '?' expression ; diff --git a/src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Internal.Generated.cs b/src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Internal.Generated.cs index b69efaceb148..337fc8999f5e 100644 --- a/src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Internal.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Internal.Generated.cs @@ -6767,6 +6767,82 @@ internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations) => new KeyValuePairElementSyntax(this.Kind, this.keyExpression, this.colonToken, this.valueExpression, GetDiagnostics(), annotations); } +internal sealed partial class WithElementSyntax : CollectionElementSyntax +{ + internal readonly SyntaxToken withKeyword; + internal readonly ArgumentListSyntax argumentList; + + internal WithElementSyntax(SyntaxKind kind, SyntaxToken withKeyword, ArgumentListSyntax argumentList, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations) + : base(kind, diagnostics, annotations) + { + this.SlotCount = 2; + this.AdjustFlagsAndWidth(withKeyword); + this.withKeyword = withKeyword; + this.AdjustFlagsAndWidth(argumentList); + this.argumentList = argumentList; + } + + internal WithElementSyntax(SyntaxKind kind, SyntaxToken withKeyword, ArgumentListSyntax argumentList, SyntaxFactoryContext context) + : base(kind) + { + this.SetFactoryContext(context); + this.SlotCount = 2; + this.AdjustFlagsAndWidth(withKeyword); + this.withKeyword = withKeyword; + this.AdjustFlagsAndWidth(argumentList); + this.argumentList = argumentList; + } + + internal WithElementSyntax(SyntaxKind kind, SyntaxToken withKeyword, ArgumentListSyntax argumentList) + : base(kind) + { + this.SlotCount = 2; + this.AdjustFlagsAndWidth(withKeyword); + this.withKeyword = withKeyword; + this.AdjustFlagsAndWidth(argumentList); + this.argumentList = argumentList; + } + + public SyntaxToken WithKeyword => this.withKeyword; + public ArgumentListSyntax ArgumentList => this.argumentList; + + internal override GreenNode? GetSlot(int index) + => index switch + { + 0 => this.withKeyword, + 1 => this.argumentList, + _ => null, + }; + + internal override SyntaxNode CreateRed(SyntaxNode? parent, int position) => new CSharp.Syntax.WithElementSyntax(this, parent, position); + + public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitWithElement(this); + public override TResult Accept(CSharpSyntaxVisitor visitor) => visitor.VisitWithElement(this); + + public WithElementSyntax Update(SyntaxToken withKeyword, ArgumentListSyntax argumentList) + { + if (withKeyword != this.WithKeyword || argumentList != this.ArgumentList) + { + var newNode = SyntaxFactory.WithElement(withKeyword, argumentList); + var diags = GetDiagnostics(); + if (diags?.Length > 0) + newNode = newNode.WithDiagnosticsGreen(diags); + var annotations = GetAnnotations(); + if (annotations?.Length > 0) + newNode = newNode.WithAnnotationsGreen(annotations); + return newNode; + } + + return this; + } + + internal override GreenNode SetDiagnostics(DiagnosticInfo[]? diagnostics) + => new WithElementSyntax(this.Kind, this.withKeyword, this.argumentList, diagnostics, GetAnnotations()); + + internal override GreenNode SetAnnotations(SyntaxAnnotation[]? annotations) + => new WithElementSyntax(this.Kind, this.withKeyword, this.argumentList, GetDiagnostics(), annotations); +} + internal abstract partial class QueryClauseSyntax : CSharpSyntaxNode { internal QueryClauseSyntax(SyntaxKind kind, DiagnosticInfo[]? diagnostics, SyntaxAnnotation[]? annotations) @@ -26641,6 +26717,7 @@ internal partial class CSharpSyntaxVisitor public virtual TResult VisitExpressionElement(ExpressionElementSyntax node) => this.DefaultVisit(node); public virtual TResult VisitSpreadElement(SpreadElementSyntax node) => this.DefaultVisit(node); public virtual TResult VisitKeyValuePairElement(KeyValuePairElementSyntax node) => this.DefaultVisit(node); + public virtual TResult VisitWithElement(WithElementSyntax node) => this.DefaultVisit(node); public virtual TResult VisitQueryExpression(QueryExpressionSyntax node) => this.DefaultVisit(node); public virtual TResult VisitQueryBody(QueryBodySyntax node) => this.DefaultVisit(node); public virtual TResult VisitFromClause(FromClauseSyntax node) => this.DefaultVisit(node); @@ -26890,6 +26967,7 @@ internal partial class CSharpSyntaxVisitor public virtual void VisitExpressionElement(ExpressionElementSyntax node) => this.DefaultVisit(node); public virtual void VisitSpreadElement(SpreadElementSyntax node) => this.DefaultVisit(node); public virtual void VisitKeyValuePairElement(KeyValuePairElementSyntax node) => this.DefaultVisit(node); + public virtual void VisitWithElement(WithElementSyntax node) => this.DefaultVisit(node); public virtual void VisitQueryExpression(QueryExpressionSyntax node) => this.DefaultVisit(node); public virtual void VisitQueryBody(QueryBodySyntax node) => this.DefaultVisit(node); public virtual void VisitFromClause(FromClauseSyntax node) => this.DefaultVisit(node); @@ -27283,6 +27361,9 @@ public override CSharpSyntaxNode VisitSpreadElement(SpreadElementSyntax node) public override CSharpSyntaxNode VisitKeyValuePairElement(KeyValuePairElementSyntax node) => node.Update((ExpressionSyntax)Visit(node.KeyExpression), (SyntaxToken)Visit(node.ColonToken), (ExpressionSyntax)Visit(node.ValueExpression)); + public override CSharpSyntaxNode VisitWithElement(WithElementSyntax node) + => node.Update((SyntaxToken)Visit(node.WithKeyword), (ArgumentListSyntax)Visit(node.ArgumentList)); + public override CSharpSyntaxNode VisitQueryExpression(QueryExpressionSyntax node) => node.Update((FromClauseSyntax)Visit(node.FromClause), (QueryBodySyntax)Visit(node.Body)); @@ -29435,6 +29516,27 @@ public KeyValuePairElementSyntax KeyValuePairElement(ExpressionSyntax keyExpress return result; } + public WithElementSyntax WithElement(SyntaxToken withKeyword, ArgumentListSyntax argumentList) + { +#if DEBUG + if (withKeyword == null) throw new ArgumentNullException(nameof(withKeyword)); + if (withKeyword.Kind != SyntaxKind.WithKeyword) throw new ArgumentException(nameof(withKeyword)); + if (argumentList == null) throw new ArgumentNullException(nameof(argumentList)); +#endif + + int hash; + var cached = CSharpSyntaxNodeCache.TryGetNode((int)SyntaxKind.WithElement, withKeyword, argumentList, this.context, out hash); + if (cached != null) return (WithElementSyntax)cached; + + var result = new WithElementSyntax(SyntaxKind.WithElement, withKeyword, argumentList, this.context); + if (hash >= 0) + { + SyntaxNodeCache.AddNode(result, hash); + } + + return result; + } + public QueryExpressionSyntax QueryExpression(FromClauseSyntax fromClause, QueryBodySyntax body) { #if DEBUG @@ -34725,6 +34827,27 @@ public static KeyValuePairElementSyntax KeyValuePairElement(ExpressionSyntax key return result; } + public static WithElementSyntax WithElement(SyntaxToken withKeyword, ArgumentListSyntax argumentList) + { +#if DEBUG + if (withKeyword == null) throw new ArgumentNullException(nameof(withKeyword)); + if (withKeyword.Kind != SyntaxKind.WithKeyword) throw new ArgumentException(nameof(withKeyword)); + if (argumentList == null) throw new ArgumentNullException(nameof(argumentList)); +#endif + + int hash; + var cached = SyntaxNodeCache.TryGetNode((int)SyntaxKind.WithElement, withKeyword, argumentList, out hash); + if (cached != null) return (WithElementSyntax)cached; + + var result = new WithElementSyntax(SyntaxKind.WithElement, withKeyword, argumentList); + if (hash >= 0) + { + SyntaxNodeCache.AddNode(result, hash); + } + + return result; + } + public static QueryExpressionSyntax QueryExpression(FromClauseSyntax fromClause, QueryBodySyntax body) { #if DEBUG diff --git a/src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Main.Generated.cs b/src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Main.Generated.cs index 91a886b58c86..808ae9f5d36a 100644 --- a/src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Main.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Main.Generated.cs @@ -231,6 +231,9 @@ public partial class CSharpSyntaxVisitor /// Called when the visitor visits a KeyValuePairElementSyntax node. public virtual TResult? VisitKeyValuePairElement(KeyValuePairElementSyntax node) => this.DefaultVisit(node); + /// Called when the visitor visits a WithElementSyntax node. + public virtual TResult? VisitWithElement(WithElementSyntax node) => this.DefaultVisit(node); + /// Called when the visitor visits a QueryExpressionSyntax node. public virtual TResult? VisitQueryExpression(QueryExpressionSyntax node) => this.DefaultVisit(node); @@ -969,6 +972,9 @@ public partial class CSharpSyntaxVisitor /// Called when the visitor visits a KeyValuePairElementSyntax node. public virtual void VisitKeyValuePairElement(KeyValuePairElementSyntax node) => this.DefaultVisit(node); + /// Called when the visitor visits a WithElementSyntax node. + public virtual void VisitWithElement(WithElementSyntax node) => this.DefaultVisit(node); + /// Called when the visitor visits a QueryExpressionSyntax node. public virtual void VisitQueryExpression(QueryExpressionSyntax node) => this.DefaultVisit(node); @@ -1707,6 +1713,9 @@ public partial class CSharpSyntaxRewriter : CSharpSyntaxVisitor public override SyntaxNode? VisitKeyValuePairElement(KeyValuePairElementSyntax node) => node.Update((ExpressionSyntax?)Visit(node.KeyExpression) ?? throw new ArgumentNullException("keyExpression"), VisitToken(node.ColonToken), (ExpressionSyntax?)Visit(node.ValueExpression) ?? throw new ArgumentNullException("valueExpression")); + public override SyntaxNode? VisitWithElement(WithElementSyntax node) + => node.Update(VisitToken(node.WithKeyword), (ArgumentListSyntax?)Visit(node.ArgumentList) ?? throw new ArgumentNullException("argumentList")); + public override SyntaxNode? VisitQueryExpression(QueryExpressionSyntax node) => node.Update((FromClauseSyntax?)Visit(node.FromClause) ?? throw new ArgumentNullException("fromClause"), (QueryBodySyntax?)Visit(node.Body) ?? throw new ArgumentNullException("body")); @@ -3439,6 +3448,18 @@ public static KeyValuePairElementSyntax KeyValuePairElement(ExpressionSyntax key public static KeyValuePairElementSyntax KeyValuePairElement(ExpressionSyntax keyExpression, ExpressionSyntax valueExpression) => SyntaxFactory.KeyValuePairElement(keyExpression, SyntaxFactory.Token(SyntaxKind.ColonToken), valueExpression); + /// Creates a new WithElementSyntax instance. + public static WithElementSyntax WithElement(SyntaxToken withKeyword, ArgumentListSyntax argumentList) + { + if (withKeyword.Kind() != SyntaxKind.WithKeyword) throw new ArgumentException(nameof(withKeyword)); + if (argumentList == null) throw new ArgumentNullException(nameof(argumentList)); + return (WithElementSyntax)Syntax.InternalSyntax.SyntaxFactory.WithElement((Syntax.InternalSyntax.SyntaxToken)withKeyword.Node!, (Syntax.InternalSyntax.ArgumentListSyntax)argumentList.Green).CreateRed(); + } + + /// Creates a new WithElementSyntax instance. + public static WithElementSyntax WithElement(ArgumentListSyntax? argumentList = default) + => SyntaxFactory.WithElement(SyntaxFactory.Token(SyntaxKind.WithKeyword), argumentList ?? SyntaxFactory.ArgumentList()); + /// Creates a new QueryExpressionSyntax instance. public static QueryExpressionSyntax QueryExpression(FromClauseSyntax fromClause, QueryBodySyntax body) { diff --git a/src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Syntax.Generated.cs b/src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Syntax.Generated.cs index de1ebb8c2c68..9e52a07a6242 100644 --- a/src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Syntax.Generated.cs +++ b/src/Compilers/CSharp/Portable/Generated/CSharpSyntaxGenerator/CSharpSyntaxGenerator.SourceGenerator/Syntax.xml.Syntax.Generated.cs @@ -4331,6 +4331,50 @@ public KeyValuePairElementSyntax Update(ExpressionSyntax keyExpression, SyntaxTo public KeyValuePairElementSyntax WithValueExpression(ExpressionSyntax valueExpression) => Update(this.KeyExpression, this.ColonToken, valueExpression); } +/// +/// This node is associated with the following syntax kinds: +/// +/// +/// +/// +public sealed partial class WithElementSyntax : CollectionElementSyntax +{ + private ArgumentListSyntax? argumentList; + + internal WithElementSyntax(InternalSyntax.CSharpSyntaxNode green, SyntaxNode? parent, int position) + : base(green, parent, position) + { + } + + public SyntaxToken WithKeyword => new SyntaxToken(this, ((InternalSyntax.WithElementSyntax)this.Green).withKeyword, Position, 0); + + public ArgumentListSyntax ArgumentList => GetRed(ref this.argumentList, 1)!; + + internal override SyntaxNode? GetNodeSlot(int index) => index == 1 ? GetRed(ref this.argumentList, 1)! : null; + + internal override SyntaxNode? GetCachedSlot(int index) => index == 1 ? this.argumentList : null; + + public override void Accept(CSharpSyntaxVisitor visitor) => visitor.VisitWithElement(this); + public override TResult? Accept(CSharpSyntaxVisitor visitor) where TResult : default => visitor.VisitWithElement(this); + + public WithElementSyntax Update(SyntaxToken withKeyword, ArgumentListSyntax argumentList) + { + if (withKeyword != this.WithKeyword || argumentList != this.ArgumentList) + { + var newNode = SyntaxFactory.WithElement(withKeyword, argumentList); + var annotations = GetAnnotations(); + return annotations?.Length > 0 ? newNode.WithAnnotations(annotations) : newNode; + } + + return this; + } + + public WithElementSyntax WithWithKeyword(SyntaxToken withKeyword) => Update(withKeyword, this.ArgumentList); + public WithElementSyntax WithArgumentList(ArgumentListSyntax argumentList) => Update(this.WithKeyword, argumentList); + + public WithElementSyntax AddArgumentListArguments(params ArgumentSyntax[] items) => WithArgumentList(this.ArgumentList.WithArguments(this.ArgumentList.Arguments.AddRange(items))); +} + public abstract partial class QueryClauseSyntax : CSharpSyntaxNode { internal QueryClauseSyntax(InternalSyntax.CSharpSyntaxNode green, SyntaxNode? parent, int position) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index 764aff091e8c..710bfdee0aa8 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -12718,6 +12718,9 @@ private bool IsPossibleCollectionElement() private CollectionElementSyntax ParseCollectionElement() { + if (this.CurrentToken.ContextualKind == SyntaxKind.WithKeyword && this.PeekToken(1).Kind == SyntaxKind.OpenParenToken) + return _syntaxFactory.WithElement(this.EatContextualToken(SyntaxKind.WithKeyword), this.ParseParenthesizedArgumentList()); + if (this.IsAtDotDotToken()) return _syntaxFactory.SpreadElement(this.EatDotDotToken(), this.ParseExpressionCore()); @@ -12727,10 +12730,9 @@ private CollectionElementSyntax ParseCollectionElement() : this.ParseExpressionCore(); var colonToken = this.TryEatToken(SyntaxKind.ColonToken); - if (colonToken != null) - return _syntaxFactory.KeyValuePairElement(expression, colonToken, this.ParseExpressionCore()); - - return _syntaxFactory.ExpressionElement(expression); + return colonToken != null + ? _syntaxFactory.KeyValuePairElement(expression, colonToken, this.ParseExpressionCore()) + : _syntaxFactory.ExpressionElement(expression); } private bool IsAnonymousType() diff --git a/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt b/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt index 30787971f37f..34ac40d5b9be 100644 --- a/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt @@ -8,14 +8,29 @@ Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax.ValueExpression.g Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax.WithColonToken(Microsoft.CodeAnalysis.SyntaxToken colonToken) -> Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax! Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax.WithKeyExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax! keyExpression) -> Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax! Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax.WithValueExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax! valueExpression) -> Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax! +Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.AddArgumentListArguments(params Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax![]! items) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! +Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.ArgumentList.get -> Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax! +Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.Update(Microsoft.CodeAnalysis.SyntaxToken withKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax! argumentList) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! +Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.WithArgumentList(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax! argumentList) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! +Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.WithKeyword.get -> Microsoft.CodeAnalysis.SyntaxToken +Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.WithWithKeyword(Microsoft.CodeAnalysis.SyntaxToken withKeyword) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! Microsoft.CodeAnalysis.CSharp.SyntaxKind.KeyValuePairElement = 9079 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind +Microsoft.CodeAnalysis.CSharp.SyntaxKind.WithElement = 9080 -> Microsoft.CodeAnalysis.CSharp.SyntaxKind override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitKeyValuePairElement(Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax! node) -> Microsoft.CodeAnalysis.SyntaxNode? +override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxRewriter.VisitWithElement(Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! node) -> Microsoft.CodeAnalysis.SyntaxNode? override Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax.Accept(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor! visitor) -> void override Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax.Accept(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor! visitor) -> TResult? +override Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.Accept(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor! visitor) -> void +override Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax.Accept(Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor! visitor) -> TResult? static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.KeyValuePairElement(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax! keyExpression, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax! valueExpression) -> Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax! static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.KeyValuePairElement(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax! keyExpression, Microsoft.CodeAnalysis.SyntaxToken colonToken, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax! valueExpression) -> Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax! +static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.WithElement(Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax? argumentList = null) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! +static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.WithElement(Microsoft.CodeAnalysis.SyntaxToken withKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentListSyntax! argumentList) -> Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitKeyValuePairElement(Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax! node) -> void +virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitWithElement(Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! node) -> void virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitKeyValuePairElement(Microsoft.CodeAnalysis.CSharp.Syntax.KeyValuePairElementSyntax! node) -> TResult? +virtual Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor.VisitWithElement(Microsoft.CodeAnalysis.CSharp.Syntax.WithElementSyntax! node) -> TResult? [RSEXPERIMENTAL002]Microsoft.CodeAnalysis.CSharp.InterceptableLocation [RSEXPERIMENTAL002]abstract Microsoft.CodeAnalysis.CSharp.InterceptableLocation.Data.get -> string! [RSEXPERIMENTAL002]abstract Microsoft.CodeAnalysis.CSharp.InterceptableLocation.GetDisplayLocation() -> string! diff --git a/src/Compilers/CSharp/Portable/Syntax/Syntax.xml b/src/Compilers/CSharp/Portable/Syntax/Syntax.xml index 98e67b9ff36a..7bb0a28ea22b 100644 --- a/src/Compilers/CSharp/Portable/Syntax/Syntax.xml +++ b/src/Compilers/CSharp/Portable/Syntax/Syntax.xml @@ -1847,6 +1847,13 @@ + + + + + + + diff --git a/src/Compilers/CSharp/Portable/Syntax/SyntaxKind.cs b/src/Compilers/CSharp/Portable/Syntax/SyntaxKind.cs index 4d767bf0b2f8..206cfc4ad2d8 100644 --- a/src/Compilers/CSharp/Portable/Syntax/SyntaxKind.cs +++ b/src/Compilers/CSharp/Portable/Syntax/SyntaxKind.cs @@ -926,5 +926,6 @@ public enum SyntaxKind : ushort ExpressionElement = 9077, SpreadElement = 9078, KeyValuePairElement = 9079, + WithElement = 9080, } } diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 66de5f6cd796..5a192d5ba242 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -2342,6 +2342,11 @@ Objekt this nelze použít před přiřazením všech jeho polí. Zvažte aktualizaci na jazykovou verzi {0} na automatické výchozí nastavení nepřiřazených polí. + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Očekával se obecný návratový typ podobný úloze, ale typ {0} nalezený v atributu AsyncMethodBuilder nebyl vhodný. Musí se jednat o nevázaný obecný typ arity a jeho nadřazený typ (pokud existuje) nesmí být obecný. @@ -2382,6 +2387,11 @@ zaškrtnuté uživatelem definované operátory + + collection expression construction arguments + collection expression construction arguments + + collection expressions výrazy kolekce diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 03195bd79f75..837bc252f2ad 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -2342,6 +2342,11 @@ Das „this“-Objekt kann nicht verwendet werden, bevor alle zugehörigen Felder zugewiesen wurden. Aktualisieren Sie ggf. auf die Sprachversion „{0}“, um die nicht zugewiesenen Felder automatisch als Standard zu verwenden. + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Ein generischer aufgabenähnlicher Rückgabetyp wurde erwartet, aber der Typ „{0}“, der im Attribut „AsyncMethodBuilder“ gefunden wurde, war nicht geeignet. Es muss sich um einen ungebundenen generischen Typ von Stelligkeit Eins handelt, und der enthaltende Typ (falls vorhanden) muss nicht generisch sein. @@ -2382,6 +2387,11 @@ Überprüfte benutzerdefinierte Operatoren + + collection expression construction arguments + collection expression construction arguments + + collection expressions Sammlungsausdrücke diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 4e3651e1e950..2c5f42d06709 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -2342,6 +2342,11 @@ No se puede usar el objeto 'this' antes de que se hayan asignado todos sus campos. Considere la posibilidad de actualizar a la versión de idioma "{0}" para establecer automáticamente el valor predeterminado de los campos sin asignar. + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Se esperaba un tipo de valor devuelto genérico similar a una tarea, pero el tipo "{0}" encontrado en el atributo "AsyncMethodBuilder" no era adecuado. Debe ser un tipo genérico independiente de aridad uno y su tipo contenedor (si existe) debe ser no genérico. @@ -2382,6 +2387,11 @@ operadores definidos por el usuario comprobados + + collection expression construction arguments + collection expression construction arguments + + collection expressions expresiones de colección diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index ac4284b1f446..d9d721272e3d 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -2342,6 +2342,11 @@ Impossible d’utiliser l’objet 'this' avant l’affectation de tous ses champs. Envisagez de mettre à jour vers la version de langage '{0}' pour définir automatiquement les champs non attribués par défaut. + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Un type de retour de type tâche générique est attendu, mais le type « {0} » trouvé dans l’attribut ’AsyncMethodBuilder’ n’était pas approprié. Il doit s’agir d’un type générique indépendant d’arité One, et son type conteneur (le cas échéant) doit être non générique. @@ -2382,6 +2387,11 @@ opérateurs définis par l’utilisateur vérifiés + + collection expression construction arguments + collection expression construction arguments + + collection expressions expressions de collection diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index f5c827482fc6..4844f0e26bbc 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -2342,6 +2342,11 @@ Impossibile utilizzare l'oggetto 'this' prima dell'assegnazione di tutti i relativi campi. Provare a eseguire l'aggiornamento alla versione del linguaggio '{0}' per impostare come predefiniti automaticamente i campi non assegnati. + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. È previsto un tipo restituito simile a un'attività generica, ma il tipo '{0}' trovato nell'attributo 'AsyncMethodBuilder' non è idoneo. Deve essere un tipo generico non associato di grado uno e il tipo che lo contiene (se presente) deve essere non generico. @@ -2382,6 +2387,11 @@ operatori definiti dall'utente controllati + + collection expression construction arguments + collection expression construction arguments + + collection expressions espressioni di raccolta diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index b985c66bdefe..97a78fc5ac75 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -2342,6 +2342,11 @@ すべてのフィールドが割り当てられる前に、'this' オブジェクトを使用することはできません。割り当てられていないフィールドを自動既定値にするため '{0}' 言語バージョンに更新することを検討してください。 + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. 汎用タスクのような戻り値の型が必要ですが、'AsyncMethodBuilder' 属性で見つかった型 '{0}' が適切ではありませんでした。アリティの非バインド ジェネリック型である必要があり、それを含む型 (存在する場合) は非ジェネリックでなければなりません。 @@ -2382,6 +2387,11 @@ チェックされたユーザー定義演算子 + + collection expression construction arguments + collection expression construction arguments + + collection expressions コレクション式 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 176ad5fe01c9..fc67f6f38394 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -2342,6 +2342,11 @@ 모든 필드가 할당되기 전에는 'this' 개체를 사용할 수 없습니다. 할당되지 않은 필드의 기본값을 자동으로 설정하려면 언어 버전 '{0}'(으)로 업데이트하는 것이 좋습니다. + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. 일반 작업과 같은 반환 유형이 예상되었지만 'AsyncMethodBuilder' 특성에 있는 '{0}' 유형이 적합하지 않습니다. 이는 인자 수가 1인 바인딩되지 않은 제네릭 유형이어야 하고, 포함하는 유형(있는 경우)은 제네릭이 아니어야 합니다. @@ -2382,6 +2387,11 @@ 확인된 사용자 정의 연산자 + + collection expression construction arguments + collection expression construction arguments + + collection expressions 컬렉션 식 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index acb1be2ec592..4651eadb2dc5 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -2342,6 +2342,11 @@ Nie można użyć obiektu „this” przed przypisaniem wszystkich jego pól. Rozważ zaktualizowanie nieprzypisanych pól do wersji językowej „{0}”, aby automatycznie ustawić domyślne pola niezaznaczone. + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Oczekiwano zwracanego typu podobnego do zadania ogólnego, ale typ "{0}" znaleziony w atrybucie "AsyncMethodBuilder" był nieodpowiedni. Musi to być niepowiązany typ ogólny jednego argumentu, a zawarty w nim typ (jeśli występuje), nie może być ogólny. @@ -2382,6 +2387,11 @@ zaznaczone operatory zdefiniowane przez użytkownika + + collection expression construction arguments + collection expression construction arguments + + collection expressions wyrażenia kolekcji diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 7d1d81e490e2..3971921fd53f 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -2342,6 +2342,11 @@ O objeto 'this' não pode ser usado antes que todos os seus campos serem atribuídos. Considere atualizar para a versão de linguagem '{0}' para auto-padrão dos campos não atribuídos. + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Um tipo de retorno semelhante à tarefa genérica era esperado, mas o tipo '{0}' encontrado no atributo 'AsyncMethodBuilder' não era adequado. Ele deve ser um tipo genérico não associado de arity um e seu tipo recipiente (se houver) deve ser não genérico. @@ -2382,6 +2387,11 @@ operadores verificados, definidos pelo usuário + + collection expression construction arguments + collection expression construction arguments + + collection expressions expressões de coleção diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index d6556d7c83f5..fe8c3e1ce0ad 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -2342,6 +2342,11 @@ Нельзя использовать объект "this", пока не будут назначены все его поля. Попробуйте обновить до языковой версии "{0}", чтобы автоматически применить значения по умолчанию к неназначенным полям. + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Ожидался универсальный возвращаемый тип, схожий с задачей, но тип "{0}", обнаруженный в атрибуте "AsyncMethodBuilder", не подходит. Требуется неограниченный универсальный тип c арностью 1, а его содержащий тип (если есть) не должен быть универсальным @@ -2382,6 +2387,11 @@ проверенные операторы, определяемые пользователем + + collection expression construction arguments + collection expression construction arguments + + collection expressions выражения коллекции diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 3633d5d45f5f..a59a00e15a30 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -2342,6 +2342,11 @@ 'this' nesnesi, tüm alanları atanmadan önce kullanılamaz. Atanmamış alanları otomatik olarak varsayılan durumuna getirmek için '{0}' dil sürümüne güncelleştirmeyi düşünün. + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. Genel bir görev benzeri dönüş türü bekleniyordu, ancak ' AsyncMethodBuilder ' özniteliğinde bulunan '{0}' türü uygun değildi. İlişkisiz bir genel tür olması ve içeren türü (varsa) genel olmayan olması gerekir. @@ -2382,6 +2387,11 @@ kullanıcı tanımlı işleçler işaretlendi + + collection expression construction arguments + collection expression construction arguments + + collection expressions koleksiyon ifadeleri diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 93900eb033f7..6fb424260dfd 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -2342,6 +2342,11 @@ 在分配“this”对象的所有字段之前,无法使用该对象。请考虑更新到语言版本 '{0}' 以自动默认未分配的字段。 + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. 应为泛用类任务返回类型,但在“AsyncMethodBuilder”属性中发现的类型“{0}”不合适。它必须是 arity one 的未绑定泛型类型,并且其包含类型(如果有)必须为非泛用。 @@ -2382,6 +2387,11 @@ 选中的用户定义运算符 + + collection expression construction arguments + collection expression construction arguments + + 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 ec34fb45b0ac..7382d680dd06 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -2342,6 +2342,11 @@ 在指派 'this' 物件的所有欄位之前,無法使用該物件。請考慮更新語言版本 '{0}',以自動預設未指派的欄位。 + + 'with(...)' element must be first element in collection expression + 'with(...)' element must be first element in collection expression + + A generic task-like return type was expected, but the type '{0}' found in 'AsyncMethodBuilder' attribute was not suitable. It must be an unbound generic type of arity one, and its containing type (if any) must be non-generic. 應存在類似泛型工作的傳回型別,但在 'AsyncMethodBuilder' 屬性中找到的類型 '{0}' 不適用。它必須是 arity one 的未綁定泛型型別,並且其包含類型 (如果有) 必須是非泛型。 @@ -2382,6 +2387,11 @@ 已檢查使用者定義的運算子 + + collection expression construction arguments + collection expression construction arguments + + collection expressions 集合運算式 diff --git a/src/Compilers/CSharp/Test/Syntax/Generated/Syntax.Test.xml.Generated.cs b/src/Compilers/CSharp/Test/Syntax/Generated/Syntax.Test.xml.Generated.cs index c80319347c4b..b6a7f4faadf5 100644 --- a/src/Compilers/CSharp/Test/Syntax/Generated/Syntax.Test.xml.Generated.cs +++ b/src/Compilers/CSharp/Test/Syntax/Generated/Syntax.Test.xml.Generated.cs @@ -226,6 +226,9 @@ private static Syntax.InternalSyntax.SpreadElementSyntax GenerateSpreadElement() private static Syntax.InternalSyntax.KeyValuePairElementSyntax GenerateKeyValuePairElement() => InternalSyntaxFactory.KeyValuePairElement(GenerateIdentifierName(), InternalSyntaxFactory.Token(SyntaxKind.ColonToken), GenerateIdentifierName()); + private static Syntax.InternalSyntax.WithElementSyntax GenerateWithElement() + => InternalSyntaxFactory.WithElement(InternalSyntaxFactory.Token(SyntaxKind.WithKeyword), GenerateArgumentList()); + private static Syntax.InternalSyntax.QueryExpressionSyntax GenerateQueryExpression() => InternalSyntaxFactory.QueryExpression(GenerateFromClause(), GenerateQueryBody()); @@ -1597,6 +1600,17 @@ public void TestKeyValuePairElementFactoryAndProperties() AttachAndCheckDiagnostics(node); } + [Fact] + public void TestWithElementFactoryAndProperties() + { + var node = GenerateWithElement(); + + Assert.Equal(SyntaxKind.WithKeyword, node.WithKeyword.Kind); + Assert.NotNull(node.ArgumentList); + + AttachAndCheckDiagnostics(node); + } + [Fact] public void TestQueryExpressionFactoryAndProperties() { @@ -5764,6 +5778,32 @@ public void TestKeyValuePairElementIdentityRewriter() Assert.Same(oldNode, newNode); } + [Fact] + public void TestWithElementTokenDeleteRewriter() + { + var oldNode = GenerateWithElement(); + var rewriter = new TokenDeleteRewriter(); + var newNode = rewriter.Visit(oldNode); + + if(!oldNode.IsMissing) + { + Assert.NotEqual(oldNode, newNode); + } + + Assert.NotNull(newNode); + Assert.True(newNode.IsMissing, "No tokens => missing"); + } + + [Fact] + public void TestWithElementIdentityRewriter() + { + var oldNode = GenerateWithElement(); + var rewriter = new IdentityRewriter(); + var newNode = rewriter.Visit(oldNode); + + Assert.Same(oldNode, newNode); + } + [Fact] public void TestQueryExpressionTokenDeleteRewriter() { @@ -10483,6 +10523,9 @@ private static SpreadElementSyntax GenerateSpreadElement() private static KeyValuePairElementSyntax GenerateKeyValuePairElement() => SyntaxFactory.KeyValuePairElement(GenerateIdentifierName(), SyntaxFactory.Token(SyntaxKind.ColonToken), GenerateIdentifierName()); + private static WithElementSyntax GenerateWithElement() + => SyntaxFactory.WithElement(SyntaxFactory.Token(SyntaxKind.WithKeyword), GenerateArgumentList()); + private static QueryExpressionSyntax GenerateQueryExpression() => SyntaxFactory.QueryExpression(GenerateFromClause(), GenerateQueryBody()); @@ -11854,6 +11897,17 @@ public void TestKeyValuePairElementFactoryAndProperties() Assert.Equal(node, newNode); } + [Fact] + public void TestWithElementFactoryAndProperties() + { + var node = GenerateWithElement(); + + Assert.Equal(SyntaxKind.WithKeyword, node.WithKeyword.Kind()); + Assert.NotNull(node.ArgumentList); + var newNode = node.WithWithKeyword(node.WithKeyword).WithArgumentList(node.ArgumentList); + Assert.Equal(node, newNode); + } + [Fact] public void TestQueryExpressionFactoryAndProperties() { @@ -16021,6 +16075,32 @@ public void TestKeyValuePairElementIdentityRewriter() Assert.Same(oldNode, newNode); } + [Fact] + public void TestWithElementTokenDeleteRewriter() + { + var oldNode = GenerateWithElement(); + var rewriter = new TokenDeleteRewriter(); + var newNode = rewriter.Visit(oldNode); + + if(!oldNode.IsMissing) + { + Assert.NotEqual(oldNode, newNode); + } + + Assert.NotNull(newNode); + Assert.True(newNode.IsMissing, "No tokens => missing"); + } + + [Fact] + public void TestWithElementIdentityRewriter() + { + var oldNode = GenerateWithElement(); + var rewriter = new IdentityRewriter(); + var newNode = rewriter.Visit(oldNode); + + Assert.Same(oldNode, newNode); + } + [Fact] public void TestQueryExpressionTokenDeleteRewriter() { diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs index c25e1945679f..2e403621f02b 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs @@ -10,10 +10,8 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests; -public sealed class CollectionExpressionParsingTests : ParsingTests +public sealed class CollectionExpressionParsingTests(ITestOutputHelper output) : ParsingTests(output) { - public CollectionExpressionParsingTests(ITestOutputHelper output) : base(output) { } - [Theory] [InlineData(LanguageVersion.CSharp11)] [InlineData(LanguageVersion.Preview)] @@ -18419,4 +18417,1644 @@ void M() } """).VerifyDiagnostics(); } + + [Fact] + public void NotWithElement1() + { + UsingExpression("[with]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement2() + { + UsingExpression("[with: with]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.KeyValuePairElement); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.ColonToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement3() + { + UsingExpression("[.. with]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.SpreadElement); + { + N(SyntaxKind.DotDotToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement4() + { + UsingExpression("[with + with]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.AddExpression); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.PlusToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement5() + { + UsingExpression("[with.X]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.SimpleMemberAccessExpression); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.DotToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "X"); + } + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement6() + { + UsingExpression("[with[X]]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.ElementAccessExpression); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.BracketedArgumentList); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "X"); + } + } + N(SyntaxKind.CloseBracketToken); + } + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement7() + { + UsingExpression("[with ? with : with]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.ConditionalExpression); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.QuestionToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.ColonToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement8() + { + UsingExpression("[with?.with]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.ConditionalAccessExpression); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.QuestionToken); + N(SyntaxKind.MemberBindingExpression); + { + N(SyntaxKind.DotToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + } + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement9() + { + UsingExpression("[with++]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.PostIncrementExpression); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.PlusPlusToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement10() + { + UsingExpression("[with)]", + // (1,6): error CS1003: Syntax error, ',' expected + // [with)] + Diagnostic(ErrorCode.ERR_SyntaxError, ")").WithArguments(",").WithLocation(1, 6)); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement11() + { + UsingExpression("[with..with]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.RangeExpression); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.DotDotToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement12() + { + UsingExpression("[with..with()]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.RangeExpression); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.DotDotToken); + N(SyntaxKind.InvocationExpression); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement13() + { + UsingExpression("[@with()]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.InvocationExpression); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "@with"); + } + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void NotWithElement14() + { + UsingExpression("with()"); + + N(SyntaxKind.InvocationExpression); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + EOF(); + } + + [Fact] + public void NotWithElement15() + { + UsingExpression("a with()", + // (1,1): error CS1073: Unexpected token 'with' + // a with() + Diagnostic(ErrorCode.ERR_UnexpectedToken, "a").WithArguments("with").WithLocation(1, 1)); + + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + EOF(); + } + + [Fact] + public void NotWithElement16() + { + UsingExpression("[with()] a => b"); + + N(SyntaxKind.SimpleLambdaExpression); + { + N(SyntaxKind.AttributeList); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.Attribute); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.AttributeArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + N(SyntaxKind.Parameter); + { + N(SyntaxKind.IdentifierToken, "a"); + } + N(SyntaxKind.EqualsGreaterThanToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "b"); + } + } + EOF(); + } + + [Fact] + public void NotWithElement17() + { + UsingExpression("[with()] async a => b"); + + N(SyntaxKind.SimpleLambdaExpression); + { + N(SyntaxKind.AttributeList); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.Attribute); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.AttributeArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + N(SyntaxKind.AsyncKeyword); + N(SyntaxKind.Parameter); + { + N(SyntaxKind.IdentifierToken, "a"); + } + N(SyntaxKind.EqualsGreaterThanToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "b"); + } + } + EOF(); + } + + [Fact] + public void NotWithElement18() + { + UsingExpression("[with()] (a) => b"); + + N(SyntaxKind.ParenthesizedLambdaExpression); + { + N(SyntaxKind.AttributeList); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.Attribute); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.AttributeArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + N(SyntaxKind.ParameterList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Parameter); + { + N(SyntaxKind.IdentifierToken, "a"); + } + N(SyntaxKind.CloseParenToken); + } + N(SyntaxKind.EqualsGreaterThanToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "b"); + } + } + EOF(); + } + + [Fact] + public void WithElement1() + { + UsingExpression("[with(]", + // (1,7): error CS1026: ) expected + // [with(] + Diagnostic(ErrorCode.ERR_CloseParenExpected, "]").WithLocation(1, 7), + // (1,8): error CS1003: Syntax error, ']' expected + // [with(] + Diagnostic(ErrorCode.ERR_SyntaxError, "").WithArguments("]").WithLocation(1, 8)); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + M(SyntaxKind.CloseParenToken); + } + } + M(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement2() + { + UsingExpression("[with()]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement3() + { + UsingExpression("[with(,)]", + // (1,7): error CS0839: Argument missing + // [with(,)] + Diagnostic(ErrorCode.ERR_MissingArgument, ",").WithLocation(1, 7), + // (1,8): error CS1525: Invalid expression term ')' + // [with(,)] + Diagnostic(ErrorCode.ERR_InvalidExprTerm, ")").WithArguments(")").WithLocation(1, 8)); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + M(SyntaxKind.Argument); + { + M(SyntaxKind.IdentifierName); + { + M(SyntaxKind.IdentifierToken); + } + } + N(SyntaxKind.CommaToken); + M(SyntaxKind.Argument); + { + M(SyntaxKind.IdentifierName); + { + M(SyntaxKind.IdentifierToken); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement4() + { + UsingExpression("[with(a)]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement5() + { + UsingExpression("[with(ref a)]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.RefKeyword); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement6() + { + UsingExpression("[with(out a)]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.OutKeyword); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement7() + { + UsingExpression("[with(out var a)]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.OutKeyword); + N(SyntaxKind.DeclarationExpression); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "var"); + } + N(SyntaxKind.SingleVariableDesignation); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement8() + { + UsingExpression("[with(name: value)]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.NameColon); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "name"); + } + N(SyntaxKind.ColonToken); + } + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "value"); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement9() + { + UsingExpression("[with(a, b)]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "b"); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement10() + { + UsingExpression("[with(), with()]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement11() + { + UsingExpression("[a, with()]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement12() + { + UsingExpression("[a:b, with()]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.KeyValuePairElement); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + N(SyntaxKind.ColonToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "b"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement13() + { + UsingExpression("[..a, with()]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.SpreadElement); + { + N(SyntaxKind.DotDotToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement14() + { + UsingExpression("[with(), a]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement15() + { + UsingExpression("[with(), a:b]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.KeyValuePairElement); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + N(SyntaxKind.ColonToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "b"); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement16() + { + UsingExpression("[with(), ..a]"); + + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.SpreadElement); + { + N(SyntaxKind.DotDotToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement17() + { + UsingExpression("[with([])]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.CloseBracketToken); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement18() + { + UsingExpression("[with(() => {})]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.ParenthesizedLambdaExpression); + { + N(SyntaxKind.ParameterList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + N(SyntaxKind.EqualsGreaterThanToken); + N(SyntaxKind.Block); + { + N(SyntaxKind.OpenBraceToken); + N(SyntaxKind.CloseBraceToken); + } + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement19() + { + UsingExpression("[with(async () => {})]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.ParenthesizedLambdaExpression); + { + N(SyntaxKind.AsyncKeyword); + N(SyntaxKind.ParameterList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + N(SyntaxKind.EqualsGreaterThanToken); + N(SyntaxKind.Block); + { + N(SyntaxKind.OpenBraceToken); + N(SyntaxKind.CloseBraceToken); + } + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement20() + { + UsingExpression("[with(from x in y select x)]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.QueryExpression); + { + N(SyntaxKind.FromClause); + { + N(SyntaxKind.FromKeyword); + N(SyntaxKind.IdentifierToken, "x"); + N(SyntaxKind.InKeyword); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "y"); + } + } + N(SyntaxKind.QueryBody); + { + N(SyntaxKind.SelectClause); + { + N(SyntaxKind.SelectKeyword); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "x"); + } + } + } + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement21() + { + UsingExpression("[with([with()])]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement22() + { + UsingExpression("[with(with: with)]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.NameColon); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + N(SyntaxKind.ColonToken); + } + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "with"); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement23() + { + UsingExpression("[with(out _)]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.OutKeyword); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "_"); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement24() + { + UsingExpression("[with(in a)]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.InKeyword); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement25() + { + UsingExpression("[with(name: ref a)]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.NameColon); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "name"); + } + N(SyntaxKind.ColonToken); + } + N(SyntaxKind.RefKeyword); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement26() + { + UsingExpression("[with(ref int () => { })]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.ParenthesizedLambdaExpression); + { + N(SyntaxKind.RefType); + { + N(SyntaxKind.RefKeyword); + N(SyntaxKind.PredefinedType); + { + N(SyntaxKind.IntKeyword); + } + } + N(SyntaxKind.ParameterList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + N(SyntaxKind.EqualsGreaterThanToken); + N(SyntaxKind.Block); + { + N(SyntaxKind.OpenBraceToken); + N(SyntaxKind.CloseBraceToken); + } + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement27() + { + UsingExpression("[with()..x]", + // (1,8): error CS1003: Syntax error, ',' expected + // [with()..x] + Diagnostic(ErrorCode.ERR_SyntaxError, ".").WithArguments(",").WithLocation(1, 8)); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + M(SyntaxKind.CommaToken); + N(SyntaxKind.SpreadElement); + { + N(SyntaxKind.DotDotToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "x"); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement28() + { + UsingExpression("[with().x]", + // (1,8): error CS1003: Syntax error, ',' expected + // [with().x] + Diagnostic(ErrorCode.ERR_SyntaxError, ".").WithArguments(",").WithLocation(1, 8), + // (1,9): error CS1003: Syntax error, ',' expected + // [with().x] + Diagnostic(ErrorCode.ERR_SyntaxError, "x").WithArguments(",").WithLocation(1, 9)); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + M(SyntaxKind.CommaToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "x"); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement29() + { + UsingExpression("[with()", + // (1,8): error CS1003: Syntax error, ']' expected + // [with() + Diagnostic(ErrorCode.ERR_SyntaxError, "").WithArguments("]").WithLocation(1, 8)); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + M(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement30() + { + UsingExpression("[with(),", + // (1,9): error CS1003: Syntax error, ']' expected + // [with(), + Diagnostic(ErrorCode.ERR_SyntaxError, "").WithArguments("]").WithLocation(1, 9)); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CommaToken); + M(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement31() + { + UsingExpression("[with(_)]"); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "_"); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement32() + { + UsingExpression("[with(a,)]", + // (1,9): error CS1525: Invalid expression term ')' + // [with(a,)] + Diagnostic(ErrorCode.ERR_InvalidExprTerm, ")").WithArguments(")").WithLocation(1, 9)); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + N(SyntaxKind.CommaToken); + M(SyntaxKind.Argument); + { + M(SyntaxKind.IdentifierName); + { + M(SyntaxKind.IdentifierToken); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } + + [Fact] + public void WithElement33() + { + UsingExpression("[with(,a)]", + // (1,7): error CS0839: Argument missing + // [with(,a)] + Diagnostic(ErrorCode.ERR_MissingArgument, ",").WithLocation(1, 7)); + + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.WithElement); + { + N(SyntaxKind.WithKeyword); + N(SyntaxKind.ArgumentList); + { + N(SyntaxKind.OpenParenToken); + M(SyntaxKind.Argument); + { + M(SyntaxKind.IdentifierName); + { + M(SyntaxKind.IdentifierToken); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.Argument); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "a"); + } + } + N(SyntaxKind.CloseParenToken); + } + } + N(SyntaxKind.CloseBracketToken); + } + EOF(); + } } diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs index f482202d68ca..dec0c9a040b6 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs @@ -51,6 +51,7 @@ public async Task DiagnosticAnalyzerDriverAllInOne() SyntaxKind.ExpressionElement, SyntaxKind.SpreadElement, SyntaxKind.KeyValuePairElement, + SyntaxKind.WithElement, }; var analyzer = new CSharpTrackingDiagnosticAnalyzer();