forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: class field is not accessible via super (microsoft#54056)
Co-authored-by: Nathan Shively-Sanders <[email protected]>
- Loading branch information
Showing
13 changed files
with
300 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//// [tests/cases/compiler/classFieldSuperAccessible.ts] //// | ||
|
||
//// [classFieldSuperAccessible.ts] | ||
class A extends class Expr {} { | ||
static { | ||
console.log(super.name); | ||
} | ||
} | ||
class B extends Number { | ||
static { | ||
console.log(super.EPSILON); | ||
} | ||
} | ||
class C extends Array { | ||
foo() { | ||
console.log(super.length); | ||
} | ||
} | ||
|
||
|
||
//// [classFieldSuperAccessible.js] | ||
class A extends class Expr { | ||
} { | ||
static { | ||
console.log(super.name); | ||
} | ||
} | ||
class B extends Number { | ||
static { | ||
console.log(super.EPSILON); | ||
} | ||
} | ||
class C extends Array { | ||
foo() { | ||
console.log(super.length); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/classFieldSuperAccessible.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//// [tests/cases/compiler/classFieldSuperAccessible.ts] //// | ||
|
||
=== classFieldSuperAccessible.ts === | ||
class A extends class Expr {} { | ||
>A : Symbol(A, Decl(classFieldSuperAccessible.ts, 0, 0)) | ||
>Expr : Symbol(Expr, Decl(classFieldSuperAccessible.ts, 0, 15)) | ||
|
||
static { | ||
console.log(super.name); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>super.name : Symbol(Function.name, Decl(lib.es2015.core.d.ts, --, --)) | ||
>super : Symbol(Expr, Decl(classFieldSuperAccessible.ts, 0, 15)) | ||
>name : Symbol(Function.name, Decl(lib.es2015.core.d.ts, --, --)) | ||
} | ||
} | ||
class B extends Number { | ||
>B : Symbol(B, Decl(classFieldSuperAccessible.ts, 4, 1)) | ||
>Number : Symbol(Number, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2020.number.d.ts, --, --)) | ||
|
||
static { | ||
console.log(super.EPSILON); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>super.EPSILON : Symbol(NumberConstructor.EPSILON, Decl(lib.es2015.core.d.ts, --, --)) | ||
>super : Symbol(NumberConstructor, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) | ||
>EPSILON : Symbol(NumberConstructor.EPSILON, Decl(lib.es2015.core.d.ts, --, --)) | ||
} | ||
} | ||
class C extends Array { | ||
>C : Symbol(C, Decl(classFieldSuperAccessible.ts, 9, 1)) | ||
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) | ||
|
||
foo() { | ||
>foo : Symbol(C.foo, Decl(classFieldSuperAccessible.ts, 10, 23)) | ||
|
||
console.log(super.length); | ||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) | ||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) | ||
>super.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) | ||
>super : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 4 more) | ||
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//// [tests/cases/compiler/classFieldSuperAccessible.ts] //// | ||
|
||
=== classFieldSuperAccessible.ts === | ||
class A extends class Expr {} { | ||
>A : A | ||
>class Expr {} : Expr | ||
>Expr : typeof Expr | ||
|
||
static { | ||
console.log(super.name); | ||
>console.log(super.name) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>super.name : string | ||
>super : typeof Expr | ||
>name : string | ||
} | ||
} | ||
class B extends Number { | ||
>B : B | ||
>Number : Number | ||
|
||
static { | ||
console.log(super.EPSILON); | ||
>console.log(super.EPSILON) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>super.EPSILON : number | ||
>super : NumberConstructor | ||
>EPSILON : number | ||
} | ||
} | ||
class C extends Array { | ||
>C : C | ||
>Array : any[] | ||
|
||
foo() { | ||
>foo : () => void | ||
|
||
console.log(super.length); | ||
>console.log(super.length) : void | ||
>console.log : (...data: any[]) => void | ||
>console : Console | ||
>log : (...data: any[]) => void | ||
>super.length : number | ||
>super : any[] | ||
>length : number | ||
} | ||
} | ||
|
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/classFieldSuperNotAccessible.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
classFieldSuperNotAccessible.ts(6,15): error TS2855: Class field 'field' defined by the parent class is not accessible in the child class via super. | ||
|
||
|
||
==== classFieldSuperNotAccessible.ts (1 errors) ==== | ||
class T { | ||
field = () => {} | ||
} | ||
class T2 extends T { | ||
f() { | ||
super.field() // error | ||
~~~~~ | ||
!!! error TS2855: Class field 'field' defined by the parent class is not accessible in the child class via super. | ||
} | ||
} | ||
|
||
new T2().f() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//// [tests/cases/compiler/classFieldSuperNotAccessible.ts] //// | ||
|
||
//// [classFieldSuperNotAccessible.ts] | ||
class T { | ||
field = () => {} | ||
} | ||
class T2 extends T { | ||
f() { | ||
super.field() // error | ||
} | ||
} | ||
|
||
new T2().f() | ||
|
||
|
||
//// [classFieldSuperNotAccessible.js] | ||
class T { | ||
field = () => { }; | ||
} | ||
class T2 extends T { | ||
f() { | ||
super.field(); // error | ||
} | ||
} | ||
new T2().f(); |
28 changes: 28 additions & 0 deletions
28
tests/baselines/reference/classFieldSuperNotAccessible.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//// [tests/cases/compiler/classFieldSuperNotAccessible.ts] //// | ||
|
||
=== classFieldSuperNotAccessible.ts === | ||
class T { | ||
>T : Symbol(T, Decl(classFieldSuperNotAccessible.ts, 0, 0)) | ||
|
||
field = () => {} | ||
>field : Symbol(T.field, Decl(classFieldSuperNotAccessible.ts, 0, 9)) | ||
} | ||
class T2 extends T { | ||
>T2 : Symbol(T2, Decl(classFieldSuperNotAccessible.ts, 2, 1)) | ||
>T : Symbol(T, Decl(classFieldSuperNotAccessible.ts, 0, 0)) | ||
|
||
f() { | ||
>f : Symbol(T2.f, Decl(classFieldSuperNotAccessible.ts, 3, 20)) | ||
|
||
super.field() // error | ||
>super.field : Symbol(T.field, Decl(classFieldSuperNotAccessible.ts, 0, 9)) | ||
>super : Symbol(T, Decl(classFieldSuperNotAccessible.ts, 0, 0)) | ||
>field : Symbol(T.field, Decl(classFieldSuperNotAccessible.ts, 0, 9)) | ||
} | ||
} | ||
|
||
new T2().f() | ||
>new T2().f : Symbol(T2.f, Decl(classFieldSuperNotAccessible.ts, 3, 20)) | ||
>T2 : Symbol(T2, Decl(classFieldSuperNotAccessible.ts, 2, 1)) | ||
>f : Symbol(T2.f, Decl(classFieldSuperNotAccessible.ts, 3, 20)) | ||
|
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/classFieldSuperNotAccessible.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//// [tests/cases/compiler/classFieldSuperNotAccessible.ts] //// | ||
|
||
=== classFieldSuperNotAccessible.ts === | ||
class T { | ||
>T : T | ||
|
||
field = () => {} | ||
>field : () => void | ||
>() => {} : () => void | ||
} | ||
class T2 extends T { | ||
>T2 : T2 | ||
>T : T | ||
|
||
f() { | ||
>f : () => void | ||
|
||
super.field() // error | ||
>super.field() : void | ||
>super.field : () => void | ||
>super : T | ||
>field : () => void | ||
} | ||
} | ||
|
||
new T2().f() | ||
>new T2().f() : void | ||
>new T2().f : () => void | ||
>new T2() : T2 | ||
>T2 : typeof T2 | ||
>f : () => void | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// @target: esnext | ||
class A extends class Expr {} { | ||
static { | ||
console.log(super.name); | ||
} | ||
} | ||
class B extends Number { | ||
static { | ||
console.log(super.EPSILON); | ||
} | ||
} | ||
class C extends Array { | ||
foo() { | ||
console.log(super.length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// @target: esnext | ||
class T { | ||
field = () => {} | ||
} | ||
class T2 extends T { | ||
f() { | ||
super.field() // error | ||
} | ||
} | ||
|
||
new T2().f() |