Skip to content

Conversation

lrhn
Copy link
Member

@lrhn lrhn commented Oct 16, 2025

For issue #3102

@lrhn lrhn requested a review from munificent October 16, 2025 12:52
Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

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

Very nice! LGTM.

return (:red, :green, :blue, :alpha);
}
}
```
Copy link
Member

Choose a reason for hiding this comment

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

It may be worth noting that the following would suffice. Before:

extension on Color {
  Color withAlpha(int alpha) =>
      (red: red, green: green, blue: blue, alpha: alpha);
}

alpha is resolved in the lexical scope, and the other identifier expressions are resolved as instance member references (adding this.). After:

extension on Color {
  Color withAlpha(int alpha) => (:red, :green, :blue, :alpha);
  }
}

If you want to avoid the discussion about "but is that readable?" then perhaps use plain local declarations rather than an extension method.


As a non-grammatical restriction, it's a **compile-time error**
if a `<namedExpression>` omits the leading`<identifier>`, and the following
expressions is not a _single identifier expression_, as defined below.
Copy link
Member

Choose a reason for hiding this comment

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

Typo:

Suggested change
expressions is not a _single identifier expression_, as defined below.
expression is not a _single identifier expression_, as defined below.

if a `<namedExpression>` omits the leading`<identifier>`, and the following
expressions is not a _single identifier expression_, as defined below.

In short, an expression is a _single identifier expression_
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In short, an expression is a _single identifier expression_
An expression is a _single identifier expression with identifier_

Having seen line 93, it seems likely that this paragraph should be commentary (such that readers will know which one wins if the two definitions disagree). Moreover, if this is changed to commentary then it would probably be more readable if placed after the actual definition (which would then motivate a reintroduction of 'In short,')

expressions is not a _single identifier expression_, as defined below.

In short, an expression is a _single identifier expression_
which has a specific single _identifier_ if and only if
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
which has a specific single _identifier_ if and only if
`id` if and only if

which has a specific single _identifier_ if and only if
it is one of the following:
* An identifier, with that identifier.
* `s!`, `s as T`, `(s)`, `s..cascadeSection`/`s?..cascadeSection`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `s!`, `s as T`, `(s)`, `s..cascadeSection`/`s?..cascadeSection`
* `s!`, `s as T`, `(s)`, `s..cascadeSection`, and `s?..cascadeSection`

I think this works fine, but it might be helpful to mention (or show in an example) that this admits constructs like id?..m1()..m2() because id?..m1() can play the role as s.

where `s` is a single identifier expression,
and then it has the same identifier as `s`.

More formally, An expression `e` is a single identifier expression with a certain identifier if and only if it is defined as such by the following:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
More formally, An expression `e` is a single identifier expression with a certain identifier if and only if it is defined as such by the following:
An expression `e` is a single identifier expression with a certain identifier if and only if it is defined as such by the following:

then `e` is a single identifier expression with the same identifier as
the `<conditionalExpression>`.

The _name of a named expression_ is then:
Copy link
Member

Choose a reason for hiding this comment

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

In this particular case it's probably more readable to keep using the actual non-terminal:

Suggested change
The _name of a named expression_ is then:
The _name of a_ `<namedExpression>` is then:

The name of a `<namedArgument>` or a named `<recordField>` is the name of
its `<namedExpression>`.


Copy link
Member

Choose a reason for hiding this comment

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

Typo:

Suggested change

it now uses this definition of the name of a `<namedArgument>`.

Where the Record specification for a record literal refers to a field name,
it now uses to this definition.
Copy link
Member

Choose a reason for hiding this comment

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

Typo:

Suggested change
it now uses to this definition.
it now uses this definition.

The identifier expression can be wrapped in casts `!` or `as T`, in parentheses,
or can be pre-used/modified using cascade invocations, but none of those
operations change the value from evaluating the identifier, only, potentially,
whether it evaluates to a value at all.
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps mention prefixed names, and motivate why they aren't included: (name: p.name,) can't be abbreviated to (:p.name,). Presumably it's motivated by the need to insist on "first" in "the name is the first identifier after the colon".

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why a prefixed name is more relevant to mention than, say, a static member or an instance member.

(And "first identifier" is the reason. I'd personally be happy to allow any prefix.id or typeName.id, expression.id or expression?.id, so that's probably why I'm not trying to find an argument for why we don't allow it.)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants