-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Unify the way anonymous class symbols are printed in error messages #61943
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
Open
Andarist
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
Andarist:unify-anonymous-class-printing-in-err-messages
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/privateNameMethodClassExpression2.errors.txt
This file contains hidden or 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,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. | ||
|
17 changes: 17 additions & 0 deletions
17
tests/baselines/reference/privateNameMethodClassExpression2.symbols
This file contains hidden or 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 @@ | ||
//// [tests/cases/compiler/privateNameMethodClassExpression2.ts] //// | ||
|
||
=== privateNameMethodClassExpression2.ts === | ||
new (class { | ||
#method() { | ||
>#method : Symbol((Anonymous class).#method, Decl(privateNameMethodClassExpression2.ts, 0, 12)) | ||
|
||
return 42; | ||
} | ||
})().#method; // error | ||
|
||
new (class { | ||
#field = 42; | ||
>#field : Symbol((Anonymous class).#field, Decl(privateNameMethodClassExpression2.ts, 6, 12)) | ||
|
||
})().#field; // error | ||
|
41 changes: 41 additions & 0 deletions
41
tests/baselines/reference/privateNameMethodClassExpression2.types
This file contains hidden or 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,41 @@ | ||
//// [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 | ||
|
This file contains hidden or 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 @@ | ||
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'. | ||
#foo: number; | ||
})(); | ||
|
This file contains hidden or 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,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(A.#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((Anonymous class).#foo, Decl(privateNamesUnique-6.ts, 5, 28)) | ||
|
||
})(); | ||
|
This file contains hidden or 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,29 @@ | ||
//// [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 | ||
> : ^^^^^^ | ||
|
||
})(); | ||
|
This file contains hidden or 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,13 @@ | ||
// @strict: true | ||
// @target: es2015 | ||
// @noEmit: true | ||
|
||
new (class { | ||
#method() { | ||
return 42; | ||
} | ||
})().#method; // error | ||
|
||
new (class { | ||
#field = 42; | ||
})().#field; // error |
This file contains hidden or 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,13 @@ | ||
// @strict: true | ||
// @strictPropertyInitialization: false | ||
// @target: es6 | ||
// @noEmit: true | ||
|
||
class A { | ||
#foo: number; | ||
} | ||
|
||
// error | ||
const test: A = new (class { | ||
#foo: number; | ||
})(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think
anon
can now be completely removed. OnlycheckNoTypeArguments
relies on it - but I can't see how it would actually end up in that branch (and there are no tests proving otherwise). I have refrained myself from doing changes there though.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.
Perhaps this proposed patch makes it a little bit more clear why I think this
anon
branch there is essentially never hit:This function is always called with a
symbol
when the argument isNodeWithTypeArguments
and it's never called with asymbol
when the argument isTypeReferenceNode
. AndTypeReferenceNode
always has atypeName
property.