-
Notifications
You must be signed in to change notification settings - Fork 583
Unify the way anonymous class symbols are printed in error messages #731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
privateNameMethodClassExpression2.ts(5,6): error TS18013: Property '#method' is not accessible outside class '(Anonymous class)' because it has a private identifier. | ||
privateNameMethodClassExpression2.ts(9,6): error TS18013: Property '#field' is not accessible outside class '(Anonymous class)' because it has a private identifier. | ||
|
||
|
||
==== privateNameMethodClassExpression2.ts (2 errors) ==== | ||
new (class { | ||
#method() { | ||
return 42; | ||
} | ||
})().#method; // error | ||
~~~~~~~ | ||
!!! error TS18013: Property '#method' is not accessible outside class '(Anonymous class)' because it has a private identifier. | ||
|
||
new (class { | ||
#field = 42; | ||
})().#field; // error | ||
~~~~~~ | ||
!!! error TS18013: Property '#field' is not accessible outside class '(Anonymous class)' because it has a private identifier. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//// [tests/cases/compiler/privateNameMethodClassExpression2.ts] //// | ||
|
||
=== privateNameMethodClassExpression2.ts === | ||
new (class { | ||
#method() { | ||
>#method : Symbol(#method, Decl(privateNameMethodClassExpression2.ts, 0, 12)) | ||
|
||
return 42; | ||
} | ||
})().#method; // error | ||
|
||
new (class { | ||
#field = 42; | ||
>#field : Symbol(#field, Decl(privateNameMethodClassExpression2.ts, 6, 12)) | ||
|
||
})().#field; // error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//// [tests/cases/compiler/privateNameMethodClassExpression2.ts] //// | ||
|
||
=== privateNameMethodClassExpression2.ts === | ||
new (class { | ||
>new (class { #method() { return 42; }})().#method : any | ||
>new (class { #method() { return 42; }})() : (Anonymous class) | ||
>(class { #method() { return 42; }}) : typeof (Anonymous class) | ||
>class { #method() { return 42; }} : typeof (Anonymous class) | ||
|
||
#method() { | ||
>#method : () => number | ||
|
||
return 42; | ||
>42 : 42 | ||
} | ||
})().#method; // error | ||
|
||
new (class { | ||
>new (class { #field = 42;})().#field : any | ||
>new (class { #field = 42;})() : (Anonymous class) | ||
>(class { #field = 42;}) : typeof (Anonymous class) | ||
>class { #field = 42;} : typeof (Anonymous class) | ||
|
||
#field = 42; | ||
>#field : number | ||
>42 : 42 | ||
|
||
})().#field; // error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
privateNamesUnique-6.ts(6,7): error TS2322: Type '(Anonymous class)' is not assignable to type 'A'. | ||
Property '#foo' in type '(Anonymous class)' refers to a different member that cannot be accessed from within type 'A'. | ||
|
||
|
||
==== privateNamesUnique-6.ts (1 errors) ==== | ||
class A { | ||
#foo: number; | ||
} | ||
|
||
// error | ||
const test: A = new (class { | ||
~~~~ | ||
!!! error TS2322: Type '(Anonymous class)' is not assignable to type 'A'. | ||
!!! error TS2322: Property '#foo' in type '(Anonymous class)' refers to a different member that cannot be accessed from within type 'A'. | ||
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strada would print Note this is a new test case, not one from Strada. |
||
#foo: number; | ||
})(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//// [tests/cases/compiler/privateNamesUnique-6.ts] //// | ||
|
||
=== privateNamesUnique-6.ts === | ||
class A { | ||
>A : Symbol(A, Decl(privateNamesUnique-6.ts, 0, 0)) | ||
|
||
#foo: number; | ||
>#foo : Symbol(#foo, Decl(privateNamesUnique-6.ts, 0, 9)) | ||
} | ||
|
||
// error | ||
const test: A = new (class { | ||
>test : Symbol(test, Decl(privateNamesUnique-6.ts, 5, 5)) | ||
>A : Symbol(A, Decl(privateNamesUnique-6.ts, 0, 0)) | ||
|
||
#foo: number; | ||
>#foo : Symbol(#foo, Decl(privateNamesUnique-6.ts, 5, 28)) | ||
|
||
})(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//// [tests/cases/compiler/privateNamesUnique-6.ts] //// | ||
|
||
=== privateNamesUnique-6.ts === | ||
class A { | ||
>A : A | ||
|
||
#foo: number; | ||
>#foo : number | ||
} | ||
|
||
// error | ||
const test: A = new (class { | ||
>test : A | ||
>new (class { #foo: number;})() : (Anonymous class) | ||
>(class { #foo: number;}) : typeof (Anonymous class) | ||
>class { #foo: number;} : typeof (Anonymous class) | ||
|
||
#foo: number; | ||
>#foo : number | ||
|
||
})(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
privateNameMethodClassExpression.ts(9,17): error TS18013: Property '#method' is not accessible outside class '(Missing)' because it has a private identifier. | ||
privateNameMethodClassExpression.ts(10,17): error TS18013: Property '#field' is not accessible outside class '(Missing)' because it has a private identifier. | ||
privateNameMethodClassExpression.ts(9,17): error TS18013: Property '#method' is not accessible outside class 'C' because it has a private identifier. | ||
privateNameMethodClassExpression.ts(10,17): error TS18013: Property '#field' is not accessible outside class 'C' because it has a private identifier. | ||
|
||
|
||
==== privateNameMethodClassExpression.ts (2 errors) ==== | ||
|
@@ -13,9 +13,9 @@ privateNameMethodClassExpression.ts(10,17): error TS18013: Property '#field' is | |
console.log(C.getInstance().getField()); | ||
C.getInstance().#method; // Error | ||
~~~~~~~ | ||
!!! error TS18013: Property '#method' is not accessible outside class '(Missing)' because it has a private identifier. | ||
!!! error TS18013: Property '#method' is not accessible outside class 'C' because it has a private identifier. | ||
C.getInstance().#field; // Error | ||
~~~~~~ | ||
!!! error TS18013: Property '#field' is not accessible outside class '(Missing)' because it has a private identifier. | ||
!!! error TS18013: Property '#field' is not accessible outside class 'C' because it has a private identifier. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strada would print |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
# Diff files to instead write to submoduleAccepted as "accepted" changes. | ||
conformance/privateNameMethodClassExpression.errors.txt.diff |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @strict: true | ||
// @target: es2015 | ||
// @noEmit: true | ||
|
||
new (class { | ||
#method() { | ||
return 42; | ||
} | ||
})().#method; // error | ||
|
||
new (class { | ||
#field = 42; | ||
})().#field; // error |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @strict: true | ||
// @strictPropertyInitialization: false | ||
// @target: es6 | ||
// @noEmit: true | ||
|
||
class A { | ||
#foo: number; | ||
} | ||
|
||
// error | ||
const test: A = new (class { | ||
#foo: number; | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the previous behavior here was already diverging slightly from Strada for those anonymous classes (IMHO, in a good way)