Skip to content

Clarify wording of declaration merging as it relates to parent modules and where exactly the merged declaration is visible #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mhegazy opened this issue Aug 26, 2014 · 1 comment
Assignees
Labels
Fixed A PR has been merged for this issue Spec Issues related to the TypeScript language specification

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Aug 26, 2014

Courtesy of @danquirk

The sections on modules and module merging are very subtle, and appear ambiguous. For example, module declaration merging has this to say:

Internal modules are “open-ended” and internal module declarations with the same qualified name relative to a common root (as defined in section 2.3) contribute to a single module.

This has interesting implications. For example, consider the following code:

module M {
   enum E {
      A = 1
   }
}

module M {
   enum E {
      A = 2
   }
}              

The section in the spec about enums says:

Enums are “open-ended” and enum declarations with the same qualified name relative to a common root (as defined in section 2.3) define a single enum type and contribute to a single enum object.

Section 2.3 then says:

The root module of an entity is defined as follows:
• The root module of a non-exported entity is the entity’s parent module.

These are non exported enums. So their root module is their parent module.

The parent module of an entity is defined as follows:
• The parent module of an entity declared in an internal module is that internal module.

So the parent module of the first E is the module M. So is the parent model of the second E. From the section on module merging, we know these are the same module. So both E’s have the same root module. They also have the same qualified name. Ergo, according to the sec, they should be merged. The implementation currently does not do this and we're unclear what the intention is.

@mhegazy mhegazy added the Spec label Aug 26, 2014
@mhegazy mhegazy added the Bug A bug in TypeScript label Mar 24, 2015
@mhegazy mhegazy added this to the TypeScript 1.6 milestone Mar 24, 2015
@mhegazy mhegazy removed the Bug A bug in TypeScript label May 27, 2015
@ahejlsberg
Copy link
Member

Fixed in #4033.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Aug 5, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue Spec Issues related to the TypeScript language specification
Projects
None yet
Development

No branches or pull requests

2 participants