Change TypeMapper to only take a type parameter, and fix combineTypeMappers to comply with that rule

This commit is contained in:
Jason Freeman
2015-04-17 18:28:38 -07:00
parent b8ebf561f9
commit ccf4104779
5 changed files with 172 additions and 3 deletions
+2 -2
View File
@@ -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(<TypeParameter>type);
}
if (type.flags & TypeFlags.Anonymous) {
return type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) ?
+1 -1
View File
@@ -1577,7 +1577,7 @@ module ts {
/* @internal */
export interface TypeMapper {
(t: Type): Type;
(t: TypeParameter): Type;
}
/* @internal */
@@ -0,0 +1,72 @@
//// [baseTypeWrappingInstantiationChain.ts]
class C<T1> extends CBase<T1> {
public works() {
new CBaseBase<Wrapper<T1>>(this);
}
public alsoWorks() {
new CBase<T1>(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
}
public method(t: Wrapper<T1>) { }
}
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
}
class CBaseBase<T3> {
constructor(x: Parameter<T3>) { }
}
class Parameter<T4> {
method(t: T4) { }
}
class Wrapper<T5> {
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<Wrapper<T1>>
};
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;
})();
@@ -0,0 +1,71 @@
=== tests/cases/compiler/baseTypeWrappingInstantiationChain.ts ===
class C<T1> extends CBase<T1> {
>C : C<T1>
>T1 : T1
>CBase : CBase<T2>
>T1 : T1
public works() {
>works : () => void
new CBaseBase<Wrapper<T1>>(this);
>new CBaseBase<Wrapper<T1>>(this) : CBaseBase<Wrapper<T1>>
>CBaseBase : typeof CBaseBase
>Wrapper : Wrapper<T5>
>T1 : T1
>this : C<T1>
}
public alsoWorks() {
>alsoWorks : () => void
new CBase<T1>(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
>new CBase<T1>(this) : CBase<T1>
>CBase : typeof CBase
>T1 : T1
>this : C<T1>
}
public method(t: Wrapper<T1>) { }
>method : (t: Wrapper<T1>) => void
>t : Wrapper<T1>
>Wrapper : Wrapper<T5>
>T1 : T1
}
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
>CBase : CBase<T2>
>T2 : T2
>CBaseBase : CBaseBase<T3>
>Wrapper : Wrapper<T5>
>T2 : T2
}
class CBaseBase<T3> {
>CBaseBase : CBaseBase<T3>
>T3 : T3
constructor(x: Parameter<T3>) { }
>x : Parameter<T3>
>Parameter : Parameter<T4>
>T3 : T3
}
class Parameter<T4> {
>Parameter : Parameter<T4>
>T4 : T4
method(t: T4) { }
>method : (t: T4) => void
>t : T4
>T4 : T4
}
class Wrapper<T5> {
>Wrapper : Wrapper<T5>
>T5 : T5
property: T5;
>property : T5
>T5 : T5
}
@@ -0,0 +1,26 @@
class C<T1> extends CBase<T1> {
public works() {
new CBaseBase<Wrapper<T1>>(this);
}
public alsoWorks() {
new CBase<T1>(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
}
public method(t: Wrapper<T1>) { }
}
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
}
class CBaseBase<T3> {
constructor(x: Parameter<T3>) { }
}
class Parameter<T4> {
method(t: T4) { }
}
class Wrapper<T5> {
property: T5;
}