Skip to content

Commit e27e6b2

Browse files
committed
During qualification if we are looking in value space, the left qualifier meaning is also value
1 parent 09ea12d commit e27e6b2

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,11 @@ module ts {
661661
return callback(globals);
662662
}
663663

664+
function getQualifiedLeftMeaning(rightMeaning: SymbolFlags) {
665+
// If we are looking in value space, the parent meaning is value, other wise it is namespace
666+
return rightMeaning === SymbolFlags.Value ? SymbolFlags.Value : SymbolFlags.Namespace;
667+
}
668+
664669
function getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): Symbol[] {
665670
function getAccessibleSymbolChainFromSymbolTable(symbols: SymbolTable): Symbol[] {
666671
function canQualifySymbol(symbolFromSymbolTable: Symbol, meaning: SymbolFlags) {
@@ -670,7 +675,7 @@ module ts {
670675
}
671676

672677
// If symbol needs qualification, make sure that parent is accessible, if it is then this symbol is accessible too
673-
var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, SymbolFlags.Namespace);
678+
var accessibleParent = getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning));
674679
return !!accessibleParent;
675680
}
676681

@@ -698,7 +703,7 @@ module ts {
698703
// Look in the exported members, if we can find accessibleSymbolChain, symbol is accessible using this chain
699704
// but only if the symbolFromSymbolTable can be qualified
700705
var accessibleSymbolsFromExports = resolvedImportedSymbol.exports ? getAccessibleSymbolChainFromSymbolTable(resolvedImportedSymbol.exports) : undefined;
701-
if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, SymbolFlags.Namespace)) {
706+
if (accessibleSymbolsFromExports && canQualifySymbol(symbolFromSymbolTable, getQualifiedLeftMeaning(meaning))) {
702707
return [symbolFromSymbolTable].concat(accessibleSymbolsFromExports);
703708
}
704709
}
@@ -758,8 +763,6 @@ module ts {
758763
return { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible: hasAccessibleDeclarations.aliasesToMakeVisible };
759764
}
760765

761-
// TODO(shkamat): Handle static method of class
762-
763766
// If we havent got the accessible symbol doesnt mean the symbol is actually inaccessible.
764767
// It could be qualified symbol and hence verify the path
765768
// eg:
@@ -772,7 +775,7 @@ module ts {
772775
// we are going to see if c can be accessed in scope directly.
773776
// But it cant, hence the accessible is going to be undefined, but that doesnt mean m.c is accessible
774777
// It is accessible if the parent m is accessible because then m.c can be accessed through qualification
775-
meaningToLook = SymbolFlags.Namespace;
778+
meaningToLook = getQualifiedLeftMeaning(meaning);
776779
symbol = symbol.parent;
777780
}
778781

@@ -851,14 +854,14 @@ module ts {
851854
var symbolName: string;
852855
while (symbol) {
853856
var isFirstName = !symbolName;
854-
var meaningToLook = isFirstName ? meaning : SymbolFlags.Namespace;
855-
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook);
857+
var accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaning);
856858
var currentSymbolName = accessibleSymbolChain ? ts.map(accessibleSymbolChain, accessibleSymbol => getSymbolName(accessibleSymbol)).join(".") : getSymbolName(symbol);
857859
symbolName = currentSymbolName + (isFirstName ? "" : ("." + symbolName));
858-
if (accessibleSymbolChain && !needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaningToLook : SymbolFlags.Namespace)) {
860+
if (accessibleSymbolChain && !needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
859861
break;
860862
}
861863
symbol = accessibleSymbolChain ? accessibleSymbolChain[0].parent : symbol.parent;
864+
meaning = getQualifiedLeftMeaning(meaning);
862865
}
863866

864867
return symbolName;

tests/baselines/reference/declarationEmit_nameConflicts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export declare module M.P {
172172
var a: typeof M.f;
173173
var b: typeof M.C;
174174
var c: typeof M.N;
175-
var g: typeof c.g;
175+
var g: typeof M.c.g;
176176
var d: typeof M.d;
177177
}
178178
export declare module M.Q {

tests/baselines/reference/declarationEmit_nameConflicts3.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ module M.P {
2020
export enum D {
2121
f
2222
}
23-
// Bug 887180
2423
export var v: M.D; // ok
2524
export var w = M.D.f; // error, should be typeof M.D.f
2625
export var x = M.C.f; // error, should be typeof M.C.f
@@ -111,7 +110,7 @@ declare module M.P {
111110
f = 0,
112111
}
113112
var v: M.D;
114-
var w: typeof D.f;
115-
var x: typeof C.f;
116-
var x: typeof C.f;
113+
var w: typeof M.D.f;
114+
var x: typeof M.C.f;
115+
var x: typeof M.C.f;
117116
}

tests/cases/compiler/declarationEmit_nameConflicts3.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module M.P {
2121
export enum D {
2222
f
2323
}
24-
// Bug 887180
2524
export var v: M.D; // ok
2625
export var w = M.D.f; // error, should be typeof M.D.f
2726
export var x = M.C.f; // error, should be typeof M.C.f

0 commit comments

Comments
 (0)