Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

No description provided.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner June 22, 2023 18:23
@ghost ghost added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 22, 2023
@CyrusNajmabadi
Copy link
Member Author

@RikkiGibson ptal.

@cston
Copy link
Contributor

cston commented Jun 23, 2023

}

Perhaps test some nested cases:

  • [[A]].GetHashCode();
  • [A([B])].GetHashCode();
  • [A([B])] GetHashCode();

Refers to: src/Compilers/CSharp/Test/Syntax/Parsing/CollectionLiteralParsingTests.cs:10134 in 7da947b. [](commit_id = 7da947b, deletion_comment = False)

@CyrusNajmabadi
Copy link
Member Author

@RikkiGibson ptal. This unblocks Chuck from being able to send his PR that renames everything.

@RikkiGibson RikkiGibson self-assigned this Jun 23, 2023
@CyrusNajmabadi
Copy link
Member Author

@RikkiGibson please review ASAP. Note, I can add any additional tests into the follow-up pr which fixes the breaking change in parsing ternary vs nullable-index expressions


// See if we should treat this as a collection expression. At the top-level or statement-level, this should
// only be considered a collection if followed by a `.`, `?` or `!` (indicating it's a value, not an
// attribute).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make sure to test at some point that in the typing scenario, the tooling doesn't fight us about doing collection literal-ey things, when it thinks we're in an attribute list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. It likely will need special IDE support here to do well given this ambiguity. But this is very normal for the IDE> For example, we have to do all sort of special work inside of (... since it could be casts, parenthesized-exprs, lambdas, etc. PITA, but in our wheelhouse :)

@CyrusNajmabadi CyrusNajmabadi merged commit de4f0b7 into dotnet:features/CollectionLiterals Jun 23, 2023
@CyrusNajmabadi CyrusNajmabadi deleted the collectionExprStatementParsing branch June 23, 2023 20:29
ParseBracketedArgumentList();

// Check the next token to see if it indicates the `[...]` sequence we have is a term or not.
var isCollectionExpression = this.CurrentToken.Kind is SyntaxKind.DotToken or SyntaxKind.QuestionToken or SyntaxKind.ExclamationToken;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like this should be scanning for either a member modifier or something that could be a type: if it finds one of those, it must be an attribute. Otherwise, it must be a collection initializer. Consider [] + new List<int>(), or [] == new List<int>(), or number of other possible scenarios like them. A hardcoded list of allowable tokens feels too fragile.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so those don't work here fro the same reason that:

a + b; is not a legal statement. Will discuss more offline.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further offline discussion has revealed missing cases such as [() => {}][0](); or [0]++;. Cyrus will file a tracking issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants