carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

Parse parameters in name qualifiers.

Open zygoloid opened this issue 1 year ago • 2 comments

Parse the name of a declaration as a sequence of NameQualifiers -- which have a name, possibly parameters, and a trailing period -- followed by a name and possibly parameters. This prepares us for parsing declarations of members of generic classes and similar cases, but actually supporting such member redeclarations is left to a future change.

We previously required functions to have parameters, but no longer do, following the direction of #3848. Cases like namespaces that can't actually have parameters are now diagnosed in check instead of in parse.

zygoloid avatar May 24 '24 23:05 zygoloid

I'm not familiar with #3848, and I'm having trouble loading it because it has merge errors.

I believe the PR is only intending to add its p3848.md file and the rest of the changes listed there are spurious.

Does this PR indicate that leads have in effect approved the proposal?

We've not approved the proposal but we have consensus on the main points (including #3860, which is directly relevant here). But even without #3848, I think it'd still make sense to use the same parse rules (including parameters) for all names, and do any declaration-kind-specific checking in check. The main impact that #3848 has here is that this PR emits a TODO error for parameterless functions, rather than adding a proper diagnostic in check, because under #3848 they will be valid.

Is there some reference for what design you're trying to implement?

The main purpose of this PR of this is to support declarations of members of parameterized types:

class C(T:! type) {
  fn F();
}
fn C(T:! type).F() {}

The most recent / specific proposal on that is #3763. I think this syntax has been part of the intended design for generics for a while, but we don't seem to have any examples of this in /docs/design yet :(

zygoloid avatar May 28 '24 20:05 zygoloid

I'm not familiar with #3848, and I'm having trouble loading it because it has merge errors.

I believe the PR is only intending to add its p3848.md file and the rest of the changes listed there are spurious.

Thanks -- to be sure, I really meant, it wasn't loading for me to try and find the proposal file. The link helped.

jonmeow avatar May 28 '24 21:05 jonmeow