Skip to content

Augmentations should specify allowed partial declarations.Β #3690

Open
@lrhn

Description

@lrhn

Augmentations can add missing pieces to existing declarations. If those missing pieces are required, then the initial declaration is not valid by itself.
The current specification would make that declaration a compile-time error.

Augmentations makes some such declarations still be compile-time errors that apply before augmentations are even applied, and other declarations be only partially declared, and filled in by an augmentation, in which case the property does not apply to the individual declarations, but to the entire declaration+augmentations stack, the "effective declaration".

If that allows a declaration to omit something that would otherwise be required by the grammar, we need to specify the allowed partial syntax too. (#3687 is an example of the augmentation declaration having a different syntax than the main declaration, but not of the main declaration being allowed to omit something it can't omit today).

I'm not absolutely sure there are any cases where augmentations allow omitting something that is otherwise grammatically required, except maybe bodies of functions (which are grammatically allowed to be omitted, because of abstract declarations, but just not in every position - top-level functions cannot grammatically end in ;).

It still means we need to go thrugh every "it's a compile-time error if declaration D ...." and decide whether that applies to the initial declaration syntax, or to the post-augmentation-application effective declaration. (And the latter case would imply that it's a semantic restriction, not a syntactic restriction.)

Some prose-introduced syntax errors are irrecoverable, which probably means being so invalid that applying an augmentation wouldn't make sense anyway. Other errors are not, and should be changed to only apply to the result of augmentation.

Examples:

  • It's definitely and eagerly a compile-time error if a static method has a covariant parameter or a this.x or super.x parameter. We can't augment that, because it has no meaning. Anything that would add a meaning to the declaration that cannot possibly apply to that kind of declaration, should be an eager error.

  • It's possibly not a compile-time error if a static method has a ; body ("no body"), if a later applied augmentation adds a body.

  • It's possibly not a compile-time error if a non-abstract class has an abstract member declaration, if a later augmentation adds a body (but that was never an eager error, because the class could inherit the implementation). Generally, anything related to satisfying an interface is going to be checked late.

  • It's a compile-time error to have a super.foo invocation in an instance function, if the superclass doesn't have a foo member. It's probably allowed if an augmentation adds a superclass that does have a foo. (Which means the check should be written in a way that doesn't point to the surrounding class declaration, but to the semantic superclass of the surrounding class. It probably already is written that way, but we need to check. Everywhere, at least where we say "it's a compile-time error".)

Metadata

Metadata

Assignees

No one assigned

    Labels

    augmentationsIssues related to the augmentations proposal.

    Type

    No type

    Projects

    Status

    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions