From fddc2253d7e22d19925698f3b6abfd69530cc620 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Tue, 30 Dec 2014 10:48:44 -0800 Subject: [PATCH 01/11] fixed checker and added a test case --- src/compiler/checker.ts | 11 ++++++++++- .../cases/compiler/differentTypesWithSameName.ts | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/cases/compiler/differentTypesWithSameName.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f8c4caa963..d835a444d3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3508,7 +3508,16 @@ module ts { } if (reportErrors) { headMessage = headMessage || Diagnostics.Type_0_is_not_assignable_to_type_1; - reportError(headMessage, typeToString(source), typeToString(target)); + var sourceType = typeToString(source); + var targetType = typeToString(target); + if (sourceType !== targetType) { + reportError(headMessage, sourceType, targetType); + } else { + // If the types are incompatible but have the same name, use the qualified names to give + // a more insightful error message + reportError(headMessage, getFullyQualifiedName(source.symbol), getFullyQualifiedName(target.symbol)); + } + //reportError(headMessage, typeToString(source), typeToString(target)); } return Ternary.False; } diff --git a/tests/cases/compiler/differentTypesWithSameName.ts b/tests/cases/compiler/differentTypesWithSameName.ts new file mode 100644 index 0000000000..2b40e23c64 --- /dev/null +++ b/tests/cases/compiler/differentTypesWithSameName.ts @@ -0,0 +1,16 @@ +module m { + export class variable{ + s: string; + } + export function doSomething(v: m.variable) { + + } +} + +class variable { + t: number; +} + + +var v: variable = new variable(); +m.doSomething(v); \ No newline at end of file From 82fcaa852c4a09481aee5a8aaa566dea22e2ecee Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Tue, 30 Dec 2014 10:50:07 -0800 Subject: [PATCH 02/11] added baselines for new test case --- .../differentTypesWithSameName.errors.txt | 22 +++++++++++ .../reference/differentTypesWithSameName.js | 38 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/baselines/reference/differentTypesWithSameName.errors.txt create mode 100644 tests/baselines/reference/differentTypesWithSameName.js diff --git a/tests/baselines/reference/differentTypesWithSameName.errors.txt b/tests/baselines/reference/differentTypesWithSameName.errors.txt new file mode 100644 index 0000000000..c451fcab1f --- /dev/null +++ b/tests/baselines/reference/differentTypesWithSameName.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/differentTypesWithSameName.ts(16,15): error TS2345: Argument of type 'variable' is not assignable to parameter of type 'm.variable'. + + +==== tests/cases/compiler/differentTypesWithSameName.ts (1 errors) ==== + module m { + export class variable{ + s: string; + } + export function doSomething(v: m.variable) { + + } + } + + class variable { + t: number; + } + + + var v: variable = new variable(); + m.doSomething(v); + ~ +!!! error TS2345: Argument of type 'variable' is not assignable to parameter of type 'm.variable'. \ No newline at end of file diff --git a/tests/baselines/reference/differentTypesWithSameName.js b/tests/baselines/reference/differentTypesWithSameName.js new file mode 100644 index 0000000000..7ee0b6bf02 --- /dev/null +++ b/tests/baselines/reference/differentTypesWithSameName.js @@ -0,0 +1,38 @@ +//// [differentTypesWithSameName.ts] +module m { + export class variable{ + s: string; + } + export function doSomething(v: m.variable) { + + } +} + +class variable { + t: number; +} + + +var v: variable = new variable(); +m.doSomething(v); + +//// [differentTypesWithSameName.js] +var m; +(function (m) { + var variable = (function () { + function variable() { + } + return variable; + })(); + m.variable = variable; + function doSomething(v) { + } + m.doSomething = doSomething; +})(m || (m = {})); +var variable = (function () { + function variable() { + } + return variable; +})(); +var v = new variable(); +m.doSomething(v); From 07d3c204d5b691db84b5b53272fa9a5453754f5b Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Tue, 30 Dec 2014 11:06:56 -0800 Subject: [PATCH 03/11] updating baseines --- .../reference/clodulesDerivedClasses.errors.txt | 4 ++-- ...ypeWithAnnotationAndInvalidInitializer.errors.txt | 12 ++++++------ tests/baselines/reference/qualify.errors.txt | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/baselines/reference/clodulesDerivedClasses.errors.txt b/tests/baselines/reference/clodulesDerivedClasses.errors.txt index 1753f6051b..c4f1e1ac42 100644 --- a/tests/baselines/reference/clodulesDerivedClasses.errors.txt +++ b/tests/baselines/reference/clodulesDerivedClasses.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/clodulesDerivedClasses.ts(9,7): error TS2417: Class static side 'typeof Path' incorrectly extends base class static side 'typeof Shape'. Types of property 'Utils' are incompatible. - Type 'typeof Utils' is not assignable to type 'typeof Utils'. + Type 'Path.Utils' is not assignable to type 'Shape.Utils'. Property 'convert' is missing in type 'typeof Utils'. @@ -17,7 +17,7 @@ tests/cases/compiler/clodulesDerivedClasses.ts(9,7): error TS2417: Class static ~~~~ !!! error TS2417: Class static side 'typeof Path' incorrectly extends base class static side 'typeof Shape'. !!! error TS2417: Types of property 'Utils' are incompatible. -!!! error TS2417: Type 'typeof Utils' is not assignable to type 'typeof Utils'. +!!! error TS2417: Type 'Path.Utils' is not assignable to type 'Shape.Utils'. !!! error TS2417: Property 'convert' is missing in type 'typeof Utils'. name: string; diff --git a/tests/baselines/reference/everyTypeWithAnnotationAndInvalidInitializer.errors.txt b/tests/baselines/reference/everyTypeWithAnnotationAndInvalidInitializer.errors.txt index 4ebb93b10a..1219067ce1 100644 --- a/tests/baselines/reference/everyTypeWithAnnotationAndInvalidInitializer.errors.txt +++ b/tests/baselines/reference/everyTypeWithAnnotationAndInvalidInitializer.errors.txt @@ -25,10 +25,10 @@ tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAnd Type 'string' is not assignable to type 'number'. tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(50,5): error TS2322: Type 'typeof N' is not assignable to type 'typeof M'. Types of property 'A' are incompatible. - Type 'typeof A' is not assignable to type 'typeof A'. - Type 'A' is not assignable to type 'A'. + Type 'N.A' is not assignable to type 'M.A'. + Type 'N.A' is not assignable to type 'M.A'. Property 'name' is missing in type 'A'. -tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(51,5): error TS2322: Type 'A' is not assignable to type 'A'. +tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(51,5): error TS2322: Type 'N.A' is not assignable to type 'M.A'. tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(52,5): error TS2322: Type '(x: number) => boolean' is not assignable to type '(x: number) => string'. Type 'boolean' is not assignable to type 'string'. @@ -124,12 +124,12 @@ tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAnd ~~~~~~~ !!! error TS2322: Type 'typeof N' is not assignable to type 'typeof M'. !!! error TS2322: Types of property 'A' are incompatible. -!!! error TS2322: Type 'typeof A' is not assignable to type 'typeof A'. -!!! error TS2322: Type 'A' is not assignable to type 'A'. +!!! error TS2322: Type 'N.A' is not assignable to type 'M.A'. +!!! error TS2322: Type 'N.A' is not assignable to type 'M.A'. !!! error TS2322: Property 'name' is missing in type 'A'. var aClassInModule: M.A = new N.A(); ~~~~~~~~~~~~~~ -!!! error TS2322: Type 'A' is not assignable to type 'A'. +!!! error TS2322: Type 'N.A' is not assignable to type 'M.A'. var aFunctionInModule: typeof M.F2 = F2; ~~~~~~~~~~~~~~~~~ !!! error TS2322: Type '(x: number) => boolean' is not assignable to type '(x: number) => string'. diff --git a/tests/baselines/reference/qualify.errors.txt b/tests/baselines/reference/qualify.errors.txt index a2f59733fa..c7679a0a0f 100644 --- a/tests/baselines/reference/qualify.errors.txt +++ b/tests/baselines/reference/qualify.errors.txt @@ -10,7 +10,7 @@ tests/cases/compiler/qualify.ts(47,13): error TS2322: Type 'I4' is not assignabl tests/cases/compiler/qualify.ts(48,13): error TS2322: Type 'I4' is not assignable to type '(k: I3) => void'. tests/cases/compiler/qualify.ts(49,13): error TS2322: Type 'I4' is not assignable to type '{ k: I3; }'. Property 'k' is missing in type 'I4'. -tests/cases/compiler/qualify.ts(58,5): error TS2322: Type 'I' is not assignable to type 'I'. +tests/cases/compiler/qualify.ts(58,5): error TS2322: Type 'I' is not assignable to type 'T.I'. Property 'p' is missing in type 'I'. @@ -93,7 +93,7 @@ tests/cases/compiler/qualify.ts(58,5): error TS2322: Type 'I' is not assignable var y:I; var x:T.I=y; ~ -!!! error TS2322: Type 'I' is not assignable to type 'I'. +!!! error TS2322: Type 'I' is not assignable to type 'T.I'. !!! error TS2322: Property 'p' is missing in type 'I'. \ No newline at end of file From 5838900b19662f37ba04d1c460f8b858ec2bafa5 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Tue, 30 Dec 2014 11:08:22 -0800 Subject: [PATCH 04/11] remove commented out code --- src/compiler/checker.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d835a444d3..b5b34686b8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3482,7 +3482,7 @@ module ts { } } } - else if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) { + else if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) {getFullyQualifiedName if (result = typeParameterRelatedTo(source, target, reportErrors)) { return result; } @@ -3517,7 +3517,6 @@ module ts { // a more insightful error message reportError(headMessage, getFullyQualifiedName(source.symbol), getFullyQualifiedName(target.symbol)); } - //reportError(headMessage, typeToString(source), typeToString(target)); } return Ternary.False; } From 3b55a0cca444ef363fc13082f86f6cb593b2014d Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Tue, 30 Dec 2014 11:10:02 -0800 Subject: [PATCH 05/11] removed errant text --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b5b34686b8..07f1728ffa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3482,7 +3482,7 @@ module ts { } } } - else if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) {getFullyQualifiedName + else if (source.flags & TypeFlags.TypeParameter && target.flags & TypeFlags.TypeParameter) { if (result = typeParameterRelatedTo(source, target, reportErrors)) { return result; } From 8808a692e5b8f1da68a1e4c00f8014b9440d4ffe Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Fri, 2 Jan 2015 11:04:00 -0800 Subject: [PATCH 06/11] rewrote the fix to use a new type format flag and fixed the baselines I broke --- src/compiler/checker.ts | 24 +++++++++---------- src/compiler/types.ts | 1 + .../clodulesDerivedClasses.errors.txt | 4 ++-- ...AnnotationAndInvalidInitializer.errors.txt | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 07f1728ffa..9052baaab7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1033,7 +1033,7 @@ module ts { * Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope * Meaning needs to be specified if the enclosing declaration is given */ - function buildSymbolDisplay(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void { + function buildSymbolDisplay(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags, typeFlags?: TypeFormatFlags): void { var parentSymbol: Symbol; function appendParentTypeArgumentsAndSymbolName(symbol: Symbol): void { if (parentSymbol) { @@ -1096,9 +1096,11 @@ module ts { } // Get qualified name - if (enclosingDeclaration && + if ((enclosingDeclaration && // TypeParameters do not need qualification - !(symbol.flags & SymbolFlags.TypeParameter)) { + !(symbol.flags & SymbolFlags.TypeParameter)) + // unless we use a format flag specifying that we want it + || TypeFormatFlags.UseFullyQualifiedType & typeFlags) { walkSymbol(symbol, meaning); return; @@ -1122,7 +1124,7 @@ module ts { writeTypeReference(type, flags); } else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { - buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, undefined, flags); } else if (type.flags & TypeFlags.Tuple) { writeTupleType(type); @@ -1193,17 +1195,17 @@ module ts { function writeAnonymousType(type: ObjectType, flags: TypeFormatFlags) { // Always use 'typeof T' for type of class, enum, and module objects if (type.symbol && type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) { - writeTypeofSymbol(type); + writeTypeofSymbol(type, flags); } // Use 'typeof T' for types of functions and methods that circularly reference themselves else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type); + writeTypeofSymbol(type, flags); } else if (typeStack && contains(typeStack, type)) { // If type is an anonymous type literal in a type alias declaration, use type alias name var typeAlias = getTypeAliasForTypeLiteral(type); if (typeAlias) { - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type); + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, undefined, flags); } else { // Recursive usage, use any @@ -1237,10 +1239,10 @@ module ts { } } - function writeTypeofSymbol(type: ObjectType) { + function writeTypeofSymbol(type: ObjectType, flags?: TypeFormatFlags) { writeKeyword(writer, SyntaxKind.TypeOfKeyword); writeSpace(writer); - buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, undefined, flags); } function getIndexerParameterName(type: ObjectType, indexKind: IndexKind, fallbackName: string): string { @@ -3513,9 +3515,7 @@ module ts { if (sourceType !== targetType) { reportError(headMessage, sourceType, targetType); } else { - // If the types are incompatible but have the same name, use the qualified names to give - // a more insightful error message - reportError(headMessage, getFullyQualifiedName(source.symbol), getFullyQualifiedName(target.symbol)); + reportError(headMessage, typeToString(source, undefined, TypeFormatFlags.UseFullyQualifiedType), typeToString(target, undefined, TypeFormatFlags.UseFullyQualifiedType)); } } return Ternary.False; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 60ed8352b9..ff15b3a9e1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1074,6 +1074,7 @@ module ts { WriteOwnNameForAnyLike = 0x00000010, // Write symbol's own name instead of 'any' for any like types (eg. unknown, __resolving__ etc) WriteTypeArgumentsOfSignature = 0x00000020, // Write the type arguments instead of type parameters of the signature InElementType = 0x00000040, // Writing an array or union element type + UseFullyQualifiedType = 0x00000080, // Write out the fully qualified type name (eg. Module.Type, instead of Type) } export const enum SymbolFormatFlags { diff --git a/tests/baselines/reference/clodulesDerivedClasses.errors.txt b/tests/baselines/reference/clodulesDerivedClasses.errors.txt index c4f1e1ac42..c3866c9e4b 100644 --- a/tests/baselines/reference/clodulesDerivedClasses.errors.txt +++ b/tests/baselines/reference/clodulesDerivedClasses.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/clodulesDerivedClasses.ts(9,7): error TS2417: Class static side 'typeof Path' incorrectly extends base class static side 'typeof Shape'. Types of property 'Utils' are incompatible. - Type 'Path.Utils' is not assignable to type 'Shape.Utils'. + Type 'typeof Path.Utils' is not assignable to type 'typeof Shape.Utils'. Property 'convert' is missing in type 'typeof Utils'. @@ -17,7 +17,7 @@ tests/cases/compiler/clodulesDerivedClasses.ts(9,7): error TS2417: Class static ~~~~ !!! error TS2417: Class static side 'typeof Path' incorrectly extends base class static side 'typeof Shape'. !!! error TS2417: Types of property 'Utils' are incompatible. -!!! error TS2417: Type 'Path.Utils' is not assignable to type 'Shape.Utils'. +!!! error TS2417: Type 'typeof Path.Utils' is not assignable to type 'typeof Shape.Utils'. !!! error TS2417: Property 'convert' is missing in type 'typeof Utils'. name: string; diff --git a/tests/baselines/reference/everyTypeWithAnnotationAndInvalidInitializer.errors.txt b/tests/baselines/reference/everyTypeWithAnnotationAndInvalidInitializer.errors.txt index 1219067ce1..1247844247 100644 --- a/tests/baselines/reference/everyTypeWithAnnotationAndInvalidInitializer.errors.txt +++ b/tests/baselines/reference/everyTypeWithAnnotationAndInvalidInitializer.errors.txt @@ -25,7 +25,7 @@ tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAnd Type 'string' is not assignable to type 'number'. tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(50,5): error TS2322: Type 'typeof N' is not assignable to type 'typeof M'. Types of property 'A' are incompatible. - Type 'N.A' is not assignable to type 'M.A'. + Type 'typeof N.A' is not assignable to type 'typeof M.A'. Type 'N.A' is not assignable to type 'M.A'. Property 'name' is missing in type 'A'. tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAndInvalidInitializer.ts(51,5): error TS2322: Type 'N.A' is not assignable to type 'M.A'. @@ -124,7 +124,7 @@ tests/cases/conformance/statements/VariableStatements/everyTypeWithAnnotationAnd ~~~~~~~ !!! error TS2322: Type 'typeof N' is not assignable to type 'typeof M'. !!! error TS2322: Types of property 'A' are incompatible. -!!! error TS2322: Type 'N.A' is not assignable to type 'M.A'. +!!! error TS2322: Type 'typeof N.A' is not assignable to type 'typeof M.A'. !!! error TS2322: Type 'N.A' is not assignable to type 'M.A'. !!! error TS2322: Property 'name' is missing in type 'A'. var aClassInModule: M.A = new N.A(); From f39a25b659cadfa5cd281185990adf06469610ae Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Mon, 5 Jan 2015 08:31:04 -0800 Subject: [PATCH 07/11] made some changes based cr feedback --- src/compiler/checker.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9052baaab7..e79aa6e8fb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1095,13 +1095,11 @@ module ts { } } - // Get qualified name - if ((enclosingDeclaration && - // TypeParameters do not need qualification - !(symbol.flags & SymbolFlags.TypeParameter)) - // unless we use a format flag specifying that we want it - || TypeFormatFlags.UseFullyQualifiedType & typeFlags) { - + // Get qualified name if there is an enclosing declaration and it is not a + // type parameter or we have a flag telling us to + var needFullyQualifiedName = (enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)); + var useFullyQualifiedFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags; + if (needFullyQualifiedName || useFullyQualifiedFlag) { walkSymbol(symbol, meaning); return; } @@ -1124,7 +1122,7 @@ module ts { writeTypeReference(type, flags); } else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { - buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, undefined, flags); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, /*flags*/ undefined, flags); } else if (type.flags & TypeFlags.Tuple) { writeTupleType(type); @@ -1205,7 +1203,7 @@ module ts { // If type is an anonymous type literal in a type alias declaration, use type alias name var typeAlias = getTypeAliasForTypeLiteral(type); if (typeAlias) { - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, undefined, flags); + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, /*flags*/ undefined, flags); } else { // Recursive usage, use any @@ -1242,7 +1240,7 @@ module ts { function writeTypeofSymbol(type: ObjectType, flags?: TypeFormatFlags) { writeKeyword(writer, SyntaxKind.TypeOfKeyword); writeSpace(writer); - buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, undefined, flags); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, /*flags*/ undefined, flags); } function getIndexerParameterName(type: ObjectType, indexKind: IndexKind, fallbackName: string): string { @@ -3512,11 +3510,11 @@ module ts { headMessage = headMessage || Diagnostics.Type_0_is_not_assignable_to_type_1; var sourceType = typeToString(source); var targetType = typeToString(target); - if (sourceType !== targetType) { - reportError(headMessage, sourceType, targetType); - } else { - reportError(headMessage, typeToString(source, undefined, TypeFormatFlags.UseFullyQualifiedType), typeToString(target, undefined, TypeFormatFlags.UseFullyQualifiedType)); + if (sourceType === targetType) { + sourceType = typeToString(source, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType); + targetType = typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType); } + reportError(headMessage, sourceType, targetType); } return Ternary.False; } From 52a6ba69a18d92ebae65e2680d22c516efa7a8d0 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Thu, 8 Jan 2015 13:42:01 -0800 Subject: [PATCH 08/11] changed logic based on CR feedback to not get fully qualified for typeparemeters even if typeformatflag is present --- src/compiler/checker.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e79aa6e8fb..239d9138ea 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1095,11 +1095,11 @@ module ts { } } - // Get qualified name if there is an enclosing declaration and it is not a - // type parameter or we have a flag telling us to - var needFullyQualifiedName = (enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)); - var useFullyQualifiedFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags; - if (needFullyQualifiedName || useFullyQualifiedFlag) { + // Get qualified name if the symbol is not a type parameter + // and we have an enclosing declaration or a typeformat flag + var typeParameter = (symbol.flags & SymbolFlags.TypeParameter); + var typeFormatFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags; + if (!typeParameter && (enclosingDeclaration || typeFormatFlag)) { walkSymbol(symbol, meaning); return; } From ce794e8b099f3a96cc3635a4f4046b019c0c0358 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Mon, 12 Jan 2015 07:45:49 -0800 Subject: [PATCH 09/11] more cr feedback: rename undefined flags param to None --- src/compiler/checker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 239d9138ea..0e8435fd48 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1096,7 +1096,7 @@ module ts { } // Get qualified name if the symbol is not a type parameter - // and we have an enclosing declaration or a typeformat flag + // and we spe var typeParameter = (symbol.flags & SymbolFlags.TypeParameter); var typeFormatFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags; if (!typeParameter && (enclosingDeclaration || typeFormatFlag)) { @@ -1122,7 +1122,7 @@ module ts { writeTypeReference(type, flags); } else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { - buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, /*flags*/ undefined, flags); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, /*flags*/ None, flags); } else if (type.flags & TypeFlags.Tuple) { writeTupleType(type); @@ -1203,7 +1203,7 @@ module ts { // If type is an anonymous type literal in a type alias declaration, use type alias name var typeAlias = getTypeAliasForTypeLiteral(type); if (typeAlias) { - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, /*flags*/ undefined, flags); + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, /*flags*/ None, flags); } else { // Recursive usage, use any @@ -1240,7 +1240,7 @@ module ts { function writeTypeofSymbol(type: ObjectType, flags?: TypeFormatFlags) { writeKeyword(writer, SyntaxKind.TypeOfKeyword); writeSpace(writer); - buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, /*flags*/ undefined, flags); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, /*flags*/ None, flags); } function getIndexerParameterName(type: ObjectType, indexKind: IndexKind, fallbackName: string): string { From d35757d1c53e2c68ca760e602e5fb721d2db3900 Mon Sep 17 00:00:00 2001 From: ChrisBubernak Date: Tue, 20 Jan 2015 11:20:27 -0800 Subject: [PATCH 10/11] fixing error in last checkin --- src/compiler/checker.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0e8435fd48..1bcc4cbcf2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1096,7 +1096,8 @@ module ts { } // Get qualified name if the symbol is not a type parameter - // and we spe + // and there is an enclosing declaration or we specifically + // asked for it var typeParameter = (symbol.flags & SymbolFlags.TypeParameter); var typeFormatFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags; if (!typeParameter && (enclosingDeclaration || typeFormatFlag)) { @@ -1122,7 +1123,7 @@ module ts { writeTypeReference(type, flags); } else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { - buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, /*flags*/ None, flags); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags); } else if (type.flags & TypeFlags.Tuple) { writeTupleType(type); @@ -1203,7 +1204,7 @@ module ts { // If type is an anonymous type literal in a type alias declaration, use type alias name var typeAlias = getTypeAliasForTypeLiteral(type); if (typeAlias) { - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, /*flags*/ None, flags); + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags); } else { // Recursive usage, use any @@ -1240,7 +1241,7 @@ module ts { function writeTypeofSymbol(type: ObjectType, flags?: TypeFormatFlags) { writeKeyword(writer, SyntaxKind.TypeOfKeyword); writeSpace(writer); - buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, /*flags*/ None, flags); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, SymbolFormatFlags.None, flags); } function getIndexerParameterName(type: ObjectType, indexKind: IndexKind, fallbackName: string): string { From afc9f45468238e086d2d2fc5a6986ff7c30b9841 Mon Sep 17 00:00:00 2001 From: Chris Bubernak Date: Sat, 24 Jan 2015 08:50:01 -0800 Subject: [PATCH 11/11] more changes based on CR feedback --- src/compiler/checker.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1bcc4cbcf2..c3b3ae9ed2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1097,10 +1097,10 @@ module ts { // Get qualified name if the symbol is not a type parameter // and there is an enclosing declaration or we specifically - // asked for it - var typeParameter = (symbol.flags & SymbolFlags.TypeParameter); + // asked for it + var isTypeParameter = symbol.flags & SymbolFlags.TypeParameter; var typeFormatFlag = TypeFormatFlags.UseFullyQualifiedType & typeFlags; - if (!typeParameter && (enclosingDeclaration || typeFormatFlag)) { + if (!isTypeParameter && (enclosingDeclaration || typeFormatFlag)) { walkSymbol(symbol, meaning); return; } @@ -1123,6 +1123,7 @@ module ts { writeTypeReference(type, flags); } else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { + // The specified symbol flags need to be reinterpreted as type flags buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags); } else if (type.flags & TypeFlags.Tuple) { @@ -1204,6 +1205,7 @@ module ts { // If type is an anonymous type literal in a type alias declaration, use type alias name var typeAlias = getTypeAliasForTypeLiteral(type); if (typeAlias) { + // The specified symbol flags need to be reinterpreted as type flags buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags); } else { @@ -1238,10 +1240,10 @@ module ts { } } - function writeTypeofSymbol(type: ObjectType, flags?: TypeFormatFlags) { + function writeTypeofSymbol(type: ObjectType, typeFormatFlags?: TypeFormatFlags) { writeKeyword(writer, SyntaxKind.TypeOfKeyword); writeSpace(writer); - buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, SymbolFormatFlags.None, flags); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Value, SymbolFormatFlags.None, typeFormatFlags); } function getIndexerParameterName(type: ObjectType, indexKind: IndexKind, fallbackName: string): string {