Unconditionally compute type arguments of class base type

This commit is contained in:
Andy Hanson 2017-05-19 08:56:56 -07:00
parent 38ece3b703
commit ce1e0097f0
6 changed files with 37 additions and 18 deletions

View file

@ -4846,6 +4846,7 @@ namespace ts {
return; return;
} }
const baseTypeNode = getBaseTypeNodeOfClass(type); const baseTypeNode = getBaseTypeNodeOfClass(type);
const typeArgs = typeArgumentsFromTypeReferenceNode(baseTypeNode);
let baseType: Type; let baseType: Type;
const originalBaseType = baseConstructorType && baseConstructorType.symbol ? getDeclaredTypeOfSymbol(baseConstructorType.symbol) : undefined; const originalBaseType = baseConstructorType && baseConstructorType.symbol ? getDeclaredTypeOfSymbol(baseConstructorType.symbol) : undefined;
if (baseConstructorType.symbol && baseConstructorType.symbol.flags & SymbolFlags.Class && if (baseConstructorType.symbol && baseConstructorType.symbol.flags & SymbolFlags.Class &&
@ -4853,7 +4854,7 @@ namespace ts {
// When base constructor type is a class with no captured type arguments we know that the constructors all have the same type parameters as the // When base constructor type is a class with no captured type arguments we know that the constructors all have the same type parameters as the
// class and all return the instance type of the class. There is no need for further checks and we can apply the // class and all return the instance type of the class. There is no need for further checks and we can apply the
// type arguments in the same manner as a type reference to get the same error reporting experience. // type arguments in the same manner as a type reference to get the same error reporting experience.
baseType = getTypeFromClassOrInterfaceReference(baseTypeNode, baseConstructorType.symbol, typeArgumentsFromTypeReferenceNode(baseTypeNode)); baseType = getTypeFromClassOrInterfaceReference(baseTypeNode, baseConstructorType.symbol, typeArgs);
} }
else if (baseConstructorType.flags & TypeFlags.Any) { else if (baseConstructorType.flags & TypeFlags.Any) {
baseType = baseConstructorType; baseType = baseConstructorType;

View file

@ -1,4 +1,5 @@
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(1,17): error TS2304: Cannot find name 'A'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(1,17): error TS2304: Cannot find name 'A'.
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(1,19): error TS2304: Cannot find name 'T'.
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(1,33): error TS2304: Cannot find name 'B'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(1,33): error TS2304: Cannot find name 'B'.
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(1,35): error TS2304: Cannot find name 'T'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(1,35): error TS2304: Cannot find name 'T'.
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(4,9): error TS2315: Type 'C' is not generic. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(4,9): error TS2315: Type 'C' is not generic.
@ -17,10 +18,12 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(14,18): error TS2304: Cannot find name 'T'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts(14,18): error TS2304: Cannot find name 'T'.
==== tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts (17 errors) ==== ==== tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts1.ts (18 errors) ====
class C extends A<T> implements B<T> { class C extends A<T> implements B<T> {
~ ~
!!! error TS2304: Cannot find name 'A'. !!! error TS2304: Cannot find name 'A'.
~
!!! error TS2304: Cannot find name 'T'.
~ ~
!!! error TS2304: Cannot find name 'B'. !!! error TS2304: Cannot find name 'B'.
~ ~

View file

@ -1,4 +1,9 @@
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,17): error TS2304: Cannot find name 'A'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,17): error TS2304: Cannot find name 'A'.
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,19): error TS2304: Cannot find name 'X'.
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,21): error TS2304: Cannot find name 'T'.
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,25): error TS2304: Cannot find name 'Y'.
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,27): error TS2304: Cannot find name 'Z'.
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,29): error TS2304: Cannot find name 'T'.
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,45): error TS2304: Cannot find name 'B'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,45): error TS2304: Cannot find name 'B'.
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,47): error TS2304: Cannot find name 'X'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,47): error TS2304: Cannot find name 'X'.
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,49): error TS2304: Cannot find name 'T'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(1,49): error TS2304: Cannot find name 'T'.
@ -49,10 +54,20 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts
tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(14,28): error TS2304: Cannot find name 'T'. tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts(14,28): error TS2304: Cannot find name 'T'.
==== tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts (49 errors) ==== ==== tests/cases/conformance/parser/ecmascript5/Generics/parserGenericsInTypeContexts2.ts (54 errors) ====
class C extends A<X<T>, Y<Z<T>>> implements B<X<T>, Y<Z<T>>> { class C extends A<X<T>, Y<Z<T>>> implements B<X<T>, Y<Z<T>>> {
~ ~
!!! error TS2304: Cannot find name 'A'. !!! error TS2304: Cannot find name 'A'.
~
!!! error TS2304: Cannot find name 'X'.
~
!!! error TS2304: Cannot find name 'T'.
~
!!! error TS2304: Cannot find name 'Y'.
~
!!! error TS2304: Cannot find name 'Z'.
~
!!! error TS2304: Cannot find name 'T'.
~ ~
!!! error TS2304: Cannot find name 'B'. !!! error TS2304: Cannot find name 'B'.
~ ~

View file

@ -5,7 +5,7 @@
/classReference.ts(4,24): error TS2315: Type 'C' is not generic. /classReference.ts(4,24): error TS2315: Type 'C' is not generic.
/interface.ts(1,21): error TS2307: Cannot find module 'unknown'. /interface.ts(1,21): error TS2307: Cannot find module 'unknown'.
/new.ts(1,21): error TS2307: Cannot find module 'unkown'. /new.ts(1,21): error TS2307: Cannot find module 'unkown'.
/super.ts(1,19): error TS2307: Cannot find module 'unknown'. /super.ts(1,22): error TS2307: Cannot find module 'unknown'.
/super.ts(8,17): error TS2304: Cannot find name 'InvalidReference'. /super.ts(8,17): error TS2304: Cannot find name 'InvalidReference'.
/typeReference.ts(6,17): error TS2315: Type 'U' is not generic. /typeReference.ts(6,17): error TS2315: Type 'U' is not generic.
@ -61,13 +61,13 @@
!!! error TS2304: Cannot find name 'InvalidReference'. !!! error TS2304: Cannot find name 'InvalidReference'.
==== /super.ts (2 errors) ==== ==== /super.ts (2 errors) ====
import { C } from "unknown"; import { A, B } from "unknown";
~~~~~~~~~ ~~~~~~~~~
!!! error TS2307: Cannot find module 'unknown'. !!! error TS2307: Cannot find module 'unknown'.
type T = number; type T = number;
export class D extends C { export class C extends A<B> {
m() { m() {
super.m<T>(1); super.m<T>(1);
super.m<InvalidReference>(); // Should get error for type argument super.m<InvalidReference>(); // Should get error for type argument

View file

@ -35,11 +35,11 @@ g<U>();
g<InvalidReference>(); // Should get error for type argument g<InvalidReference>(); // Should get error for type argument
//// [super.ts] //// [super.ts]
import { C } from "unknown"; import { A, B } from "unknown";
type T = number; type T = number;
export class D extends C { export class C extends A<B> {
m() { m() {
super.m<T>(1); super.m<T>(1);
super.m<InvalidReference>(); // Should get error for type argument super.m<InvalidReference>(); // Should get error for type argument
@ -108,15 +108,15 @@ var __extends = (this && this.__extends) || (function () {
})(); })();
exports.__esModule = true; exports.__esModule = true;
var unknown_1 = require("unknown"); var unknown_1 = require("unknown");
var D = (function (_super) { var C = (function (_super) {
__extends(D, _super); __extends(C, _super);
function D() { function C() {
return _super !== null && _super.apply(this, arguments) || this; return _super !== null && _super.apply(this, arguments) || this;
} }
D.prototype.m = function () { C.prototype.m = function () {
_super.prototype.m.call(this, 1); _super.prototype.m.call(this, 1);
_super.prototype.m.call(this); // Should get error for type argument _super.prototype.m.call(this); // Should get error for type argument
}; };
return D; return C;
}(unknown_1.C)); }(unknown_1.A));
exports.D = D; exports.C = C;

View file

@ -34,11 +34,11 @@ g<U>();
g<InvalidReference>(); // Should get error for type argument g<InvalidReference>(); // Should get error for type argument
// @Filename: /super.ts // @Filename: /super.ts
import { C } from "unknown"; import { A, B } from "unknown";
type T = number; type T = number;
export class D extends C { export class C extends A<B> {
m() { m() {
super.m<T>(1); super.m<T>(1);
super.m<InvalidReference>(); // Should get error for type argument super.m<InvalidReference>(); // Should get error for type argument