-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
[Note that for clarity, the code links below point to the code as of this writing, not the code at HEAD when you're reading.]
Currently the toolchain parses an associated constant declaration just like any other let
declaration, even though associated constants have a different grammar: the pattern must be a single symbolic binding pattern (i.e. "name :!
type"), and it can't have an initializer (we don't support default let
at all yet). Instead, we enforce those restrictions in the check phase, where the handler for a symbolic binding is special-cased to have entirely different behavior when it's inside an interface
. The handler for let
is similarly special-cased, but it's dispersed throughout the file instead of a single discrete branch.
We used to have a similar situation for class field declarations, but #5320 fixed it by having the parser enforce the restricted grammar, and emit different parse node kinds for class field declarations than for other var
declarations, so that they are processed by separate handlers and don't have to share code with ordinary var
declarations.
For consistency with var
, as well as for overall clarity and simplicity, we should handle associated constants the same way we handle class fields.