diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a6973bb273b6a..d5e5b5c67e4ad 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3788,7 +3788,7 @@ module ts { } function combineTypeMappers(mapper1: TypeMapper, mapper2: TypeMapper): TypeMapper { - return t => mapper2(mapper1(t)); + return t => instantiateType(mapper1(t), mapper2); } function instantiateTypeParameter(typeParameter: TypeParameter, mapper: TypeMapper): TypeParameter { @@ -3859,7 +3859,7 @@ module ts { function instantiateType(type: Type, mapper: TypeMapper): Type { if (mapper !== identityMapper) { if (type.flags & TypeFlags.TypeParameter) { - return mapper(type); + return mapper(type); } if (type.flags & TypeFlags.Anonymous) { return type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) ? diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 078f3d060a61b..9191a6999bf50 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1577,7 +1577,7 @@ module ts { /* @internal */ export interface TypeMapper { - (t: Type): Type; + (t: TypeParameter): Type; } /* @internal */ diff --git a/tests/baselines/reference/baseTypeWrappingInstantiationChain.js b/tests/baselines/reference/baseTypeWrappingInstantiationChain.js new file mode 100644 index 0000000000000..97180f421335c --- /dev/null +++ b/tests/baselines/reference/baseTypeWrappingInstantiationChain.js @@ -0,0 +1,72 @@ +//// [baseTypeWrappingInstantiationChain.ts] +class C extends CBase { + public works() { + new CBaseBase>(this); + } + public alsoWorks() { + new CBase(this); // Should not error, parameter is of type Parameter> + } + + public method(t: Wrapper) { } +} + +class CBase extends CBaseBase> { + +} + +class CBaseBase { + constructor(x: Parameter) { } +} + +class Parameter { + method(t: T4) { } +} + +class Wrapper { + property: T5; +} + +//// [baseTypeWrappingInstantiationChain.js] +var __extends = 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 C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + C.prototype.works = function () { + new CBaseBase(this); + }; + C.prototype.alsoWorks = function () { + new CBase(this); // Should not error, parameter is of type Parameter> + }; + C.prototype.method = function (t) { }; + return C; +})(CBase); +var CBase = (function (_super) { + __extends(CBase, _super); + function CBase() { + _super.apply(this, arguments); + } + return CBase; +})(CBaseBase); +var CBaseBase = (function () { + function CBaseBase(x) { + } + return CBaseBase; +})(); +var Parameter = (function () { + function Parameter() { + } + Parameter.prototype.method = function (t) { }; + return Parameter; +})(); +var Wrapper = (function () { + function Wrapper() { + } + return Wrapper; +})(); diff --git a/tests/baselines/reference/baseTypeWrappingInstantiationChain.symbols b/tests/baselines/reference/baseTypeWrappingInstantiationChain.symbols new file mode 100644 index 0000000000000..1e8ab089b900f --- /dev/null +++ b/tests/baselines/reference/baseTypeWrappingInstantiationChain.symbols @@ -0,0 +1,69 @@ +=== tests/cases/compiler/baseTypeWrappingInstantiationChain.ts === +class C extends CBase { +>C : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0)) +>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8)) +>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 9, 1)) +>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8)) + + public works() { +>works : Symbol(works, Decl(baseTypeWrappingInstantiationChain.ts, 0, 31)) + + new CBaseBase>(this); +>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 13, 1)) +>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1)) +>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8)) +>this : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0)) + } + public alsoWorks() { +>alsoWorks : Symbol(alsoWorks, Decl(baseTypeWrappingInstantiationChain.ts, 3, 5)) + + new CBase(this); // Should not error, parameter is of type Parameter> +>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 9, 1)) +>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8)) +>this : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0)) + } + + public method(t: Wrapper) { } +>method : Symbol(method, Decl(baseTypeWrappingInstantiationChain.ts, 6, 5)) +>t : Symbol(t, Decl(baseTypeWrappingInstantiationChain.ts, 8, 18)) +>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1)) +>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8)) +} + +class CBase extends CBaseBase> { +>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 9, 1)) +>T2 : Symbol(T2, Decl(baseTypeWrappingInstantiationChain.ts, 11, 12)) +>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 13, 1)) +>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1)) +>T2 : Symbol(T2, Decl(baseTypeWrappingInstantiationChain.ts, 11, 12)) + +} + +class CBaseBase { +>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 13, 1)) +>T3 : Symbol(T3, Decl(baseTypeWrappingInstantiationChain.ts, 15, 16)) + + constructor(x: Parameter) { } +>x : Symbol(x, Decl(baseTypeWrappingInstantiationChain.ts, 16, 16)) +>Parameter : Symbol(Parameter, Decl(baseTypeWrappingInstantiationChain.ts, 17, 1)) +>T3 : Symbol(T3, Decl(baseTypeWrappingInstantiationChain.ts, 15, 16)) +} + +class Parameter { +>Parameter : Symbol(Parameter, Decl(baseTypeWrappingInstantiationChain.ts, 17, 1)) +>T4 : Symbol(T4, Decl(baseTypeWrappingInstantiationChain.ts, 19, 16)) + + method(t: T4) { } +>method : Symbol(method, Decl(baseTypeWrappingInstantiationChain.ts, 19, 21)) +>t : Symbol(t, Decl(baseTypeWrappingInstantiationChain.ts, 20, 11)) +>T4 : Symbol(T4, Decl(baseTypeWrappingInstantiationChain.ts, 19, 16)) +} + +class Wrapper { +>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1)) +>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 23, 14)) + + property: T5; +>property : Symbol(property, Decl(baseTypeWrappingInstantiationChain.ts, 23, 19)) +>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 23, 14)) +} diff --git a/tests/baselines/reference/baseTypeWrappingInstantiationChain.types b/tests/baselines/reference/baseTypeWrappingInstantiationChain.types new file mode 100644 index 0000000000000..61919bad212c6 --- /dev/null +++ b/tests/baselines/reference/baseTypeWrappingInstantiationChain.types @@ -0,0 +1,71 @@ +=== tests/cases/compiler/baseTypeWrappingInstantiationChain.ts === +class C extends CBase { +>C : C +>T1 : T1 +>CBase : CBase +>T1 : T1 + + public works() { +>works : () => void + + new CBaseBase>(this); +>new CBaseBase>(this) : CBaseBase> +>CBaseBase : typeof CBaseBase +>Wrapper : Wrapper +>T1 : T1 +>this : C + } + public alsoWorks() { +>alsoWorks : () => void + + new CBase(this); // Should not error, parameter is of type Parameter> +>new CBase(this) : CBase +>CBase : typeof CBase +>T1 : T1 +>this : C + } + + public method(t: Wrapper) { } +>method : (t: Wrapper) => void +>t : Wrapper +>Wrapper : Wrapper +>T1 : T1 +} + +class CBase extends CBaseBase> { +>CBase : CBase +>T2 : T2 +>CBaseBase : CBaseBase +>Wrapper : Wrapper +>T2 : T2 + +} + +class CBaseBase { +>CBaseBase : CBaseBase +>T3 : T3 + + constructor(x: Parameter) { } +>x : Parameter +>Parameter : Parameter +>T3 : T3 +} + +class Parameter { +>Parameter : Parameter +>T4 : T4 + + method(t: T4) { } +>method : (t: T4) => void +>t : T4 +>T4 : T4 +} + +class Wrapper { +>Wrapper : Wrapper +>T5 : T5 + + property: T5; +>property : T5 +>T5 : T5 +} diff --git a/tests/cases/compiler/baseTypeWrappingInstantiationChain.ts b/tests/cases/compiler/baseTypeWrappingInstantiationChain.ts new file mode 100644 index 0000000000000..f630b908ec2bd --- /dev/null +++ b/tests/cases/compiler/baseTypeWrappingInstantiationChain.ts @@ -0,0 +1,26 @@ +class C extends CBase { + public works() { + new CBaseBase>(this); + } + public alsoWorks() { + new CBase(this); // Should not error, parameter is of type Parameter> + } + + public method(t: Wrapper) { } +} + +class CBase extends CBaseBase> { + +} + +class CBaseBase { + constructor(x: Parameter) { } +} + +class Parameter { + method(t: T4) { } +} + +class Wrapper { + property: T5; +} \ No newline at end of file