-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Avoid dependent parameters narrowings if any declared symbol of the parameter is assigned to #56313
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
Merged
gabritto
merged 8 commits into
microsoft:main
from
Andarist:fix/depenent-parameters-invalidation
Dec 11, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
982f99a
Avoid dependent parameters narrowings if any declared symbols of the …
Andarist 72b5004
Remove `isSymbolAssigned`
Andarist 6e7aa4d
Merge remote-tracking branch 'origin/main' into fix/depenent-paramete…
Andarist 0ccedd6
Merge remote-tracking branch 'origin/main' into fix/depenent-paramete…
Andarist a02be27
add a comment back
Andarist fc368df
Fixed the dependent parameters narrowing invalidation with contextual…
Andarist bbda1ed
Keep narrowing non-reassigned names coming from parameters
Andarist f82fbb4
Revert `isParameterDeclaration` change
Andarist 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
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
24 changes: 24 additions & 0 deletions
24
...baselines/reference/narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.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,24 @@ | ||
//// [tests/cases/compiler/narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts] //// | ||
|
||
=== narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts === | ||
function ff({ a, b }: { a: string | undefined, b: () => void }) { | ||
>ff : Symbol(ff, Decl(narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts, 0, 0)) | ||
>a : Symbol(a, Decl(narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts, 0, 13)) | ||
>b : Symbol(b, Decl(narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts, 0, 16)) | ||
>a : Symbol(a, Decl(narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts, 0, 23)) | ||
>b : Symbol(b, Decl(narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts, 0, 46)) | ||
|
||
if (a !== undefined) { | ||
>a : Symbol(a, Decl(narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts, 0, 13)) | ||
>undefined : Symbol(undefined) | ||
|
||
b = () => { | ||
>b : Symbol(b, Decl(narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts, 0, 16)) | ||
|
||
const x: string = a; | ||
>x : Symbol(x, Decl(narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts, 3, 11)) | ||
>a : Symbol(a, Decl(narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts, 0, 13)) | ||
} | ||
} | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
...s/baselines/reference/narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.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,27 @@ | ||
//// [tests/cases/compiler/narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts] //// | ||
|
||
=== narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts === | ||
function ff({ a, b }: { a: string | undefined, b: () => void }) { | ||
>ff : ({ a, b }: { a: string | undefined; b: () => void;}) => void | ||
>a : string | undefined | ||
>b : () => void | ||
>a : string | undefined | ||
>b : () => void | ||
|
||
if (a !== undefined) { | ||
>a !== undefined : boolean | ||
>a : string | undefined | ||
>undefined : undefined | ||
|
||
b = () => { | ||
>b = () => { const x: string = a; } : () => void | ||
>b : () => void | ||
>() => { const x: string = a; } : () => void | ||
|
||
const x: string = a; | ||
>x : string | ||
>a : string | ||
} | ||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
tests/cases/compiler/narrowRefinedConstLikeParameterBIndingElementNameInInnerScope.ts
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,10 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
|
||
function ff({ a, b }: { a: string | undefined, b: () => void }) { | ||
if (a !== undefined) { | ||
b = () => { | ||
const x: string = a; | ||
} | ||
} | ||
} |
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.
It looks like the change to
isSymbolAssigned
behavior, to aggregateisAssigned
at the root declaration level, might not be the correct thing to do here, for this particular usage ofisSymbolAssigned
, as evidenced by this breaking change: #56313 (comment).Maybe we want to keep marking symbols with
isAssigned
, and also aggregate that info at the root declaration level, sincegetNarrowedTypeOfSymbol
needs the aggregate info butcheckIdentifier
needs the symbol info.Here's a more minimal repro of the break linked above:
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.
Heh, I really need to start reading through all of the existing comments at once instead of reading through them one by one. It would save me a few minutes here 😅