From dd84d7ca483c6a94592b592ab07fb980c21e2732 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 13 Mar 2017 13:24:14 -0700 Subject: [PATCH] Add repro --- .../overrideBaseIntersectionMethod.js | 83 ++++++++++++++ .../overrideBaseIntersectionMethod.symbols | 88 +++++++++++++++ .../overrideBaseIntersectionMethod.types | 102 ++++++++++++++++++ .../overrideBaseIntersectionMethod.ts | 31 ++++++ 4 files changed, 304 insertions(+) create mode 100644 tests/baselines/reference/overrideBaseIntersectionMethod.js create mode 100644 tests/baselines/reference/overrideBaseIntersectionMethod.symbols create mode 100644 tests/baselines/reference/overrideBaseIntersectionMethod.types create mode 100644 tests/cases/compiler/overrideBaseIntersectionMethod.ts diff --git a/tests/baselines/reference/overrideBaseIntersectionMethod.js b/tests/baselines/reference/overrideBaseIntersectionMethod.js new file mode 100644 index 00000000000..26613f07469 --- /dev/null +++ b/tests/baselines/reference/overrideBaseIntersectionMethod.js @@ -0,0 +1,83 @@ +//// [overrideBaseIntersectionMethod.ts] + +// Repro from #14615 + +type Constructor = new (...args: any[]) => T; + +const WithLocation = >(Base: T) => class extends Base { + getLocation(): [number, number] { + const [x,y] = super.getLocation(); + return [this.x | x, this.y | y]; + } +} + +class Point { + constructor(public x: number, public y: number) { } + getLocation(): [number, number] { + return [0,0]; + } +} + +class Foo extends WithLocation(Point) { + calculate() { + return this.x + this.y; + } + getLocation() { + return super.getLocation() + } + whereAmI() { + return this.getLocation(); + } +} + + +//// [overrideBaseIntersectionMethod.js] +// Repro from #14615 +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var WithLocation = function (Base) { return (function (_super) { + __extends(class_1, _super); + function class_1() { + return _super !== null && _super.apply(this, arguments) || this; + } + class_1.prototype.getLocation = function () { + var _a = _super.prototype.getLocation.call(this), x = _a[0], y = _a[1]; + return [this.x | x, this.y | y]; + }; + return class_1; +}(Base)); }; +var Point = (function () { + function Point(x, y) { + this.x = x; + this.y = y; + } + Point.prototype.getLocation = function () { + return [0, 0]; + }; + return Point; +}()); +var Foo = (function (_super) { + __extends(Foo, _super); + function Foo() { + return _super !== null && _super.apply(this, arguments) || this; + } + Foo.prototype.calculate = function () { + return this.x + this.y; + }; + Foo.prototype.getLocation = function () { + return _super.prototype.getLocation.call(this); + }; + Foo.prototype.whereAmI = function () { + return this.getLocation(); + }; + return Foo; +}(WithLocation(Point))); diff --git a/tests/baselines/reference/overrideBaseIntersectionMethod.symbols b/tests/baselines/reference/overrideBaseIntersectionMethod.symbols new file mode 100644 index 00000000000..45a84543408 --- /dev/null +++ b/tests/baselines/reference/overrideBaseIntersectionMethod.symbols @@ -0,0 +1,88 @@ +=== tests/cases/compiler/overrideBaseIntersectionMethod.ts === + +// Repro from #14615 + +type Constructor = new (...args: any[]) => T; +>Constructor : Symbol(Constructor, Decl(overrideBaseIntersectionMethod.ts, 0, 0)) +>T : Symbol(T, Decl(overrideBaseIntersectionMethod.ts, 3, 17)) +>args : Symbol(args, Decl(overrideBaseIntersectionMethod.ts, 3, 27)) +>T : Symbol(T, Decl(overrideBaseIntersectionMethod.ts, 3, 17)) + +const WithLocation = >(Base: T) => class extends Base { +>WithLocation : Symbol(WithLocation, Decl(overrideBaseIntersectionMethod.ts, 5, 5)) +>T : Symbol(T, Decl(overrideBaseIntersectionMethod.ts, 5, 22)) +>Constructor : Symbol(Constructor, Decl(overrideBaseIntersectionMethod.ts, 0, 0)) +>Point : Symbol(Point, Decl(overrideBaseIntersectionMethod.ts, 10, 1)) +>Base : Symbol(Base, Decl(overrideBaseIntersectionMethod.ts, 5, 52)) +>T : Symbol(T, Decl(overrideBaseIntersectionMethod.ts, 5, 22)) +>Base : Symbol(Base, Decl(overrideBaseIntersectionMethod.ts, 5, 52)) + + getLocation(): [number, number] { +>getLocation : Symbol((Anonymous class).getLocation, Decl(overrideBaseIntersectionMethod.ts, 5, 84)) + + const [x,y] = super.getLocation(); +>x : Symbol(x, Decl(overrideBaseIntersectionMethod.ts, 7, 11)) +>y : Symbol(y, Decl(overrideBaseIntersectionMethod.ts, 7, 13)) +>super.getLocation : Symbol(Point.getLocation, Decl(overrideBaseIntersectionMethod.ts, 13, 53)) +>super : Symbol(Point, Decl(overrideBaseIntersectionMethod.ts, 10, 1)) +>getLocation : Symbol(Point.getLocation, Decl(overrideBaseIntersectionMethod.ts, 13, 53)) + + return [this.x | x, this.y | y]; +>this.x : Symbol(Point.x, Decl(overrideBaseIntersectionMethod.ts, 13, 14)) +>this : Symbol((Anonymous class), Decl(overrideBaseIntersectionMethod.ts, 5, 63)) +>x : Symbol(Point.x, Decl(overrideBaseIntersectionMethod.ts, 13, 14)) +>x : Symbol(x, Decl(overrideBaseIntersectionMethod.ts, 7, 11)) +>this.y : Symbol(Point.y, Decl(overrideBaseIntersectionMethod.ts, 13, 31)) +>this : Symbol((Anonymous class), Decl(overrideBaseIntersectionMethod.ts, 5, 63)) +>y : Symbol(Point.y, Decl(overrideBaseIntersectionMethod.ts, 13, 31)) +>y : Symbol(y, Decl(overrideBaseIntersectionMethod.ts, 7, 13)) + } +} + +class Point { +>Point : Symbol(Point, Decl(overrideBaseIntersectionMethod.ts, 10, 1)) + + constructor(public x: number, public y: number) { } +>x : Symbol(Point.x, Decl(overrideBaseIntersectionMethod.ts, 13, 14)) +>y : Symbol(Point.y, Decl(overrideBaseIntersectionMethod.ts, 13, 31)) + + getLocation(): [number, number] { +>getLocation : Symbol(Point.getLocation, Decl(overrideBaseIntersectionMethod.ts, 13, 53)) + + return [0,0]; + } +} + +class Foo extends WithLocation(Point) { +>Foo : Symbol(Foo, Decl(overrideBaseIntersectionMethod.ts, 17, 1)) +>WithLocation : Symbol(WithLocation, Decl(overrideBaseIntersectionMethod.ts, 5, 5)) +>Point : Symbol(Point, Decl(overrideBaseIntersectionMethod.ts, 10, 1)) + + calculate() { +>calculate : Symbol(Foo.calculate, Decl(overrideBaseIntersectionMethod.ts, 19, 39)) + + return this.x + this.y; +>this.x : Symbol(Point.x, Decl(overrideBaseIntersectionMethod.ts, 13, 14)) +>this : Symbol(Foo, Decl(overrideBaseIntersectionMethod.ts, 17, 1)) +>x : Symbol(Point.x, Decl(overrideBaseIntersectionMethod.ts, 13, 14)) +>this.y : Symbol(Point.y, Decl(overrideBaseIntersectionMethod.ts, 13, 31)) +>this : Symbol(Foo, Decl(overrideBaseIntersectionMethod.ts, 17, 1)) +>y : Symbol(Point.y, Decl(overrideBaseIntersectionMethod.ts, 13, 31)) + } + getLocation() { +>getLocation : Symbol(Foo.getLocation, Decl(overrideBaseIntersectionMethod.ts, 22, 3)) + + return super.getLocation() +>super.getLocation : Symbol(getLocation, Decl(overrideBaseIntersectionMethod.ts, 5, 84), Decl(overrideBaseIntersectionMethod.ts, 13, 53)) +>getLocation : Symbol(getLocation, Decl(overrideBaseIntersectionMethod.ts, 5, 84), Decl(overrideBaseIntersectionMethod.ts, 13, 53)) + } + whereAmI() { +>whereAmI : Symbol(Foo.whereAmI, Decl(overrideBaseIntersectionMethod.ts, 25, 3)) + + return this.getLocation(); +>this.getLocation : Symbol(Foo.getLocation, Decl(overrideBaseIntersectionMethod.ts, 22, 3)) +>this : Symbol(Foo, Decl(overrideBaseIntersectionMethod.ts, 17, 1)) +>getLocation : Symbol(Foo.getLocation, Decl(overrideBaseIntersectionMethod.ts, 22, 3)) + } +} + diff --git a/tests/baselines/reference/overrideBaseIntersectionMethod.types b/tests/baselines/reference/overrideBaseIntersectionMethod.types new file mode 100644 index 00000000000..3e31211bdbf --- /dev/null +++ b/tests/baselines/reference/overrideBaseIntersectionMethod.types @@ -0,0 +1,102 @@ +=== tests/cases/compiler/overrideBaseIntersectionMethod.ts === + +// Repro from #14615 + +type Constructor = new (...args: any[]) => T; +>Constructor : Constructor +>T : T +>args : any[] +>T : T + +const WithLocation = >(Base: T) => class extends Base { +>WithLocation : >(Base: T) => { new (...args: any[]): (Anonymous class); prototype: .(Anonymous class); } & T +>>(Base: T) => class extends Base { getLocation(): [number, number] { const [x,y] = super.getLocation(); return [this.x | x, this.y | y]; }} : >(Base: T) => { new (...args: any[]): (Anonymous class); prototype: .(Anonymous class); } & T +>T : T +>Constructor : Constructor +>Point : Point +>Base : T +>T : T +>class extends Base { getLocation(): [number, number] { const [x,y] = super.getLocation(); return [this.x | x, this.y | y]; }} : { new (...args: any[]): (Anonymous class); prototype: .(Anonymous class); } & T +>Base : Point + + getLocation(): [number, number] { +>getLocation : () => [number, number] + + const [x,y] = super.getLocation(); +>x : number +>y : number +>super.getLocation() : [number, number] +>super.getLocation : () => [number, number] +>super : Point +>getLocation : () => [number, number] + + return [this.x | x, this.y | y]; +>[this.x | x, this.y | y] : [number, number] +>this.x | x : number +>this.x : number +>this : this +>x : number +>x : number +>this.y | y : number +>this.y : number +>this : this +>y : number +>y : number + } +} + +class Point { +>Point : Point + + constructor(public x: number, public y: number) { } +>x : number +>y : number + + getLocation(): [number, number] { +>getLocation : () => [number, number] + + return [0,0]; +>[0,0] : [number, number] +>0 : 0 +>0 : 0 + } +} + +class Foo extends WithLocation(Point) { +>Foo : Foo +>WithLocation(Point) : .(Anonymous class) & Point +>WithLocation : >(Base: T) => { new (...args: any[]): (Anonymous class); prototype: .(Anonymous class); } & T +>Point : typeof Point + + calculate() { +>calculate : () => number + + return this.x + this.y; +>this.x + this.y : number +>this.x : number +>this : this +>x : number +>this.y : number +>this : this +>y : number + } + getLocation() { +>getLocation : () => [number, number] + + return super.getLocation() +>super.getLocation() : [number, number] +>super.getLocation : () => [number, number] +>super : .(Anonymous class) & Point +>getLocation : () => [number, number] + } + whereAmI() { +>whereAmI : () => [number, number] + + return this.getLocation(); +>this.getLocation() : [number, number] +>this.getLocation : () => [number, number] +>this : this +>getLocation : () => [number, number] + } +} + diff --git a/tests/cases/compiler/overrideBaseIntersectionMethod.ts b/tests/cases/compiler/overrideBaseIntersectionMethod.ts new file mode 100644 index 00000000000..99cd4664bc5 --- /dev/null +++ b/tests/cases/compiler/overrideBaseIntersectionMethod.ts @@ -0,0 +1,31 @@ +// @strict: true + +// Repro from #14615 + +type Constructor = new (...args: any[]) => T; + +const WithLocation = >(Base: T) => class extends Base { + getLocation(): [number, number] { + const [x,y] = super.getLocation(); + return [this.x | x, this.y | y]; + } +} + +class Point { + constructor(public x: number, public y: number) { } + getLocation(): [number, number] { + return [0,0]; + } +} + +class Foo extends WithLocation(Point) { + calculate() { + return this.x + this.y; + } + getLocation() { + return super.getLocation() + } + whereAmI() { + return this.getLocation(); + } +}