Skip to content

Commit 21e30e0

Browse files
committed
Merge pull request microsoft#5235 from Microsoft/fixDecoratorDiagostics
Fix exception in compiler when type checking decorators with generics.
2 parents 5234bf6 + 0fa89ad commit 21e30e0

4 files changed

Lines changed: 71 additions & 2 deletions

File tree

src/compiler/core.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,12 @@ namespace ts {
437437
}
438438

439439
export function concatenateDiagnosticMessageChains(headChain: DiagnosticMessageChain, tailChain: DiagnosticMessageChain): DiagnosticMessageChain {
440-
Debug.assert(!headChain.next);
441-
headChain.next = tailChain;
440+
let lastChain = headChain;
441+
while (lastChain.next) {
442+
lastChain = lastChain.next;
443+
}
444+
445+
lastChain.next = tailChain;
442446
return headChain;
443447
}
444448

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
tests/cases/conformance/decorators/decoratorCallGeneric.ts(7,2): error TS1238: Unable to resolve signature of class decorator when called as an expression.
2+
The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
3+
Type argument candidate 'C' is not a valid type argument because it is not a supertype of candidate 'void'.
4+
5+
6+
==== tests/cases/conformance/decorators/decoratorCallGeneric.ts (1 errors) ====
7+
interface I<T> {
8+
prototype: T,
9+
m: () => T
10+
}
11+
function dec<T>(c: I<T>) { }
12+
13+
@dec
14+
~~~
15+
!!! error TS1238: Unable to resolve signature of class decorator when called as an expression.
16+
!!! error TS1238: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
17+
!!! error TS1238: Type argument candidate 'C' is not a valid type argument because it is not a supertype of candidate 'void'.
18+
class C {
19+
_brand: any;
20+
static m() {}
21+
}
22+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [decoratorCallGeneric.ts]
2+
interface I<T> {
3+
prototype: T,
4+
m: () => T
5+
}
6+
function dec<T>(c: I<T>) { }
7+
8+
@dec
9+
class C {
10+
_brand: any;
11+
static m() {}
12+
}
13+
14+
15+
//// [decoratorCallGeneric.js]
16+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
17+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
18+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
19+
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;
20+
return c > 3 && r && Object.defineProperty(target, key, r), r;
21+
};
22+
function dec(c) { }
23+
var C = (function () {
24+
function C() {
25+
}
26+
C.m = function () { };
27+
C = __decorate([
28+
dec
29+
], C);
30+
return C;
31+
})();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @experimentalDecorators: true
2+
interface I<T> {
3+
prototype: T,
4+
m: () => T
5+
}
6+
function dec<T>(c: I<T>) { }
7+
8+
@dec
9+
class C {
10+
_brand: any;
11+
static m() {}
12+
}

0 commit comments

Comments
 (0)