From e3c972a338abd76e55a915ca1efadf4a8f92a621 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 15 Aug 2023 09:12:09 -0700 Subject: [PATCH 1/6] initial ideal --- .../CSharp/Portable/Parser/LanguageParser.cs | 22 +++++++++---------- .../CollectionExpressionParsingTests.cs | 17 ++++++++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index 4f9edf52379f..fd75d4591def 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -5777,10 +5777,9 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( return ScanTypeFlags.GenericTypeOrMethod; } - ScanTypeFlags result = ScanTypeFlags.GenericTypeOrExpression; - do { + // Eat the < this.EatToken(); // Type arguments cannot contain attributes, so if this is an open square, we early out and assume it is not a type argument @@ -5793,12 +5792,14 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( if (this.CurrentToken.Kind == SyntaxKind.GreaterThanToken) { greaterThanToken = EatToken(); - return result; + return ScanTypeFlags.GenericTypeOrExpression; } + // Now try to consume the type-arguments to this generic type. switch (this.ScanType(out _)) { case ScanTypeFlags.NotType: + // Hit something that wasn't a type, this is definitely not a type. greaterThanToken = null; return ScanTypeFlags.NotType; @@ -5825,7 +5826,6 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( // (int, string, etc.), or array types (Goo[], A[][] etc.), or pointer types // of things that must be types (int*, void**, etc.). isDefinitelyTypeArgumentList = DetermineIfDefinitelyTypeArgumentList(isDefinitelyTypeArgumentList); - result = ScanTypeFlags.GenericTypeOrMethod; break; // case ScanTypeFlags.TupleType: @@ -5852,10 +5852,6 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( case ScanTypeFlags.NullableType: // See above. If we have X, then this is definitely a type argument list. isDefinitelyTypeArgumentList = DetermineIfDefinitelyTypeArgumentList(isDefinitelyTypeArgumentList); - if (isDefinitelyTypeArgumentList) - { - result = ScanTypeFlags.GenericTypeOrMethod; - } // Note: we intentionally fall out without setting 'result'. // Seeing a nullable type (not followed by a , or > ) is not enough @@ -5864,7 +5860,6 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( // X < Y ? Z : W // // We'd see a nullable type here, but this is definitely not a type arg list. - break; case ScanTypeFlags.GenericTypeOrExpression: @@ -5874,12 +5869,14 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( if (!isDefinitelyTypeArgumentList) { isDefinitelyTypeArgumentList = this.CurrentToken.Kind == SyntaxKind.CommaToken; - result = ScanTypeFlags.GenericTypeOrMethod; } break; case ScanTypeFlags.GenericTypeOrMethod: - result = ScanTypeFlags.GenericTypeOrMethod; + if (!isDefinitelyTypeArgumentList) + { + isDefinitelyTypeArgumentList = this.CurrentToken.Kind == SyntaxKind.CommaToken; + } break; case ScanTypeFlags.NonGenericTypeOrExpression: @@ -5899,8 +5896,9 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( return ScanTypeFlags.NotType; } + // We consumed <...> successfully. This has to be a generic type or method at this point. greaterThanToken = this.EatToken(); - return result; + return ScanTypeFlags.GenericTypeOrMethod; } private bool DetermineIfDefinitelyTypeArgumentList(bool isDefinitelyTypeArgumentList) diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs index 25df4bbd4eb5..7a9716a50e12 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using Microsoft.CodeAnalysis.CSharp.Test.Utilities; +using Roslyn.Test.Utilities; using Xunit; using Xunit.Abstractions; @@ -5656,6 +5657,22 @@ public void CastVersusIndexAmbiguity30() EOF(); } + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/69508")] + public void CastVersusIndexAmbiguity31() + { + UsingStatement("var collection = (List)[1, 2, 3, 4, 5];"); + + EOF(); + } + + [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/69508")] + public void CastVersusIndexAmbiguity32() + { + UsingTree("var collection = (List)[1, 2, 3, 4, 5];"); + + EOF(); + } + [Fact] public void SpreadOfQuery() { From f740a66aaa0001a748a9e63acb9909e441445a75 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 15 Aug 2023 09:31:18 -0700 Subject: [PATCH 2/6] Fix parsing of generics in casts. --- .../CSharp/Portable/Parser/LanguageParser.cs | 40 +++-- .../CollectionExpressionParsingTests.cs | 169 ++++++++++++++++++ 2 files changed, 194 insertions(+), 15 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index fd75d4591def..0a2aa53c0a51 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -5777,9 +5777,10 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( return ScanTypeFlags.GenericTypeOrMethod; } + ScanTypeFlags result = ScanTypeFlags.GenericTypeOrExpression; + do { - // Eat the < this.EatToken(); // Type arguments cannot contain attributes, so if this is an open square, we early out and assume it is not a type argument @@ -5792,14 +5793,12 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( if (this.CurrentToken.Kind == SyntaxKind.GreaterThanToken) { greaterThanToken = EatToken(); - return ScanTypeFlags.GenericTypeOrExpression; + return result; } - // Now try to consume the type-arguments to this generic type. switch (this.ScanType(out _)) { case ScanTypeFlags.NotType: - // Hit something that wasn't a type, this is definitely not a type. greaterThanToken = null; return ScanTypeFlags.NotType; @@ -5826,6 +5825,7 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( // (int, string, etc.), or array types (Goo[], A[][] etc.), or pointer types // of things that must be types (int*, void**, etc.). isDefinitelyTypeArgumentList = DetermineIfDefinitelyTypeArgumentList(isDefinitelyTypeArgumentList); + result = ScanTypeFlags.GenericTypeOrMethod; break; // case ScanTypeFlags.TupleType: @@ -5852,6 +5852,10 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( case ScanTypeFlags.NullableType: // See above. If we have X, then this is definitely a type argument list. isDefinitelyTypeArgumentList = DetermineIfDefinitelyTypeArgumentList(isDefinitelyTypeArgumentList); + if (isDefinitelyTypeArgumentList) + { + result = ScanTypeFlags.GenericTypeOrMethod; + } // Note: we intentionally fall out without setting 'result'. // Seeing a nullable type (not followed by a , or > ) is not enough @@ -5860,23 +5864,22 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( // X < Y ? Z : W // // We'd see a nullable type here, but this is definitely not a type arg list. + break; case ScanTypeFlags.GenericTypeOrExpression: - // See above. If we have X, then this would definitely be a type argument list. - // However, if we have X> then this might not be type argument list. This could just - // be some sort of expression where we're comparing, and then shifting values. + // See above. If we have `X,` or `X)` then this would definitely be a type argument + // list. However, if we have `X>` then this might not be type argument list. This could + // just be some sort of expression where we're comparing, and then shifting values. if (!isDefinitelyTypeArgumentList) { - isDefinitelyTypeArgumentList = this.CurrentToken.Kind == SyntaxKind.CommaToken; + isDefinitelyTypeArgumentList = this.CurrentToken.Kind is SyntaxKind.CommaToken or SyntaxKind.CloseParenToken; + result = ScanTypeFlags.GenericTypeOrMethod; } break; case ScanTypeFlags.GenericTypeOrMethod: - if (!isDefinitelyTypeArgumentList) - { - isDefinitelyTypeArgumentList = this.CurrentToken.Kind == SyntaxKind.CommaToken; - } + result = ScanTypeFlags.GenericTypeOrMethod; break; case ScanTypeFlags.NonGenericTypeOrExpression: @@ -5896,9 +5899,16 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( return ScanTypeFlags.NotType; } - // We consumed <...> successfully. This has to be a generic type or method at this point. greaterThanToken = this.EatToken(); - return ScanTypeFlags.GenericTypeOrMethod; + + // If we have `X)` then this would definitely be a type argument list. + if (!isDefinitelyTypeArgumentList && this.CurrentToken.Kind is SyntaxKind.CloseParenToken) + { + isDefinitelyTypeArgumentList = true; + result = ScanTypeFlags.GenericTypeOrMethod; + } + + return result; } private bool DetermineIfDefinitelyTypeArgumentList(bool isDefinitelyTypeArgumentList) @@ -11796,7 +11806,7 @@ private bool ScanCast(bool forPattern = false) this.EatToken(); - var type = this.ScanType(forPattern: forPattern); + var type = this.ScanType(forPattern); if (type == ScanTypeFlags.NotType) { return false; diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs index 7a9716a50e12..3b76676408d3 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs @@ -5662,6 +5662,87 @@ public void CastVersusIndexAmbiguity31() { UsingStatement("var collection = (List)[1, 2, 3, 4, 5];"); + N(SyntaxKind.LocalDeclarationStatement); + { + N(SyntaxKind.VariableDeclaration); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "var"); + } + N(SyntaxKind.VariableDeclarator); + { + N(SyntaxKind.IdentifierToken, "collection"); + N(SyntaxKind.EqualsValueClause); + { + N(SyntaxKind.EqualsToken); + N(SyntaxKind.CastExpression); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.GenericName); + { + N(SyntaxKind.IdentifierToken, "List"); + N(SyntaxKind.TypeArgumentList); + { + N(SyntaxKind.LessThanToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "Cell"); + } + N(SyntaxKind.GreaterThanToken); + } + } + N(SyntaxKind.CloseParenToken); + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.NumericLiteralExpression); + { + N(SyntaxKind.NumericLiteralToken, "1"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.NumericLiteralExpression); + { + N(SyntaxKind.NumericLiteralToken, "2"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.NumericLiteralExpression); + { + N(SyntaxKind.NumericLiteralToken, "3"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.NumericLiteralExpression); + { + N(SyntaxKind.NumericLiteralToken, "4"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.NumericLiteralExpression); + { + N(SyntaxKind.NumericLiteralToken, "5"); + } + } + N(SyntaxKind.CloseBracketToken); + } + } + } + } + } + N(SyntaxKind.SemicolonToken); + } EOF(); } @@ -5670,6 +5751,94 @@ public void CastVersusIndexAmbiguity32() { UsingTree("var collection = (List)[1, 2, 3, 4, 5];"); + N(SyntaxKind.CompilationUnit); + { + N(SyntaxKind.GlobalStatement); + { + N(SyntaxKind.LocalDeclarationStatement); + { + N(SyntaxKind.VariableDeclaration); + { + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "var"); + } + N(SyntaxKind.VariableDeclarator); + { + N(SyntaxKind.IdentifierToken, "collection"); + N(SyntaxKind.EqualsValueClause); + { + N(SyntaxKind.EqualsToken); + N(SyntaxKind.CastExpression); + { + N(SyntaxKind.OpenParenToken); + N(SyntaxKind.GenericName); + { + N(SyntaxKind.IdentifierToken, "List"); + N(SyntaxKind.TypeArgumentList); + { + N(SyntaxKind.LessThanToken); + N(SyntaxKind.IdentifierName); + { + N(SyntaxKind.IdentifierToken, "Cell"); + } + N(SyntaxKind.GreaterThanToken); + } + } + N(SyntaxKind.CloseParenToken); + N(SyntaxKind.CollectionExpression); + { + N(SyntaxKind.OpenBracketToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.NumericLiteralExpression); + { + N(SyntaxKind.NumericLiteralToken, "1"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.NumericLiteralExpression); + { + N(SyntaxKind.NumericLiteralToken, "2"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.NumericLiteralExpression); + { + N(SyntaxKind.NumericLiteralToken, "3"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.NumericLiteralExpression); + { + N(SyntaxKind.NumericLiteralToken, "4"); + } + } + N(SyntaxKind.CommaToken); + N(SyntaxKind.ExpressionElement); + { + N(SyntaxKind.NumericLiteralExpression); + { + N(SyntaxKind.NumericLiteralToken, "5"); + } + } + N(SyntaxKind.CloseBracketToken); + } + } + } + } + } + N(SyntaxKind.SemicolonToken); + } + } + N(SyntaxKind.EndOfFileToken); + } EOF(); } From 547de9c1bcb3ca30ec3e9a8e5889bc2e9fd8a1a5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 15 Aug 2023 09:38:40 -0700 Subject: [PATCH 3/6] Simplify --- .../CSharp/Portable/Parser/LanguageParser.cs | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index 0a2aa53c0a51..0d8302d9bb83 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -5824,7 +5824,7 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( // Note: we check if we got 'MustBeType' which triggers for predefined types, // (int, string, etc.), or array types (Goo[], A[][] etc.), or pointer types // of things that must be types (int*, void**, etc.). - isDefinitelyTypeArgumentList = DetermineIfDefinitelyTypeArgumentList(isDefinitelyTypeArgumentList); + isDefinitelyTypeArgumentList = isDefinitelyTypeArgumentList || this.CurrentToken.Kind is SyntaxKind.CommaToken or SyntaxKind.GreaterThanToken; result = ScanTypeFlags.GenericTypeOrMethod; break; @@ -5850,8 +5850,9 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( // } case ScanTypeFlags.NullableType: - // See above. If we have X, then this is definitely a type argument list. - isDefinitelyTypeArgumentList = DetermineIfDefinitelyTypeArgumentList(isDefinitelyTypeArgumentList); + // See above. If we have `X` or `X,` or `X)` then this would definitely be a type argument // list. However, if we have `X>` then this might not be type argument list. This could // just be some sort of expression where we're comparing, and then shifting values. - if (!isDefinitelyTypeArgumentList) + isDefinitelyTypeArgumentList = isDefinitelyTypeArgumentList || this.CurrentToken.Kind is SyntaxKind.CommaToken or SyntaxKind.CloseParenToken; + if (isDefinitelyTypeArgumentList) { - isDefinitelyTypeArgumentList = this.CurrentToken.Kind is SyntaxKind.CommaToken or SyntaxKind.CloseParenToken; result = ScanTypeFlags.GenericTypeOrMethod; } break; @@ -5902,25 +5903,15 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( greaterThanToken = this.EatToken(); // If we have `X)` then this would definitely be a type argument list. - if (!isDefinitelyTypeArgumentList && this.CurrentToken.Kind is SyntaxKind.CloseParenToken) + isDefinitelyTypeArgumentList = isDefinitelyTypeArgumentList || this.CurrentToken.Kind is SyntaxKind.CloseParenToken; + if (isDefinitelyTypeArgumentList) { - isDefinitelyTypeArgumentList = true; result = ScanTypeFlags.GenericTypeOrMethod; } return result; } - private bool DetermineIfDefinitelyTypeArgumentList(bool isDefinitelyTypeArgumentList) - { - if (!isDefinitelyTypeArgumentList) - { - isDefinitelyTypeArgumentList = this.CurrentToken.Kind is SyntaxKind.CommaToken or SyntaxKind.GreaterThanToken; - } - - return isDefinitelyTypeArgumentList; - } - // ParseInstantiation: Parses the generic argument/parameter parts of the name. private void ParseTypeArgumentList(out SyntaxToken open, SeparatedSyntaxListBuilder types, out SyntaxToken close) { From 054b157943f21a5f59fee1b3c041101c4560eed3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 15 Aug 2023 09:39:43 -0700 Subject: [PATCH 4/6] REvert --- src/Compilers/CSharp/Portable/Parser/LanguageParser.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index 0d8302d9bb83..766c0b7a425b 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -5850,8 +5850,7 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( // } case ScanTypeFlags.NullableType: - // See above. If we have `X` or `X` then this is definitely a type argument list. isDefinitelyTypeArgumentList = isDefinitelyTypeArgumentList || this.CurrentToken.Kind is SyntaxKind.CommaToken or SyntaxKind.GreaterThanToken; if (isDefinitelyTypeArgumentList) { From c7f519794c050b5e29925fa66eefd3c813f34ca1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 15 Aug 2023 12:04:06 -0700 Subject: [PATCH 5/6] Add test. Revert code change --- .../CSharp/Portable/Parser/LanguageParser.cs | 10 +++++----- .../CollectionExpressionParsingTests.cs | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index 766c0b7a425b..949eee752e97 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -5868,12 +5868,12 @@ private ScanTypeFlags ScanPossibleTypeArgumentList( break; case ScanTypeFlags.GenericTypeOrExpression: - // See above. If we have `X,` or `X)` then this would definitely be a type argument - // list. However, if we have `X>` then this might not be type argument list. This could - // just be some sort of expression where we're comparing, and then shifting values. - isDefinitelyTypeArgumentList = isDefinitelyTypeArgumentList || this.CurrentToken.Kind is SyntaxKind.CommaToken or SyntaxKind.CloseParenToken; - if (isDefinitelyTypeArgumentList) + // See above. If we have X, then this would definitely be a type argument list. + // However, if we have X> then this might not be type argument list. This could just + // be some sort of expression where we're comparing, and then shifting values. + if (!isDefinitelyTypeArgumentList) { + isDefinitelyTypeArgumentList = this.CurrentToken.Kind == SyntaxKind.CommaToken; result = ScanTypeFlags.GenericTypeOrMethod; } break; diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs index 3b76676408d3..7e892348d2a8 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs @@ -5660,7 +5660,7 @@ public void CastVersusIndexAmbiguity30() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/69508")] public void CastVersusIndexAmbiguity31() { - UsingStatement("var collection = (List)[1, 2, 3, 4, 5];"); + UsingStatement("var x = (A)[1, 2, 3, 4, 5];"); N(SyntaxKind.LocalDeclarationStatement); { @@ -5672,7 +5672,7 @@ public void CastVersusIndexAmbiguity31() } N(SyntaxKind.VariableDeclarator); { - N(SyntaxKind.IdentifierToken, "collection"); + N(SyntaxKind.IdentifierToken, "x"); N(SyntaxKind.EqualsValueClause); { N(SyntaxKind.EqualsToken); @@ -5681,13 +5681,13 @@ public void CastVersusIndexAmbiguity31() N(SyntaxKind.OpenParenToken); N(SyntaxKind.GenericName); { - N(SyntaxKind.IdentifierToken, "List"); + N(SyntaxKind.IdentifierToken, "A"); N(SyntaxKind.TypeArgumentList); { N(SyntaxKind.LessThanToken); N(SyntaxKind.IdentifierName); { - N(SyntaxKind.IdentifierToken, "Cell"); + N(SyntaxKind.IdentifierToken, "B"); } N(SyntaxKind.GreaterThanToken); } @@ -5747,9 +5747,9 @@ public void CastVersusIndexAmbiguity31() } [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/69508")] - public void CastVersusIndexAmbiguity32() + public void CastVersusIndexAmbiguity31_GlobalStatement() { - UsingTree("var collection = (List)[1, 2, 3, 4, 5];"); + UsingTree("var x = (A)[1, 2, 3, 4, 5];"); N(SyntaxKind.CompilationUnit); { @@ -5765,7 +5765,7 @@ public void CastVersusIndexAmbiguity32() } N(SyntaxKind.VariableDeclarator); { - N(SyntaxKind.IdentifierToken, "collection"); + N(SyntaxKind.IdentifierToken, "x"); N(SyntaxKind.EqualsValueClause); { N(SyntaxKind.EqualsToken); @@ -5774,13 +5774,13 @@ public void CastVersusIndexAmbiguity32() N(SyntaxKind.OpenParenToken); N(SyntaxKind.GenericName); { - N(SyntaxKind.IdentifierToken, "List"); + N(SyntaxKind.IdentifierToken, "A"); N(SyntaxKind.TypeArgumentList); { N(SyntaxKind.LessThanToken); N(SyntaxKind.IdentifierName); { - N(SyntaxKind.IdentifierToken, "Cell"); + N(SyntaxKind.IdentifierToken, "B"); } N(SyntaxKind.GreaterThanToken); } From d4ac00350b9fd5e289d0d15a3418bdfc72e8a4a1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 15 Aug 2023 12:27:28 -0700 Subject: [PATCH 6/6] Apply suggestions from code review --- .../CollectionExpressionParsingTests.cs | 68 +------------------ 1 file changed, 2 insertions(+), 66 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs index 7e892348d2a8..8f27d62d11d6 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/CollectionExpressionParsingTests.cs @@ -5660,7 +5660,7 @@ public void CastVersusIndexAmbiguity30() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/69508")] public void CastVersusIndexAmbiguity31() { - UsingStatement("var x = (A)[1, 2, 3, 4, 5];"); + UsingStatement("var x = (A)[1];"); N(SyntaxKind.LocalDeclarationStatement); { @@ -5703,38 +5703,6 @@ public void CastVersusIndexAmbiguity31() N(SyntaxKind.NumericLiteralToken, "1"); } } - N(SyntaxKind.CommaToken); - N(SyntaxKind.ExpressionElement); - { - N(SyntaxKind.NumericLiteralExpression); - { - N(SyntaxKind.NumericLiteralToken, "2"); - } - } - N(SyntaxKind.CommaToken); - N(SyntaxKind.ExpressionElement); - { - N(SyntaxKind.NumericLiteralExpression); - { - N(SyntaxKind.NumericLiteralToken, "3"); - } - } - N(SyntaxKind.CommaToken); - N(SyntaxKind.ExpressionElement); - { - N(SyntaxKind.NumericLiteralExpression); - { - N(SyntaxKind.NumericLiteralToken, "4"); - } - } - N(SyntaxKind.CommaToken); - N(SyntaxKind.ExpressionElement); - { - N(SyntaxKind.NumericLiteralExpression); - { - N(SyntaxKind.NumericLiteralToken, "5"); - } - } N(SyntaxKind.CloseBracketToken); } } @@ -5749,7 +5717,7 @@ public void CastVersusIndexAmbiguity31() [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/69508")] public void CastVersusIndexAmbiguity31_GlobalStatement() { - UsingTree("var x = (A)[1, 2, 3, 4, 5];"); + UsingTree("var x = (A)[1];"); N(SyntaxKind.CompilationUnit); { @@ -5796,38 +5764,6 @@ public void CastVersusIndexAmbiguity31_GlobalStatement() N(SyntaxKind.NumericLiteralToken, "1"); } } - N(SyntaxKind.CommaToken); - N(SyntaxKind.ExpressionElement); - { - N(SyntaxKind.NumericLiteralExpression); - { - N(SyntaxKind.NumericLiteralToken, "2"); - } - } - N(SyntaxKind.CommaToken); - N(SyntaxKind.ExpressionElement); - { - N(SyntaxKind.NumericLiteralExpression); - { - N(SyntaxKind.NumericLiteralToken, "3"); - } - } - N(SyntaxKind.CommaToken); - N(SyntaxKind.ExpressionElement); - { - N(SyntaxKind.NumericLiteralExpression); - { - N(SyntaxKind.NumericLiteralToken, "4"); - } - } - N(SyntaxKind.CommaToken); - N(SyntaxKind.ExpressionElement); - { - N(SyntaxKind.NumericLiteralExpression); - { - N(SyntaxKind.NumericLiteralToken, "5"); - } - } N(SyntaxKind.CloseBracketToken); } }