-
Notifications
You must be signed in to change notification settings - Fork 228
Description
In #4623, the idea is to widen the grammar to ensure that augmentations are allowed to contain pretty much any kind of variable/getter/setter declaration. The semantic restrictions around not being able to augment an already complete declaration remain, but syntactically, the grammar allows you to write just about everything.
There is an important restriction in the language that some variables must be initialized at their declaration. @eernstg can correct me if I get this wrong, but I think the rules are:
If the variable is:
- top-level or a static field,
- and it's
finalorconst, - and it's not
late,
Then it needs to have an initializer. (Local const declarations also need initializers, but those aren't affected by augmentations.)
It looks like the behavior is currently captured in the spec outside of the grammar:
A compile-time error occurs if a static or library variable has no initializing ⊖
expression and a type which is not nullable (??), unless the variable declaration
has the modifier late or the modifier external.
A constant variable is a variable whose declaration includes the modifier △
const. A constant variable must be initialized to a constant expression (17.3),
or a compile-time error occurs.
So I don't think there's anything we need to do for augmentations. But it might be worth pointing out in the augmentations spec that this restriction remains.