Instantiate this-type in super property access

This commit is contained in:
Nathan Shively-Sanders
2016-05-24 13:07:34 -07:00
parent e67df33bcf
commit a323fdf49d
6 changed files with 371 additions and 78 deletions

View File

@@ -8569,7 +8569,7 @@ namespace ts {
return nodeCheckFlag === NodeCheckFlags.SuperStatic
? getBaseConstructorTypeOfClass(classType)
: baseClassType;
: getTypeWithThisArgument(baseClassType, classType.thisType);
function isLegalUsageOfSuperExpression(container: Node): boolean {
if (!container) {

View File

@@ -1,75 +0,0 @@
tests/cases/conformance/expressions/superPropertyAccess/superPropertyAccessNoError.ts(33,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/expressions/superPropertyAccess/superPropertyAccessNoError.ts(39,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/expressions/superPropertyAccess/superPropertyAccessNoError.ts(49,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/expressions/superPropertyAccess/superPropertyAccessNoError.ts(55,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
==== tests/cases/conformance/expressions/superPropertyAccess/superPropertyAccessNoError.ts (4 errors) ====
//super.publicInstanceMemberFunction in constructor of derived class
//super.publicInstanceMemberFunction in instance member function of derived class
//super.publicInstanceMemberFunction in instance member accessor(get and set) of derived class
//super.publicInstanceMemberFunction in lambda in member function
//super.publicStaticMemberFunction in static member function of derived class
//super.publicStaticMemberFunction in static member accessor(get and set) of derived class
class SomeBaseClass {
public func() {
return '';
}
static func() {
return 3;
}
}
class SomeDerivedClass extends SomeBaseClass {
constructor() {
super();
var x = super.func();
var x: string;
}
fn() {
var x = super.func();
var x: string;
var y = () => super.func();
}
get a() {
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
var x = super.func();
var x: string;
return null;
}
set a(n) {
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
var x = super.func();
var x: string;
}
static fn() {
var x = super.func();
var x: number;
}
static get a() {
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
var x = super.func();
var x: number;
return null;
}
static set a(n) {
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
var x = super.func();
var x: number;
}
}

View File

@@ -16,6 +16,9 @@ class SomeBaseClass {
return 3;
}
returnThis() {
return this;
}
}
class SomeDerivedClass extends SomeBaseClass {
@@ -58,7 +61,14 @@ class SomeDerivedClass extends SomeBaseClass {
var x: number;
}
}
returnThis() {
return super.returnThis();
}
}
let instance = new SomeDerivedClass();
instance.returnThis().fn();
//// [superPropertyAccessNoError.js]
//super.publicInstanceMemberFunction in constructor of derived class
@@ -81,6 +91,9 @@ var SomeBaseClass = (function () {
SomeBaseClass.func = function () {
return 3;
};
SomeBaseClass.prototype.returnThis = function () {
return this;
};
return SomeBaseClass;
}());
var SomeDerivedClass = (function (_super) {
@@ -126,5 +139,10 @@ var SomeDerivedClass = (function (_super) {
enumerable: true,
configurable: true
});
SomeDerivedClass.prototype.returnThis = function () {
return _super.prototype.returnThis.call(this);
};
return SomeDerivedClass;
}(SomeBaseClass));
var instance = new SomeDerivedClass();
instance.returnThis().fn();

View File

@@ -0,0 +1,161 @@
=== tests/cases/conformance/expressions/superPropertyAccess/superPropertyAccessNoError.ts ===
//super.publicInstanceMemberFunction in constructor of derived class
//super.publicInstanceMemberFunction in instance member function of derived class
//super.publicInstanceMemberFunction in instance member accessor(get and set) of derived class
//super.publicInstanceMemberFunction in lambda in member function
//super.publicStaticMemberFunction in static member function of derived class
//super.publicStaticMemberFunction in static member accessor(get and set) of derived class
class SomeBaseClass {
>SomeBaseClass : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
public func() {
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
return '';
}
static func() {
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
return 3;
}
returnThis() {
>returnThis : Symbol(SomeBaseClass.returnThis, Decl(superPropertyAccessNoError.ts, 15, 5))
return this;
>this : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
}
}
class SomeDerivedClass extends SomeBaseClass {
>SomeDerivedClass : Symbol(SomeDerivedClass, Decl(superPropertyAccessNoError.ts, 20, 1))
>SomeBaseClass : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
constructor() {
super();
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
var x = super.func();
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 25, 11), Decl(superPropertyAccessNoError.ts, 26, 11))
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
var x: string;
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 25, 11), Decl(superPropertyAccessNoError.ts, 26, 11))
}
fn() {
>fn : Symbol(SomeDerivedClass.fn, Decl(superPropertyAccessNoError.ts, 27, 5))
var x = super.func();
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 30, 11), Decl(superPropertyAccessNoError.ts, 31, 11))
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
var x: string;
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 30, 11), Decl(superPropertyAccessNoError.ts, 31, 11))
var y = () => super.func();
>y : Symbol(y, Decl(superPropertyAccessNoError.ts, 32, 11))
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
}
get a() {
>a : Symbol(SomeDerivedClass.a, Decl(superPropertyAccessNoError.ts, 33, 5), Decl(superPropertyAccessNoError.ts, 39, 5))
var x = super.func();
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 36, 11), Decl(superPropertyAccessNoError.ts, 37, 11))
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
var x: string;
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 36, 11), Decl(superPropertyAccessNoError.ts, 37, 11))
return null;
}
set a(n) {
>a : Symbol(SomeDerivedClass.a, Decl(superPropertyAccessNoError.ts, 33, 5), Decl(superPropertyAccessNoError.ts, 39, 5))
>n : Symbol(n, Decl(superPropertyAccessNoError.ts, 41, 10))
var x = super.func();
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 42, 11), Decl(superPropertyAccessNoError.ts, 43, 11))
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 8, 21))
var x: string;
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 42, 11), Decl(superPropertyAccessNoError.ts, 43, 11))
}
static fn() {
>fn : Symbol(SomeDerivedClass.fn, Decl(superPropertyAccessNoError.ts, 44, 5))
var x = super.func();
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 47, 11), Decl(superPropertyAccessNoError.ts, 48, 11))
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
var x: number;
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 47, 11), Decl(superPropertyAccessNoError.ts, 48, 11))
}
static get a() {
>a : Symbol(SomeDerivedClass.a, Decl(superPropertyAccessNoError.ts, 49, 5), Decl(superPropertyAccessNoError.ts, 55, 5))
var x = super.func();
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 52, 11), Decl(superPropertyAccessNoError.ts, 53, 11))
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
var x: number;
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 52, 11), Decl(superPropertyAccessNoError.ts, 53, 11))
return null;
}
static set a(n) {
>a : Symbol(SomeDerivedClass.a, Decl(superPropertyAccessNoError.ts, 49, 5), Decl(superPropertyAccessNoError.ts, 55, 5))
>n : Symbol(n, Decl(superPropertyAccessNoError.ts, 57, 17))
var x = super.func();
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 58, 11), Decl(superPropertyAccessNoError.ts, 59, 11))
>super.func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
>func : Symbol(SomeBaseClass.func, Decl(superPropertyAccessNoError.ts, 11, 5))
var x: number;
>x : Symbol(x, Decl(superPropertyAccessNoError.ts, 58, 11), Decl(superPropertyAccessNoError.ts, 59, 11))
}
returnThis() {
>returnThis : Symbol(SomeDerivedClass.returnThis, Decl(superPropertyAccessNoError.ts, 60, 5))
return super.returnThis();
>super.returnThis : Symbol(SomeBaseClass.returnThis, Decl(superPropertyAccessNoError.ts, 15, 5))
>super : Symbol(SomeBaseClass, Decl(superPropertyAccessNoError.ts, 0, 0))
>returnThis : Symbol(SomeBaseClass.returnThis, Decl(superPropertyAccessNoError.ts, 15, 5))
}
}
let instance = new SomeDerivedClass();
>instance : Symbol(instance, Decl(superPropertyAccessNoError.ts, 67, 3))
>SomeDerivedClass : Symbol(SomeDerivedClass, Decl(superPropertyAccessNoError.ts, 20, 1))
instance.returnThis().fn();
>instance.returnThis().fn : Symbol(SomeDerivedClass.fn, Decl(superPropertyAccessNoError.ts, 27, 5))
>instance.returnThis : Symbol(SomeDerivedClass.returnThis, Decl(superPropertyAccessNoError.ts, 60, 5))
>instance : Symbol(instance, Decl(superPropertyAccessNoError.ts, 67, 3))
>returnThis : Symbol(SomeDerivedClass.returnThis, Decl(superPropertyAccessNoError.ts, 60, 5))
>fn : Symbol(SomeDerivedClass.fn, Decl(superPropertyAccessNoError.ts, 27, 5))

View File

@@ -0,0 +1,179 @@
=== tests/cases/conformance/expressions/superPropertyAccess/superPropertyAccessNoError.ts ===
//super.publicInstanceMemberFunction in constructor of derived class
//super.publicInstanceMemberFunction in instance member function of derived class
//super.publicInstanceMemberFunction in instance member accessor(get and set) of derived class
//super.publicInstanceMemberFunction in lambda in member function
//super.publicStaticMemberFunction in static member function of derived class
//super.publicStaticMemberFunction in static member accessor(get and set) of derived class
class SomeBaseClass {
>SomeBaseClass : SomeBaseClass
public func() {
>func : () => string
return '';
>'' : string
}
static func() {
>func : () => number
return 3;
>3 : number
}
returnThis() {
>returnThis : () => this
return this;
>this : this
}
}
class SomeDerivedClass extends SomeBaseClass {
>SomeDerivedClass : SomeDerivedClass
>SomeBaseClass : SomeBaseClass
constructor() {
super();
>super() : void
>super : typeof SomeBaseClass
var x = super.func();
>x : string
>super.func() : string
>super.func : () => string
>super : SomeBaseClass
>func : () => string
var x: string;
>x : string
}
fn() {
>fn : () => void
var x = super.func();
>x : string
>super.func() : string
>super.func : () => string
>super : SomeBaseClass
>func : () => string
var x: string;
>x : string
var y = () => super.func();
>y : () => string
>() => super.func() : () => string
>super.func() : string
>super.func : () => string
>super : SomeBaseClass
>func : () => string
}
get a() {
>a : any
var x = super.func();
>x : string
>super.func() : string
>super.func : () => string
>super : SomeBaseClass
>func : () => string
var x: string;
>x : string
return null;
>null : null
}
set a(n) {
>a : any
>n : any
var x = super.func();
>x : string
>super.func() : string
>super.func : () => string
>super : SomeBaseClass
>func : () => string
var x: string;
>x : string
}
static fn() {
>fn : () => void
var x = super.func();
>x : number
>super.func() : number
>super.func : () => number
>super : typeof SomeBaseClass
>func : () => number
var x: number;
>x : number
}
static get a() {
>a : any
var x = super.func();
>x : number
>super.func() : number
>super.func : () => number
>super : typeof SomeBaseClass
>func : () => number
var x: number;
>x : number
return null;
>null : null
}
static set a(n) {
>a : any
>n : any
var x = super.func();
>x : number
>super.func() : number
>super.func : () => number
>super : typeof SomeBaseClass
>func : () => number
var x: number;
>x : number
}
returnThis() {
>returnThis : () => this
return super.returnThis();
>super.returnThis() : this
>super.returnThis : () => this
>super : SomeBaseClass
>returnThis : () => this
}
}
let instance = new SomeDerivedClass();
>instance : SomeDerivedClass
>new SomeDerivedClass() : SomeDerivedClass
>SomeDerivedClass : typeof SomeDerivedClass
instance.returnThis().fn();
>instance.returnThis().fn() : void
>instance.returnThis().fn : () => void
>instance.returnThis() : SomeDerivedClass
>instance.returnThis : () => SomeDerivedClass
>instance : SomeDerivedClass
>returnThis : () => SomeDerivedClass
>fn : () => void

View File

@@ -1,3 +1,4 @@
// @target: es5
//super.publicInstanceMemberFunction in constructor of derived class
//super.publicInstanceMemberFunction in instance member function of derived class
//super.publicInstanceMemberFunction in instance member accessor(get and set) of derived class
@@ -15,6 +16,9 @@ class SomeBaseClass {
return 3;
}
returnThis() {
return this;
}
}
class SomeDerivedClass extends SomeBaseClass {
@@ -57,4 +61,10 @@ class SomeDerivedClass extends SomeBaseClass {
var x: number;
}
}
returnThis() {
return super.returnThis();
}
}
let instance = new SomeDerivedClass();
instance.returnThis().fn();