Skip to content

Do not report errors for classes and interfaces merging #5290

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

Merged
merged 2 commits into from
Oct 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12874,11 +12874,6 @@ namespace ts {
}
checkClassLikeDeclaration(node);

// Interfaces cannot be merged with non-ambient classes.
if (getSymbolOfNode(node).flags & SymbolFlags.Interface && !isInAmbientContext(node)) {
error(node, Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface);
}

forEach(node.members, checkSourceElement);
}

Expand Down Expand Up @@ -13164,16 +13159,6 @@ namespace ts {
checkIndexConstraints(type);
}
}

// Interfaces cannot merge with non-ambient classes.
if (symbol && symbol.declarations) {
for (let declaration of symbol.declarations) {
if (declaration.kind === SyntaxKind.ClassDeclaration && !isInAmbientContext(declaration)) {
error(node, Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface);
break;
}
}
}
}
forEach(getInterfaceBaseTypeNodes(node), heritageElement => {
if (!isSupportedExpressionWithTypeArguments(heritageElement)) {
Expand Down
4 changes: 0 additions & 4 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1620,10 +1620,6 @@
"category": "Error",
"code":2517
},
"Only an ambient class can be merged with an interface.": {
"category": "Error",
"code": 2518
},
"Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": {
"category": "Error",
"code": 2520
Expand Down
12 changes: 3 additions & 9 deletions tests/baselines/reference/augmentedTypesClass2.errors.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
tests/cases/compiler/augmentedTypesClass2.ts(4,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/augmentedTypesClass2.ts(10,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/augmentedTypesClass2.ts(16,7): error TS2300: Duplicate identifier 'c33'.
tests/cases/compiler/augmentedTypesClass2.ts(21,6): error TS2300: Duplicate identifier 'c33'.


==== tests/cases/compiler/augmentedTypesClass2.ts (4 errors) ====
==== tests/cases/compiler/augmentedTypesClass2.ts (2 errors) ====
// Checking class with other things in type space not value space

// class then interface
class c11 { // error
~~~
!!! error TS2518: Only an ambient class can be merged with an interface.
class c11 {
foo() {
return 1;
}
}

interface c11 { // error
~~~
!!! error TS2518: Only an ambient class can be merged with an interface.
interface c11 {
bar(): void;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/augmentedTypesClass2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Checking class with other things in type space not value space

// class then interface
class c11 { // error
class c11 {
foo() {
return 1;
}
}

interface c11 { // error
interface c11 {
bar(): void;
}

Expand Down
12 changes: 3 additions & 9 deletions tests/baselines/reference/augmentedTypesInterface.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
tests/cases/compiler/augmentedTypesInterface.ts(12,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/augmentedTypesInterface.ts(16,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/compiler/augmentedTypesInterface.ts(23,11): error TS2300: Duplicate identifier 'i3'.
tests/cases/compiler/augmentedTypesInterface.ts(26,6): error TS2300: Duplicate identifier 'i3'.


==== tests/cases/compiler/augmentedTypesInterface.ts (4 errors) ====
==== tests/cases/compiler/augmentedTypesInterface.ts (2 errors) ====
// interface then interface

interface i {
Expand All @@ -16,15 +14,11 @@ tests/cases/compiler/augmentedTypesInterface.ts(26,6): error TS2300: Duplicate i
}

// interface then class
interface i2 { // error
~~
!!! error TS2518: Only an ambient class can be merged with an interface.
interface i2 {
foo(): void;
}

class i2 { // error
~~
!!! error TS2518: Only an ambient class can be merged with an interface.
class i2 {
bar() {
return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/augmentedTypesInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ interface i {
}

// interface then class
interface i2 { // error
interface i2 {
foo(): void;
}

class i2 { // error
class i2 {
bar() {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(7,16): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(8,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(10,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(11,16): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(13,16): error TS2300: Duplicate identifier 'CC1'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(14,7): error TS2300: Duplicate identifier 'CC1'.
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(16,7): error TS2300: Duplicate identifier 'CC2'.
Expand All @@ -20,26 +16,18 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(39,1): error TS2511: Cannot create an instance of the abstract class 'DCC1'.


==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts (20 errors) ====
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts (16 errors) ====
abstract class CM {}
module CM {}

module MC {}
abstract class MC {}

abstract class CI {}
~~
!!! error TS2518: Only an ambient class can be merged with an interface.
interface CI {}
~~
!!! error TS2518: Only an ambient class can be merged with an interface.

interface IC {}
~~
!!! error TS2518: Only an ambient class can be merged with an interface.
abstract class IC {}
~~
!!! error TS2518: Only an ambient class can be merged with an interface.

abstract class CC1 {}
~~~
Expand Down
18 changes: 3 additions & 15 deletions tests/baselines/reference/classAndInterfaceWithSameName.errors.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(1,7): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(1,11): error TS2300: Duplicate identifier 'foo'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(2,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(2,15): error TS2300: Duplicate identifier 'foo'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(5,11): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(6,9): error TS2300: Duplicate identifier 'bar'.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(9,15): error TS2518: Only an ambient class can be merged with an interface.
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(10,9): error TS2300: Duplicate identifier 'bar'.


==== tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts (8 errors) ====
==== tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts (4 errors) ====
class C { foo: string; }
~
!!! error TS2518: Only an ambient class can be merged with an interface.
~~~
!!! error TS2300: Duplicate identifier 'foo'.
interface C { foo: string; } // error
~
!!! error TS2518: Only an ambient class can be merged with an interface.
interface C { foo: string; }
~~~
!!! error TS2300: Duplicate identifier 'foo'.

module M {
class D {
~
!!! error TS2518: Only an ambient class can be merged with an interface.
bar: string;
~~~
!!! error TS2300: Duplicate identifier 'bar'.
}

interface D { // error
~
!!! error TS2518: Only an ambient class can be merged with an interface.
interface D {
bar: string;
~~~
!!! error TS2300: Duplicate identifier 'bar'.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/classAndInterfaceWithSameName.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//// [classAndInterfaceWithSameName.ts]
class C { foo: string; }
interface C { foo: string; } // error
interface C { foo: string; }

module M {
class D {
bar: string;
}

interface D { // error
interface D {
bar: string;
}
}
Expand Down
52 changes: 0 additions & 52 deletions tests/baselines/reference/clinterfaces.errors.txt

This file was deleted.

52 changes: 52 additions & 0 deletions tests/baselines/reference/clinterfaces.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
=== tests/cases/compiler/clinterfaces.ts ===
module M {
>M : Symbol(M, Decl(clinterfaces.ts, 0, 0))

class C { }
>C : Symbol(C, Decl(clinterfaces.ts, 0, 10), Decl(clinterfaces.ts, 1, 15))

interface C { }
>C : Symbol(C, Decl(clinterfaces.ts, 0, 10), Decl(clinterfaces.ts, 1, 15))

interface D { }
>D : Symbol(D, Decl(clinterfaces.ts, 2, 19), Decl(clinterfaces.ts, 3, 19))

class D { }
>D : Symbol(D, Decl(clinterfaces.ts, 2, 19), Decl(clinterfaces.ts, 3, 19))
}

interface Foo<T> {
>Foo : Symbol(Foo, Decl(clinterfaces.ts, 5, 1), Decl(clinterfaces.ts, 9, 1))
>T : Symbol(T, Decl(clinterfaces.ts, 7, 14), Decl(clinterfaces.ts, 11, 10))

a: string;
>a : Symbol(a, Decl(clinterfaces.ts, 7, 18))
}

class Foo<T>{
>Foo : Symbol(Foo, Decl(clinterfaces.ts, 5, 1), Decl(clinterfaces.ts, 9, 1))
>T : Symbol(T, Decl(clinterfaces.ts, 7, 14), Decl(clinterfaces.ts, 11, 10))

b: number;
>b : Symbol(b, Decl(clinterfaces.ts, 11, 13))
}

class Bar<T>{
>Bar : Symbol(Bar, Decl(clinterfaces.ts, 13, 1), Decl(clinterfaces.ts, 17, 1))
>T : Symbol(T, Decl(clinterfaces.ts, 15, 10), Decl(clinterfaces.ts, 19, 14))

b: number;
>b : Symbol(b, Decl(clinterfaces.ts, 15, 13))
}

interface Bar<T> {
>Bar : Symbol(Bar, Decl(clinterfaces.ts, 13, 1), Decl(clinterfaces.ts, 17, 1))
>T : Symbol(T, Decl(clinterfaces.ts, 15, 10), Decl(clinterfaces.ts, 19, 14))

a: string;
>a : Symbol(a, Decl(clinterfaces.ts, 19, 18))
}

export = Foo;
>Foo : Symbol(Foo, Decl(clinterfaces.ts, 5, 1), Decl(clinterfaces.ts, 9, 1))

52 changes: 52 additions & 0 deletions tests/baselines/reference/clinterfaces.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
=== tests/cases/compiler/clinterfaces.ts ===
module M {
>M : typeof M

class C { }
>C : C

interface C { }
>C : C

interface D { }
>D : D

class D { }
>D : D
}

interface Foo<T> {
>Foo : Foo<T>
>T : T

a: string;
>a : string
}

class Foo<T>{
>Foo : Foo<T>
>T : T

b: number;
>b : number
}

class Bar<T>{
>Bar : Bar<T>
>T : T

b: number;
>b : number
}

interface Bar<T> {
>Bar : Bar<T>
>T : T

a: string;
>a : string
}

export = Foo;
>Foo : Foo<T>

Loading