Merge pull request #6628 from Microsoft/thisTypeAsConstraint

break on 'this' type in hasConstraintReferenceTo
This commit is contained in:
Vladimir Matveev 2016-01-26 14:58:35 -08:00
commit 322126d106
5 changed files with 37 additions and 1 deletions

View file

@ -4285,7 +4285,7 @@ namespace ts {
function hasConstraintReferenceTo(type: Type, target: TypeParameter): boolean {
let checked: Type[];
while (type && type.flags & TypeFlags.TypeParameter && !contains(checked, type)) {
while (type && !(type.flags & TypeFlags.ThisType) && type.flags & TypeFlags.TypeParameter && !contains(checked, type)) {
if (type === target) {
return true;
}

View file

@ -0,0 +1,14 @@
//// [thisTypeAsConstraint.ts]
class C {
public m<T extends this>() {
}
}
//// [thisTypeAsConstraint.js]
var C = (function () {
function C() {
}
C.prototype.m = function () {
};
return C;
}());

View file

@ -0,0 +1,9 @@
=== tests/cases/compiler/thisTypeAsConstraint.ts ===
class C {
>C : Symbol(C, Decl(thisTypeAsConstraint.ts, 0, 0))
public m<T extends this>() {
>m : Symbol(m, Decl(thisTypeAsConstraint.ts, 0, 9))
>T : Symbol(T, Decl(thisTypeAsConstraint.ts, 1, 11))
}
}

View file

@ -0,0 +1,9 @@
=== tests/cases/compiler/thisTypeAsConstraint.ts ===
class C {
>C : C
public m<T extends this>() {
>m : <T extends this>() => void
>T : T
}
}

View file

@ -0,0 +1,4 @@
class C {
public m<T extends this>() {
}
}