From c172c067779caf4cdd12ba98ecc702baf3d33db8 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 19 May 2016 10:35:29 -0700 Subject: [PATCH] Test assignability of inherited generic default constructor --- .../genericInheritedImplicitConstructors.js | 37 ++++++++++++++++++ ...nericInheritedImplicitConstructors.symbols | 38 +++++++++++++++++++ ...genericInheritedImplicitConstructors.types | 38 +++++++++++++++++++ .../genericInheritedDefaultConstructors.ts | 13 +++++++ 4 files changed, 126 insertions(+) create mode 100644 tests/baselines/reference/genericInheritedImplicitConstructors.js create mode 100644 tests/baselines/reference/genericInheritedImplicitConstructors.symbols create mode 100644 tests/baselines/reference/genericInheritedImplicitConstructors.types create mode 100644 tests/cases/compiler/genericInheritedDefaultConstructors.ts diff --git a/tests/baselines/reference/genericInheritedImplicitConstructors.js b/tests/baselines/reference/genericInheritedImplicitConstructors.js new file mode 100644 index 0000000000..87c715c7aa --- /dev/null +++ b/tests/baselines/reference/genericInheritedImplicitConstructors.js @@ -0,0 +1,37 @@ +//// [genericInheritedImplicitConstructors.ts] +interface Constructor { + new(...args: any[]): T; + prototype: T; +} + +class A { a: U; } +class B extends A { b: V; } +var c:Constructor> = B; // error here + +//class A1 { a: boolean; } +//class B1 extends A1 { b: boolean; } +//var c1:Constructor = B1; // no error here + + +//// [genericInheritedImplicitConstructors.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var A = (function () { + function A() { + } + return A; +}()); +var B = (function (_super) { + __extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; +}(A)); +var c = B; // error here +//class A1 { a: boolean; } +//class B1 extends A1 { b: boolean; } +//var c1:Constructor = B1; // no error here diff --git a/tests/baselines/reference/genericInheritedImplicitConstructors.symbols b/tests/baselines/reference/genericInheritedImplicitConstructors.symbols new file mode 100644 index 0000000000..82a13ff05f --- /dev/null +++ b/tests/baselines/reference/genericInheritedImplicitConstructors.symbols @@ -0,0 +1,38 @@ +=== tests/cases/compiler/genericInheritedImplicitConstructors.ts === +interface Constructor { +>Constructor : Symbol(Constructor, Decl(genericInheritedImplicitConstructors.ts, 0, 0)) +>T : Symbol(T, Decl(genericInheritedImplicitConstructors.ts, 0, 22)) + + new(...args: any[]): T; +>args : Symbol(args, Decl(genericInheritedImplicitConstructors.ts, 1, 8)) +>T : Symbol(T, Decl(genericInheritedImplicitConstructors.ts, 0, 22)) + + prototype: T; +>prototype : Symbol(Constructor.prototype, Decl(genericInheritedImplicitConstructors.ts, 1, 27)) +>T : Symbol(T, Decl(genericInheritedImplicitConstructors.ts, 0, 22)) +} + +class A { a: U; } +>A : Symbol(A, Decl(genericInheritedImplicitConstructors.ts, 3, 1)) +>U : Symbol(U, Decl(genericInheritedImplicitConstructors.ts, 5, 8)) +>a : Symbol(A.a, Decl(genericInheritedImplicitConstructors.ts, 5, 12)) +>U : Symbol(U, Decl(genericInheritedImplicitConstructors.ts, 5, 8)) + +class B extends A { b: V; } +>B : Symbol(B, Decl(genericInheritedImplicitConstructors.ts, 5, 20)) +>V : Symbol(V, Decl(genericInheritedImplicitConstructors.ts, 6, 8)) +>A : Symbol(A, Decl(genericInheritedImplicitConstructors.ts, 3, 1)) +>V : Symbol(V, Decl(genericInheritedImplicitConstructors.ts, 6, 8)) +>b : Symbol(B.b, Decl(genericInheritedImplicitConstructors.ts, 6, 25)) +>V : Symbol(V, Decl(genericInheritedImplicitConstructors.ts, 6, 8)) + +var c:Constructor> = B; // error here +>c : Symbol(c, Decl(genericInheritedImplicitConstructors.ts, 7, 3)) +>Constructor : Symbol(Constructor, Decl(genericInheritedImplicitConstructors.ts, 0, 0)) +>B : Symbol(B, Decl(genericInheritedImplicitConstructors.ts, 5, 20)) +>B : Symbol(B, Decl(genericInheritedImplicitConstructors.ts, 5, 20)) + +//class A1 { a: boolean; } +//class B1 extends A1 { b: boolean; } +//var c1:Constructor = B1; // no error here + diff --git a/tests/baselines/reference/genericInheritedImplicitConstructors.types b/tests/baselines/reference/genericInheritedImplicitConstructors.types new file mode 100644 index 0000000000..3535cd95de --- /dev/null +++ b/tests/baselines/reference/genericInheritedImplicitConstructors.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/genericInheritedImplicitConstructors.ts === +interface Constructor { +>Constructor : Constructor +>T : T + + new(...args: any[]): T; +>args : any[] +>T : T + + prototype: T; +>prototype : T +>T : T +} + +class A { a: U; } +>A : A +>U : U +>a : U +>U : U + +class B extends A { b: V; } +>B : B +>V : V +>A : A +>V : V +>b : V +>V : V + +var c:Constructor> = B; // error here +>c : Constructor> +>Constructor : Constructor +>B : B +>B : typeof B + +//class A1 { a: boolean; } +//class B1 extends A1 { b: boolean; } +//var c1:Constructor = B1; // no error here + diff --git a/tests/cases/compiler/genericInheritedDefaultConstructors.ts b/tests/cases/compiler/genericInheritedDefaultConstructors.ts new file mode 100644 index 0000000000..dfe21f418e --- /dev/null +++ b/tests/cases/compiler/genericInheritedDefaultConstructors.ts @@ -0,0 +1,13 @@ +interface Constructor { + new(...args: any[]): T; + prototype: T; +} + +class A { a: U; } +class B extends A { b: V; } +var c:Constructor> = B; // error here +var x = new B(); + +//class A1 { a: boolean; } +//class B1 extends A1 { b: boolean; } +//var c1:Constructor = B1; // no error here