Merge pull request #5235 from Microsoft/fixDecoratorDiagostics

Fix exception in compiler when type checking decorators with generics.
This commit is contained in:
Mohamed Hegazy
2015-10-14 12:29:08 -07:00
4 changed files with 71 additions and 2 deletions

View File

@@ -437,8 +437,12 @@ namespace ts {
}
export function concatenateDiagnosticMessageChains(headChain: DiagnosticMessageChain, tailChain: DiagnosticMessageChain): DiagnosticMessageChain {
Debug.assert(!headChain.next);
headChain.next = tailChain;
let lastChain = headChain;
while (lastChain.next) {
lastChain = lastChain.next;
}
lastChain.next = tailChain;
return headChain;
}

View File

@@ -0,0 +1,22 @@
tests/cases/conformance/decorators/decoratorCallGeneric.ts(7,2): error TS1238: Unable to resolve signature of class decorator when called as an expression.
The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'C' is not a valid type argument because it is not a supertype of candidate 'void'.
==== tests/cases/conformance/decorators/decoratorCallGeneric.ts (1 errors) ====
interface I<T> {
prototype: T,
m: () => T
}
function dec<T>(c: I<T>) { }
@dec
~~~
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression.
!!! error TS1238: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
!!! error TS1238: Type argument candidate 'C' is not a valid type argument because it is not a supertype of candidate 'void'.
class C {
_brand: any;
static m() {}
}

View File

@@ -0,0 +1,31 @@
//// [decoratorCallGeneric.ts]
interface I<T> {
prototype: T,
m: () => T
}
function dec<T>(c: I<T>) { }
@dec
class C {
_brand: any;
static m() {}
}
//// [decoratorCallGeneric.js]
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
function dec(c) { }
var C = (function () {
function C() {
}
C.m = function () { };
C = __decorate([
dec
], C);
return C;
})();

View File

@@ -0,0 +1,12 @@
// @experimentalDecorators: true
interface I<T> {
prototype: T,
m: () => T
}
function dec<T>(c: I<T>) { }
@dec
class C {
_brand: any;
static m() {}
}