From fa9b6fcb0708d9a90f3d537198107abbe235627b Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Tue, 2 Jun 2015 17:34:34 -0700 Subject: [PATCH] fixed loops, merged baseline --- src/compiler/checker.ts | 27 +++++---------- .../classAndInterfaceMerge.d.errors.txt | 4 +-- ...IdentifiersAcrossFileBoundaries.errors.txt | 11 +++--- ...uplicateIdentifiersAcrossFileBoundaries.js | 34 +++++++++++++++++++ 4 files changed, 50 insertions(+), 26 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4a65b3503d..36012af42a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10403,12 +10403,8 @@ module ts { } // Non-ambient classes cannot merge with interfaces. - if (!(node.flags & NodeFlags.Ambient)) { - if (forEach(symbol.declarations, (element: Declaration) => { - return element.kind === SyntaxKind.InterfaceDeclaration; - })) { - error(node, Diagnostics.A_non_ambient_class_cannot_be_merged_with_an_interface) - } + if (!(node.flags & NodeFlags.Ambient) && getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration)) { + error(node, Diagnostics.A_non_ambient_class_cannot_be_merged_with_an_interface) } forEach(node.members, checkSourceElement); @@ -10562,15 +10558,6 @@ module ts { return ok; } - /** - * Checks if the symbol contains a class declaration that is non-ambient. - */ - function hasNonAmbientClass(symbol: Symbol): boolean { - return symbol && forEach(symbol.declarations, (element: Declaration) => { - return element.kind === SyntaxKind.ClassDeclaration && !(element.flags & NodeFlags.Ambient); - }); - } - function checkInterfaceDeclaration(node: InterfaceDeclaration) { // Grammar checking checkGrammarDeclarationNameInStrictMode(node) || checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); @@ -10600,10 +10587,12 @@ module ts { } } - // Interfaces cannot merge with non-ambient classes. - if (!(node.flags & NodeFlags.Ambient)) { - if (hasNonAmbientClass(symbol)) { - error(node, Diagnostics.An_interface_cannot_merge_with_a_non_ambient_class); + if (symbol && symbol.declarations) { + for (let declaration of symbol.declarations) { + if (declaration.kind === SyntaxKind.ClassDeclaration && !(declaration.flags & NodeFlags.Ambient)) { + error(node, Diagnostics.An_interface_cannot_merge_with_a_non_ambient_class); + break; + } } } } diff --git a/tests/baselines/reference/classAndInterfaceMerge.d.errors.txt b/tests/baselines/reference/classAndInterfaceMerge.d.errors.txt index d4afe3bc7c..d73e5fcb2f 100644 --- a/tests/baselines/reference/classAndInterfaceMerge.d.errors.txt +++ b/tests/baselines/reference/classAndInterfaceMerge.d.errors.txt @@ -17,7 +17,7 @@ tests/cases/conformance/classes/classDeclarations/classAndInterfaceMerge.d.ts(24 interface C { } declare module M { - + interface C1 { } ~~ !!! error TS2507: An interface cannot merge with a non-ambient class. @@ -33,7 +33,7 @@ tests/cases/conformance/classes/classDeclarations/classAndInterfaceMerge.d.ts(24 interface C1 { } ~~ !!! error TS2507: An interface cannot merge with a non-ambient class. - + export class C2 { } ~~ !!! error TS2506: A non-ambient class cannot be merged with an interface. diff --git a/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.errors.txt b/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.errors.txt index 0febfd77ec..bd22333066 100644 --- a/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.errors.txt +++ b/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.errors.txt @@ -1,8 +1,8 @@ -tests/cases/compiler/file1.ts(1,11): error TS2507: An interface cannot merge with a non-ambient class. -tests/cases/compiler/file1.ts(2,7): error TS2506: A non-ambient class cannot be merged with an interface. -tests/cases/compiler/file1.ts(3,7): error TS2300: Duplicate identifier 'C2'. -tests/cases/compiler/file1.ts(4,10): error TS2300: Duplicate identifier 'f'. -tests/cases/compiler/file1.ts(8,12): error TS2300: Duplicate identifier 'x'. +tests/cases/compiler/file1.ts(2,11): error TS2507: An interface cannot merge with a non-ambient class. +tests/cases/compiler/file1.ts(3,7): error TS2506: A non-ambient class cannot be merged with an interface. +tests/cases/compiler/file1.ts(4,7): error TS2300: Duplicate identifier 'C2'. +tests/cases/compiler/file1.ts(5,10): error TS2300: Duplicate identifier 'f'. +tests/cases/compiler/file1.ts(9,12): error TS2300: Duplicate identifier 'x'. tests/cases/compiler/file2.ts(1,7): error TS2506: A non-ambient class cannot be merged with an interface. tests/cases/compiler/file2.ts(2,11): error TS2507: An interface cannot merge with a non-ambient class. tests/cases/compiler/file2.ts(3,10): error TS2300: Duplicate identifier 'C2'. @@ -12,6 +12,7 @@ tests/cases/compiler/file2.ts(8,16): error TS2300: Duplicate identifier 'x'. ==== tests/cases/compiler/file1.ts (5 errors) ==== + interface I { } ~ !!! error TS2507: An interface cannot merge with a non-ambient class. diff --git a/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.js b/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.js index f6e3a5652e..a2509ea97f 100644 --- a/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.js +++ b/tests/baselines/reference/duplicateIdentifiersAcrossFileBoundaries.js @@ -1,6 +1,7 @@ //// [tests/cases/compiler/duplicateIdentifiersAcrossFileBoundaries.ts] //// //// [file1.ts] + interface I { } class C1 { } class C2 { } @@ -74,3 +75,36 @@ var v = 3; var Foo; (function (Foo) { })(Foo || (Foo = {})); + + +//// [file1.d.ts] +interface I { +} +declare class C1 { +} +declare class C2 { +} +declare function f(): void; +declare var v: number; +declare class Foo { + static x: number; +} +declare module N { + module F { + } +} +//// [file2.d.ts] +declare class I { +} +interface C1 { +} +declare function C2(): void; +declare class f { +} +declare var v: number; +declare module Foo { + var x: number; +} +declare module N { + function F(): any; +}