From 49be653a252226f496923a06b919079d13220b64 Mon Sep 17 00:00:00 2001 From: David Li Date: Wed, 10 Jun 2015 19:22:01 -0400 Subject: [PATCH 1/2] Added test case for invalid generic type constraints Signed-off-by: David Li --- .../genericTypeConstraints.errors.txt | 24 ++++++++++ .../reference/genericTypeConstraints.js | 45 +++++++++++++++++++ .../cases/compiler/genericTypeConstraints.ts | 13 ++++++ 3 files changed, 82 insertions(+) create mode 100644 tests/baselines/reference/genericTypeConstraints.errors.txt create mode 100644 tests/baselines/reference/genericTypeConstraints.js create mode 100644 tests/cases/compiler/genericTypeConstraints.ts diff --git a/tests/baselines/reference/genericTypeConstraints.errors.txt b/tests/baselines/reference/genericTypeConstraints.errors.txt new file mode 100644 index 00000000000..9fd8b5f15be --- /dev/null +++ b/tests/baselines/reference/genericTypeConstraints.errors.txt @@ -0,0 +1,24 @@ +tests/cases/compiler/genericTypeConstraints.ts(9,27): error TS2344: Type 'FooExtended' does not satisfy the constraint 'Foo'. + Property 'fooMethod' is missing in type 'FooExtended'. +tests/cases/compiler/genericTypeConstraints.ts(9,31): error TS2344: Type 'FooExtended' does not satisfy the constraint 'Foo'. + + +==== tests/cases/compiler/genericTypeConstraints.ts (2 errors) ==== + class Foo { + fooMethod() {} + } + + class FooExtended { } + + class Bar { } + + class BarExtended extends Bar { + ~~~~~~~~~~~~~~~~ +!!! error TS2344: Type 'FooExtended' does not satisfy the constraint 'Foo'. +!!! error TS2344: Property 'fooMethod' is missing in type 'FooExtended'. + ~~~~~~~~~~~ +!!! error TS2344: Type 'FooExtended' does not satisfy the constraint 'Foo'. + constructor() { + super(); + } + } \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeConstraints.js b/tests/baselines/reference/genericTypeConstraints.js new file mode 100644 index 00000000000..6f0f235ccb8 --- /dev/null +++ b/tests/baselines/reference/genericTypeConstraints.js @@ -0,0 +1,45 @@ +//// [genericTypeConstraints.ts] +class Foo { + fooMethod() {} +} + +class FooExtended { } + +class Bar { } + +class BarExtended extends Bar { + constructor() { + super(); + } +} + +//// [genericTypeConstraints.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Foo = (function () { + function Foo() { + } + Foo.prototype.fooMethod = function () { }; + return Foo; +})(); +var FooExtended = (function () { + function FooExtended() { + } + return FooExtended; +})(); +var Bar = (function () { + function Bar() { + } + return Bar; +})(); +var BarExtended = (function (_super) { + __extends(BarExtended, _super); + function BarExtended() { + _super.call(this); + } + return BarExtended; +})(Bar); diff --git a/tests/cases/compiler/genericTypeConstraints.ts b/tests/cases/compiler/genericTypeConstraints.ts new file mode 100644 index 00000000000..eba726171ad --- /dev/null +++ b/tests/cases/compiler/genericTypeConstraints.ts @@ -0,0 +1,13 @@ +class Foo { + fooMethod() {} +} + +class FooExtended { } + +class Bar { } + +class BarExtended extends Bar { + constructor() { + super(); + } +} \ No newline at end of file From 5fc4a8e4d30203b3a7c675f06501370987dfb31d Mon Sep 17 00:00:00 2001 From: David Li Date: Wed, 10 Jun 2015 19:59:07 -0400 Subject: [PATCH 2/2] Fix crash with unmet generic type constraints It looks like 93dbcf006f3855c20f02e587970add1744cf32d1 didn't completely change "(node).typeArguments" to "typeArguments". Closes #3464 Signed-off-by: David Li --- 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 c8150d644a2..04f1e7101e6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7275,8 +7275,8 @@ module ts { checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, /*excludeArgument*/ undefined, /*reportErrors*/ true); } else if (candidateForTypeArgumentError) { - if (!isTaggedTemplate && (node).typeArguments) { - checkTypeArguments(candidateForTypeArgumentError, (node).typeArguments, [], /*reportErrors*/ true) + if (!isTaggedTemplate && typeArguments) { + checkTypeArguments(candidateForTypeArgumentError, typeArguments, [], /*reportErrors*/ true) } else { Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0);