From 50d0f9b719d40d1c05a41c0adbb7e54e3f00a6a0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 18 Dec 2014 16:34:14 -0800 Subject: [PATCH 1/3] Added tests/baselines. --- ...genericAndNonGenericInheritedSignature1.js | 12 ++++++++++ ...ericAndNonGenericInheritedSignature1.types | 24 +++++++++++++++++++ ...ndNonGenericInheritedSignature2.errors.txt | 17 +++++++++++++ ...genericAndNonGenericInheritedSignature2.js | 12 ++++++++++ ...genericAndNonGenericInheritedSignature1.ts | 8 +++++++ ...genericAndNonGenericInheritedSignature2.ts | 8 +++++++ 6 files changed, 81 insertions(+) create mode 100644 tests/baselines/reference/genericAndNonGenericInheritedSignature1.js create mode 100644 tests/baselines/reference/genericAndNonGenericInheritedSignature1.types create mode 100644 tests/baselines/reference/genericAndNonGenericInheritedSignature2.errors.txt create mode 100644 tests/baselines/reference/genericAndNonGenericInheritedSignature2.js create mode 100644 tests/cases/compiler/genericAndNonGenericInheritedSignature1.ts create mode 100644 tests/cases/compiler/genericAndNonGenericInheritedSignature2.ts diff --git a/tests/baselines/reference/genericAndNonGenericInheritedSignature1.js b/tests/baselines/reference/genericAndNonGenericInheritedSignature1.js new file mode 100644 index 00000000000..15ea71b1223 --- /dev/null +++ b/tests/baselines/reference/genericAndNonGenericInheritedSignature1.js @@ -0,0 +1,12 @@ +//// [genericAndNonGenericInheritedSignature1.ts] +interface Foo { + f(x: any): any; +} +interface Bar { + f(x: T): T; +} +interface Hello extends Foo, Bar { +} + + +//// [genericAndNonGenericInheritedSignature1.js] diff --git a/tests/baselines/reference/genericAndNonGenericInheritedSignature1.types b/tests/baselines/reference/genericAndNonGenericInheritedSignature1.types new file mode 100644 index 00000000000..939cbfa612f --- /dev/null +++ b/tests/baselines/reference/genericAndNonGenericInheritedSignature1.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/genericAndNonGenericInheritedSignature1.ts === +interface Foo { +>Foo : Foo + + f(x: any): any; +>f : (x: any) => any +>x : any +} +interface Bar { +>Bar : Bar + + f(x: T): T; +>f : (x: T) => T +>T : T +>x : T +>T : T +>T : T +} +interface Hello extends Foo, Bar { +>Hello : Hello +>Foo : Foo +>Bar : Bar +} + diff --git a/tests/baselines/reference/genericAndNonGenericInheritedSignature2.errors.txt b/tests/baselines/reference/genericAndNonGenericInheritedSignature2.errors.txt new file mode 100644 index 00000000000..05fdd68319e --- /dev/null +++ b/tests/baselines/reference/genericAndNonGenericInheritedSignature2.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/genericAndNonGenericInheritedSignature2.ts(7,11): error TS2320: Interface 'Hello' cannot simultaneously extend types 'Bar' and 'Foo'. + Named properties 'f' of types 'Bar' and 'Foo' are not identical. + + +==== tests/cases/compiler/genericAndNonGenericInheritedSignature2.ts (1 errors) ==== + interface Foo { + f(x: any): any; + } + interface Bar { + f(x: T): T; + } + interface Hello extends Bar, Foo { + ~~~~~ +!!! error TS2320: Interface 'Hello' cannot simultaneously extend types 'Bar' and 'Foo'. +!!! error TS2320: Named properties 'f' of types 'Bar' and 'Foo' are not identical. + } + \ No newline at end of file diff --git a/tests/baselines/reference/genericAndNonGenericInheritedSignature2.js b/tests/baselines/reference/genericAndNonGenericInheritedSignature2.js new file mode 100644 index 00000000000..d8353b81e98 --- /dev/null +++ b/tests/baselines/reference/genericAndNonGenericInheritedSignature2.js @@ -0,0 +1,12 @@ +//// [genericAndNonGenericInheritedSignature2.ts] +interface Foo { + f(x: any): any; +} +interface Bar { + f(x: T): T; +} +interface Hello extends Bar, Foo { +} + + +//// [genericAndNonGenericInheritedSignature2.js] diff --git a/tests/cases/compiler/genericAndNonGenericInheritedSignature1.ts b/tests/cases/compiler/genericAndNonGenericInheritedSignature1.ts new file mode 100644 index 00000000000..3e5aa480be4 --- /dev/null +++ b/tests/cases/compiler/genericAndNonGenericInheritedSignature1.ts @@ -0,0 +1,8 @@ +interface Foo { + f(x: any): any; +} +interface Bar { + f(x: T): T; +} +interface Hello extends Foo, Bar { +} diff --git a/tests/cases/compiler/genericAndNonGenericInheritedSignature2.ts b/tests/cases/compiler/genericAndNonGenericInheritedSignature2.ts new file mode 100644 index 00000000000..f35e2ffda98 --- /dev/null +++ b/tests/cases/compiler/genericAndNonGenericInheritedSignature2.ts @@ -0,0 +1,8 @@ +interface Foo { + f(x: any): any; +} +interface Bar { + f(x: T): T; +} +interface Hello extends Bar, Foo { +} From 4aa37691a1a87cda0476965207e6b00af0fe0ae3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 18 Dec 2014 16:37:50 -0800 Subject: [PATCH 2/3] Fixed issue where the second type's signature having type parameters would not cause an error. --- src/compiler/checker.ts | 8 +++---- ...ndNonGenericInheritedSignature1.errors.txt | 17 +++++++++++++ ...ericAndNonGenericInheritedSignature1.types | 24 ------------------- 3 files changed, 21 insertions(+), 28 deletions(-) create mode 100644 tests/baselines/reference/genericAndNonGenericInheritedSignature1.errors.txt delete mode 100644 tests/baselines/reference/genericAndNonGenericInheritedSignature1.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b1559f8dd13..d4ce2e6da9a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4016,7 +4016,7 @@ module ts { result &= related; } } - else if (source.typeParameters || source.typeParameters) { + else if (source.typeParameters || target.typeParameters) { return Ternary.False; } // Spec 1.0 Section 3.8.3 & 3.8.4: @@ -5244,8 +5244,8 @@ module ts { // Return the contextual signature for a given expression node. A contextual type provides a // contextual signature if it has a single call signature and if that call signature is non-generic. // If the contextual type is a union type, get the signature from each type possible and if they are - // all identical ignoring their return type, the result is same signature but with return type as - // union type of return types from these signatures + // all identical ignoring their return type, the result is same signature but with a union type of + // the return types of these signatures function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); var type = isObjectLiteralMethod(node) @@ -5274,7 +5274,7 @@ module ts { signatureList = [signature]; } else if (!compareSignatures(signatureList[0], signature, /*compareReturnTypes*/ false, compareTypes)) { - // Signatures arent identical, do not use + // Signatures aren't identical, do not use return undefined; } else { diff --git a/tests/baselines/reference/genericAndNonGenericInheritedSignature1.errors.txt b/tests/baselines/reference/genericAndNonGenericInheritedSignature1.errors.txt new file mode 100644 index 00000000000..63ff9d9313e --- /dev/null +++ b/tests/baselines/reference/genericAndNonGenericInheritedSignature1.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/genericAndNonGenericInheritedSignature1.ts(7,11): error TS2320: Interface 'Hello' cannot simultaneously extend types 'Foo' and 'Bar'. + Named properties 'f' of types 'Foo' and 'Bar' are not identical. + + +==== tests/cases/compiler/genericAndNonGenericInheritedSignature1.ts (1 errors) ==== + interface Foo { + f(x: any): any; + } + interface Bar { + f(x: T): T; + } + interface Hello extends Foo, Bar { + ~~~~~ +!!! error TS2320: Interface 'Hello' cannot simultaneously extend types 'Foo' and 'Bar'. +!!! error TS2320: Named properties 'f' of types 'Foo' and 'Bar' are not identical. + } + \ No newline at end of file diff --git a/tests/baselines/reference/genericAndNonGenericInheritedSignature1.types b/tests/baselines/reference/genericAndNonGenericInheritedSignature1.types deleted file mode 100644 index 939cbfa612f..00000000000 --- a/tests/baselines/reference/genericAndNonGenericInheritedSignature1.types +++ /dev/null @@ -1,24 +0,0 @@ -=== tests/cases/compiler/genericAndNonGenericInheritedSignature1.ts === -interface Foo { ->Foo : Foo - - f(x: any): any; ->f : (x: any) => any ->x : any -} -interface Bar { ->Bar : Bar - - f(x: T): T; ->f : (x: T) => T ->T : T ->x : T ->T : T ->T : T -} -interface Hello extends Foo, Bar { ->Hello : Hello ->Foo : Foo ->Bar : Bar -} - From 52ef460002c5b8b4383dd1df29b566ed992a80f3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 19 Dec 2014 15:30:03 -0800 Subject: [PATCH 3/3] Undid comment change that made things more misleading. --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d4ce2e6da9a..f8c4caa9630 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5244,8 +5244,8 @@ module ts { // Return the contextual signature for a given expression node. A contextual type provides a // contextual signature if it has a single call signature and if that call signature is non-generic. // If the contextual type is a union type, get the signature from each type possible and if they are - // all identical ignoring their return type, the result is same signature but with a union type of - // the return types of these signatures + // all identical ignoring their return type, the result is same signature but with return type as + // union type of return types from these signatures function getContextualSignature(node: FunctionExpression | MethodDeclaration): Signature { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); var type = isObjectLiteralMethod(node)