Skip to content

someTypeRelatedToType now passes isIntersectionConstituent - #33213

Merged
Nathan Shively-Sanders (sandersn) merged 3 commits into
masterfrom
fix-missed-intersection-constituent-threading
Sep 4, 2019
Merged

someTypeRelatedToType now passes isIntersectionConstituent#33213
Nathan Shively-Sanders (sandersn) merged 3 commits into
masterfrom
fix-missed-intersection-constituent-threading

Conversation

@sandersn

@sandersnNathan Shively-Sanders (sandersn) commented Sep 3, 2019

Copy link
Copy Markdown
Member

The quick check for intersection sources doesn't pass isIntersectionConstituent, which incorrectly causes excess property checking to happen on intersection constituents.

In this example, the quick check happens when checking g(CC), and incorrectly finds that CP is not assignable to { children?: boolean } even though the latter is part of CP & { children?: boolean }. The result is then cached, which breaks the assignability check on the next line: <CC {...(null as CP) }/>.

This is a 3.6 regression, but the example is so complex that I'm not sure how hard it is to reproduce.

interfaceF<P>{(props: P&{children?: boolean}): void;propTypes: {[KinkeyofP]: nullextendsP ? K : K};}declarefunctiong(C: F<unknown>): string;exportfunctionwu<CPextends{o: object}>(CC: F<CP>){classWU{m(){g(CC)return<CC{...(nullasunknownasCP)}/>;}}}

Fixes#33133

Edit: Added commentary from the issue:

The basic problem is that the flag isIntersectionConstituent, which is used to exempt intersection constituents from common-property checks ("weak types"), isn't threaded through one particular intersection call in assignability checking. I missed it when threading that flag through more calls in 3.6 (#32582), and my new assertion in overload error reporting caught the mistake. It's quite likely that this assert would have fired a lot more before #32582.

Comment threadsrc/compiler/checker.ts Outdated
}
else {
const allDiagnostics: DiagnosticRelatedInformation[][] = [];
const allDiagnostics: Array<ReadonlyArray<DiagnosticRelatedInformation>> = [];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constallDiagnostics: Array<ReadonlyArray<DiagnosticRelatedInformation>>=[];
constallDiagnostics: (readonlyDiagnosticRelatedInformation[])[]=[];

to fix that lint failure.

@sandersnNathan Shively-Sanders (sandersn)Sep 4, 2019

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our parsing for readonly T[][] is so bad, and yet we have a lint rule requiring it.

@sandersn

Copy link
Copy Markdown
MemberAuthor

TypeScript Bot (@typescript-bot) cherry-pick this to release-3.6

TypeScript Bot (typescript-bot) pushed a commit to typescript-bot/TypeScript that referenced this pull request Sep 4, 2019
Component commits:
cc1dc3b someTypeRelatedToType now passes isIntersectionConstituent
cf3eadc Merge branch 'master' into fix-missed-intersection-constituent-threading
f10fe38 Fix [][] lint
@typescript-bot

Copy link
Copy Markdown
Contributor

Hey Nathan Shively-Sanders (@sandersn), I've opened #33245 for you.

@sandersn
Nathan Shively-Sanders (sandersn) deleted the fix-missed-intersection-constituent-threading branch September 4, 2019 20:42
Nathan Shively-Sanders (sandersn) pushed a commit that referenced this pull request Sep 4, 2019
Component commits:
cc1dc3b someTypeRelatedToType now passes isIntersectionConstituent
cf3eadc Merge branch 'master' into fix-missed-intersection-constituent-threading
f10fe38 Fix [][] lint
Wesley Wigham (weswigham) added a commit to weswigham/TypeScript that referenced this pull request Sep 5, 2019
Tim Suchanek (timsuchanek) pushed a commit to timsuchanek/TypeScript that referenced this pull request Sep 11, 2019
…#33213)
* someTypeRelatedToType now passes isIntersectionConstituent
* Fix [][] lint
Nathan Shively-Sanders (sandersn) added a commit that referenced this pull request Oct 28, 2019
isIntersectionConstituent controls whether relation checking performs
excess property and common property checks. It is possible to fail a
relation check with excess property checks turned on, cache the result,
and then skip a relation check with excess property checks that would
have succeeded. #33133 provides an example of such a program.
Fixes#33133 the right way, so I reverted the fix at #33213Fixes#34762 (by reverting #33213)
Fixes#33944 -- I added the test from #34646
Nathan Shively-Sanders (sandersn) added a commit that referenced this pull request Oct 29, 2019
* Add isIntersectionConstituent to relation key
isIntersectionConstituent controls whether relation checking performs
excess property and common property checks. It is possible to fail a
relation check with excess property checks turned on, cache the result,
and then skip a relation check with excess property checks that would
have succeeded. #33133 provides an example of such a program.
Fixes#33133 the right way, so I reverted the fix at #33213Fixes#34762 (by reverting #33213)
Fixes#33944 -- I added the test from #34646
* Update comments in test
TypeScript Bot (typescript-bot) pushed a commit to typescript-bot/TypeScript that referenced this pull request Oct 29, 2019
Component commits:
2e0b451 Add isIntersectionConstituent to relation key
isIntersectionConstituent controls whether relation checking performs
excess property and common property checks. It is possible to fail a
relation check with excess property checks turned on, cache the result,
and then skip a relation check with excess property checks that would
have succeeded. microsoft#33133 provides an example of such a program.
Fixesmicrosoft#33133 the right way, so I reverted the fix at microsoft#33213Fixesmicrosoft#34762 (by reverting microsoft#33213)
Fixesmicrosoft#33944 -- I added the test from microsoft#3464614d7a44 Merge branch 'master' into add-isIntersectionConstituent-to-relation-key
ea80362 Update comments in test
0764275 Merge branch 'master' into add-isIntersectionConstituent-to-relation-key
Nathan Shively-Sanders (sandersn) pushed a commit that referenced this pull request Oct 29, 2019
Component commits:
2e0b451 Add isIntersectionConstituent to relation key
isIntersectionConstituent controls whether relation checking performs
excess property and common property checks. It is possible to fail a
relation check with excess property checks turned on, cache the result,
and then skip a relation check with excess property checks that would
have succeeded. #33133 provides an example of such a program.
Fixes#33133 the right way, so I reverted the fix at #33213Fixes#34762 (by reverting #33213)
Fixes#33944 -- I added the test from #3464614d7a44 Merge branch 'master' into add-isIntersectionConstituent-to-relation-key
ea80362 Update comments in test
0764275 Merge branch 'master' into add-isIntersectionConstituent-to-relation-key
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3.6 regression: Error: Debug Failure. No error for last overload signature

3 participants

@sandersn@typescript-bot@weswigham