-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Changes from 7 commits
982f99a
72b5004
6e7aa4d
0ccedd6
a02be27
fc368df
bbda1ed
f82fbb4
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 |
|---|---|---|
|
|
@@ -5278,7 +5278,7 @@ export function isPushOrUnshiftIdentifier(node: Identifier) { | |
| * | ||
| * @internal | ||
| */ | ||
| export function isParameterDeclaration(node: Declaration): boolean { | ||
| export function isParameterDeclaration(node: Declaration): node is ParameterDeclaration { | ||
|
||
| const root = getRootDeclaration(node); | ||
| return root.kind === SyntaxKind.Parameter; | ||
| } | ||
|
|
||
| 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)) | ||
| } | ||
| } | ||
| } | ||
|
|
| 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 | ||
| } | ||
| } | ||
| } | ||
|
|
| 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; | ||
| } | ||
| } | ||
| } |
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
isSymbolAssignedbehavior, to aggregateisAssignedat 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, sincegetNarrowedTypeOfSymbolneeds the aggregate info butcheckIdentifierneeds 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 😅