-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Implement(60881): Added detailed diagnostic for parent to child assignment #61145
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
NamHaiBui
wants to merge
32
commits into
microsoft:main
Choose a base branch
from
SeniorSeminarGroup:60881
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
Show all changes
32 commits
Select commit
Hold shift + click to select a range
a010044
.
NamHaiBui 3d632b3
new check
NamHaiBui ef0dd9d
new diagnostic message
NamHaiBui e16f35f
Merge branch 'main' of https://github.com/microsoft/TypeScript
NamHaiBui 63e6b4c
#60881
NamHaiBui 09022f3
#60881
NamHaiBui 8def683
#60881 Minor typo change
NamHaiBui ce15fd8
Normalize line endings
NamHaiBui 01e2bfc
Merge branch 'main' of https://github.com/microsoft/TypeScript into 6…
NamHaiBui 85dc004
#60881 reformat
NamHaiBui 47acf44
removed old comments
Alexandrialexie 65fdfc1
generic check before hand
NamHaiBui 4f8eeb6
Merge branch '60881' of https://github.com/SeniorSeminarGroup/TypeScr…
Alexandrialexie 4db251b
new approach and all changed tests reviewed
NamHaiBui 6505632
formatting
NamHaiBui c0b8e55
Merge branch 'main' of https://github.com/microsoft/TypeScript into 6…
NamHaiBui d62eed1
Merge branch '60881' of https://github.com/SeniorSeminarGroup/TypeScr…
Alexandrialexie 753d8c1
Merge branch 'main' of https://github.com/microsoft/TypeScript into 6…
NamHaiBui 694b893
Merge branch '60881' of https://github.com/SeniorSeminarGroup/TypeScr…
Alexandrialexie ef4e281
removed unnecessary comments
Alexandrialexie dd6ab9a
added more informative test language and extra test case.
RolandLocke 2a56797
added diagnostic message to the 'semantic messages' area in diagnosti…
RolandLocke a697946
accepted baseline changes
RolandLocke c662343
Merge branch 'main' of https://github.com/microsoft/TypeScript into 6…
NamHaiBui cad1a24
Merge branch 'main' of https://github.com/microsoft/TypeScript into 6…
NamHaiBui b3664f8
Revert "#60881 reformat"
NamHaiBui b285ebc
reverted formatting errors
RolandLocke 95b249f
added trailing comma
RolandLocke c88940c
Merge branch 'microsoft:main' into 60881
maitnngo2002 8933230
Revert "Merge branch 'microsoft:main' into 60881"
ngothingocmaiclht eab824d
Revert "Revert "Merge branch 'microsoft:main' into 60881""
ngothingocmaiclht c741d1e
Updated test function parameters
RolandLocke 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
25 changes: 25 additions & 0 deletions
25
tests/baselines/reference/better_subType_assignable_to_superType_error_messsage.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,25 @@ | ||
better_subType_assignable_to_superType_error_messsage.ts(3,3): error TS2322: Type 'SuperType' is not assignable to type 'SubType'. | ||
'SubType' is constrained to be a subtype of 'SuperType'. | ||
better_subType_assignable_to_superType_error_messsage.ts(6,3): error TS2322: Type 'SuperType' is not assignable to type 'SubType2'. | ||
'SubType2' is constrained to be a subtype of 'SuperType'. | ||
|
||
|
||
==== better_subType_assignable_to_superType_error_messsage.ts (2 errors) ==== | ||
function parameterExtendsOtherParameter<SuperType, SubType extends SuperType, SubType2 extends SubType>(superType: SuperType, subtype: SubType, subType2: SubType2) { | ||
//ensures that supertypes are not assignable to subtypes | ||
subtype = superType;//error | ||
~~~~~~~ | ||
!!! error TS2322: Type 'SuperType' is not assignable to type 'SubType'. | ||
!!! error TS2322: 'SubType' is constrained to be a subtype of 'SuperType'. | ||
!!! related TS2208 better_subType_assignable_to_superType_error_messsage.ts:1:41: This type parameter might need an `extends SubType` constraint. | ||
|
||
//ensures that supertypes are not assignable to 'grandchild' subtypes | ||
subType2 = superType;//error | ||
~~~~~~~~ | ||
!!! error TS2322: Type 'SuperType' is not assignable to type 'SubType2'. | ||
!!! error TS2322: 'SubType2' is constrained to be a subtype of 'SuperType'. | ||
!!! related TS2208 better_subType_assignable_to_superType_error_messsage.ts:1:41: This type parameter might need an `extends SubType2` constraint. | ||
|
||
superType = subType2;//ok | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/better_subType_assignable_to_superType_error_messsage.js
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,22 @@ | ||
//// [tests/cases/compiler/better_subType_assignable_to_superType_error_messsage.ts] //// | ||
|
||
//// [better_subType_assignable_to_superType_error_messsage.ts] | ||
function parameterExtendsOtherParameter<SuperType, SubType extends SuperType, SubType2 extends SubType>(superType: SuperType, subtype: SubType, subType2: SubType2) { | ||
//ensures that supertypes are not assignable to subtypes | ||
subtype = superType;//error | ||
|
||
//ensures that supertypes are not assignable to 'grandchild' subtypes | ||
subType2 = superType;//error | ||
|
||
superType = subType2;//ok | ||
} | ||
|
||
|
||
//// [better_subType_assignable_to_superType_error_messsage.js] | ||
function parameterExtendsOtherParameter(superType, subtype, subType2) { | ||
//ensures that supertypes are not assignable to subtypes | ||
subtype = superType; //error | ||
//ensures that supertypes are not assignable to 'grandchild' subtypes | ||
subType2 = superType; //error | ||
superType = subType2; //ok | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/baselines/reference/better_subType_assignable_to_superType_error_messsage.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,32 @@ | ||
//// [tests/cases/compiler/better_subType_assignable_to_superType_error_messsage.ts] //// | ||
|
||
=== better_subType_assignable_to_superType_error_messsage.ts === | ||
function parameterExtendsOtherParameter<SuperType, SubType extends SuperType, SubType2 extends SubType>(superType: SuperType, subtype: SubType, subType2: SubType2) { | ||
>parameterExtendsOtherParameter : Symbol(parameterExtendsOtherParameter, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 0)) | ||
>SuperType : Symbol(SuperType, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 40)) | ||
>SubType : Symbol(SubType, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 50)) | ||
>SuperType : Symbol(SuperType, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 40)) | ||
>SubType2 : Symbol(SubType2, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 77)) | ||
>SubType : Symbol(SubType, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 50)) | ||
>superType : Symbol(superType, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 104)) | ||
>SuperType : Symbol(SuperType, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 40)) | ||
>subtype : Symbol(subtype, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 125)) | ||
>SubType : Symbol(SubType, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 50)) | ||
>subType2 : Symbol(subType2, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 143)) | ||
>SubType2 : Symbol(SubType2, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 77)) | ||
|
||
//ensures that supertypes are not assignable to subtypes | ||
subtype = superType;//error | ||
>subtype : Symbol(subtype, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 125)) | ||
>superType : Symbol(superType, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 104)) | ||
|
||
//ensures that supertypes are not assignable to 'grandchild' subtypes | ||
subType2 = superType;//error | ||
>subType2 : Symbol(subType2, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 143)) | ||
>superType : Symbol(superType, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 104)) | ||
|
||
superType = subType2;//ok | ||
>superType : Symbol(superType, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 104)) | ||
>subType2 : Symbol(subType2, Decl(better_subType_assignable_to_superType_error_messsage.ts, 0, 143)) | ||
} | ||
|
40 changes: 40 additions & 0 deletions
40
tests/baselines/reference/better_subType_assignable_to_superType_error_messsage.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,40 @@ | ||
//// [tests/cases/compiler/better_subType_assignable_to_superType_error_messsage.ts] //// | ||
|
||
=== better_subType_assignable_to_superType_error_messsage.ts === | ||
function parameterExtendsOtherParameter<SuperType, SubType extends SuperType, SubType2 extends SubType>(superType: SuperType, subtype: SubType, subType2: SubType2) { | ||
>parameterExtendsOtherParameter : <SuperType, SubType extends SuperType, SubType2 extends SubType>(superType: SuperType, subtype: SubType, subType2: SubType2) => void | ||
> : ^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^ | ||
>superType : SuperType | ||
> : ^^^^^^^^^ | ||
>subtype : SubType | ||
> : ^^^^^^^ | ||
>subType2 : SubType2 | ||
> : ^^^^^^^^ | ||
|
||
//ensures that supertypes are not assignable to subtypes | ||
subtype = superType;//error | ||
>subtype = superType : SuperType | ||
> : ^^^^^^^^^ | ||
>subtype : SubType | ||
> : ^^^^^^^ | ||
>superType : SuperType | ||
> : ^^^^^^^^^ | ||
|
||
//ensures that supertypes are not assignable to 'grandchild' subtypes | ||
subType2 = superType;//error | ||
>subType2 = superType : SuperType | ||
> : ^^^^^^^^^ | ||
>subType2 : SubType2 | ||
> : ^^^^^^^^ | ||
>superType : SuperType | ||
> : ^^^^^^^^^ | ||
|
||
superType = subType2;//ok | ||
>superType = subType2 : SubType2 | ||
> : ^^^^^^^^ | ||
>superType : SuperType | ||
> : ^^^^^^^^^ | ||
>subType2 : SubType2 | ||
> : ^^^^^^^^ | ||
} | ||
|
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
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
Oops, something went wrong.
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'm not understanding why this error message is an improvement. What's the smallest example where this error is going to be easier to understand?
Uh oh!
There was an error while loading. Please reload this page.
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.
@RyanCavanaugh This error message is an improvement because the original error message says that the two types could be unrelated but we know they are related in a parent child relationship, you just can't assign a parent to a child. We tried to pick a new error message that was similar to the suggestion in the original issue. This is the simplest example we looked at: