-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Track recursive callback-covariance calls to compareSignaturesRelated #19078
Closed
sandersn
wants to merge
2
commits into
master
from
track-recursive-calls-to-compareSignaturesRelated
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
35 changes: 35 additions & 0 deletions
35
tests/baselines/reference/mutuallyRecursiveCallbacks.errors.txt
This file contains 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,35 @@ | ||
tests/cases/compiler/mutuallyRecursiveCallbacks.ts(6,1): error TS2322: Type '<T>(bar: Bar<T>) => void' is not assignable to type 'Bar<{}>'. | ||
Types of parameters 'bar' and 'foo' are incompatible. | ||
Types of parameters 'bar' and 'foo' are incompatible. | ||
Types of parameters 'bar' and 'foo' are incompatible. | ||
Type 'Foo<{}>' is not assignable to type 'Bar<{}>'. | ||
Types of parameters 'bar' and 'foo' are incompatible. | ||
Types of parameters 'bar' and 'foo' are incompatible. | ||
Types of parameters 'bar' and 'foo' are incompatible. | ||
Type 'Foo<{}>' is not assignable to type 'Bar<{}>'. | ||
Types of parameters 'bar' and 'foo' are incompatible. | ||
Types of parameters 'bar' and 'foo' are incompatible. | ||
Type 'void' is not assignable to type 'Foo<{}>'. | ||
|
||
|
||
==== tests/cases/compiler/mutuallyRecursiveCallbacks.ts (1 errors) ==== | ||
// #18277 | ||
interface Foo<T> { (bar: Bar<T>): void }; | ||
type Bar<T> = (foo: Foo<T>) => Foo<T>; | ||
declare function foo<T>(bar: Bar<T>): void; | ||
declare var bar: Bar<{}>; | ||
bar = foo; | ||
~~~ | ||
!!! error TS2322: Type '<T>(bar: Bar<T>) => void' is not assignable to type 'Bar<{}>'. | ||
!!! error TS2322: Types of parameters 'bar' and 'foo' are incompatible. | ||
!!! error TS2322: Types of parameters 'bar' and 'foo' are incompatible. | ||
!!! error TS2322: Types of parameters 'bar' and 'foo' are incompatible. | ||
!!! error TS2322: Type 'Foo<{}>' is not assignable to type 'Bar<{}>'. | ||
!!! error TS2322: Types of parameters 'bar' and 'foo' are incompatible. | ||
!!! error TS2322: Types of parameters 'bar' and 'foo' are incompatible. | ||
!!! error TS2322: Types of parameters 'bar' and 'foo' are incompatible. | ||
!!! error TS2322: Type 'Foo<{}>' is not assignable to type 'Bar<{}>'. | ||
!!! error TS2322: Types of parameters 'bar' and 'foo' are incompatible. | ||
!!! error TS2322: Types of parameters 'bar' and 'foo' are incompatible. | ||
!!! error TS2322: Type 'void' is not assignable to type 'Foo<{}>'. | ||
|
This file contains 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,12 @@ | ||
//// [mutuallyRecursiveCallbacks.ts] | ||
// #18277 | ||
interface Foo<T> { (bar: Bar<T>): void }; | ||
type Bar<T> = (foo: Foo<T>) => Foo<T>; | ||
declare function foo<T>(bar: Bar<T>): void; | ||
declare var bar: Bar<{}>; | ||
bar = foo; | ||
|
||
|
||
//// [mutuallyRecursiveCallbacks.js] | ||
; | ||
bar = foo; |
33 changes: 33 additions & 0 deletions
33
tests/baselines/reference/mutuallyRecursiveCallbacks.symbols
This file contains 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,33 @@ | ||
=== tests/cases/compiler/mutuallyRecursiveCallbacks.ts === | ||
// #18277 | ||
interface Foo<T> { (bar: Bar<T>): void }; | ||
>Foo : Symbol(Foo, Decl(mutuallyRecursiveCallbacks.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mutuallyRecursiveCallbacks.ts, 1, 14)) | ||
>bar : Symbol(bar, Decl(mutuallyRecursiveCallbacks.ts, 1, 20)) | ||
>Bar : Symbol(Bar, Decl(mutuallyRecursiveCallbacks.ts, 1, 41)) | ||
>T : Symbol(T, Decl(mutuallyRecursiveCallbacks.ts, 1, 14)) | ||
|
||
type Bar<T> = (foo: Foo<T>) => Foo<T>; | ||
>Bar : Symbol(Bar, Decl(mutuallyRecursiveCallbacks.ts, 1, 41)) | ||
>T : Symbol(T, Decl(mutuallyRecursiveCallbacks.ts, 2, 9)) | ||
>foo : Symbol(foo, Decl(mutuallyRecursiveCallbacks.ts, 2, 15)) | ||
>Foo : Symbol(Foo, Decl(mutuallyRecursiveCallbacks.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mutuallyRecursiveCallbacks.ts, 2, 9)) | ||
>Foo : Symbol(Foo, Decl(mutuallyRecursiveCallbacks.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mutuallyRecursiveCallbacks.ts, 2, 9)) | ||
|
||
declare function foo<T>(bar: Bar<T>): void; | ||
>foo : Symbol(foo, Decl(mutuallyRecursiveCallbacks.ts, 2, 38)) | ||
>T : Symbol(T, Decl(mutuallyRecursiveCallbacks.ts, 3, 21)) | ||
>bar : Symbol(bar, Decl(mutuallyRecursiveCallbacks.ts, 3, 24)) | ||
>Bar : Symbol(Bar, Decl(mutuallyRecursiveCallbacks.ts, 1, 41)) | ||
>T : Symbol(T, Decl(mutuallyRecursiveCallbacks.ts, 3, 21)) | ||
|
||
declare var bar: Bar<{}>; | ||
>bar : Symbol(bar, Decl(mutuallyRecursiveCallbacks.ts, 4, 11)) | ||
>Bar : Symbol(Bar, Decl(mutuallyRecursiveCallbacks.ts, 1, 41)) | ||
|
||
bar = foo; | ||
>bar : Symbol(bar, Decl(mutuallyRecursiveCallbacks.ts, 4, 11)) | ||
>foo : Symbol(foo, Decl(mutuallyRecursiveCallbacks.ts, 2, 38)) | ||
|
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/mutuallyRecursiveCallbacks.types
This file contains 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,34 @@ | ||
=== tests/cases/compiler/mutuallyRecursiveCallbacks.ts === | ||
// #18277 | ||
interface Foo<T> { (bar: Bar<T>): void }; | ||
>Foo : Foo<T> | ||
>T : T | ||
>bar : Bar<T> | ||
>Bar : Bar<T> | ||
>T : T | ||
|
||
type Bar<T> = (foo: Foo<T>) => Foo<T>; | ||
>Bar : Bar<T> | ||
>T : T | ||
>foo : Foo<T> | ||
>Foo : Foo<T> | ||
>T : T | ||
>Foo : Foo<T> | ||
>T : T | ||
|
||
declare function foo<T>(bar: Bar<T>): void; | ||
>foo : <T>(bar: Bar<T>) => void | ||
>T : T | ||
>bar : Bar<T> | ||
>Bar : Bar<T> | ||
>T : T | ||
|
||
declare var bar: Bar<{}>; | ||
>bar : Bar<{}> | ||
>Bar : Bar<T> | ||
|
||
bar = foo; | ||
>bar = foo : <T>(bar: Bar<T>) => void | ||
>bar : Bar<{}> | ||
>foo : <T>(bar: Bar<T>) => void | ||
|
This file contains 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,6 @@ | ||
// #18277 | ||
interface Foo<T> { (bar: Bar<T>): void }; | ||
type Bar<T> = (foo: Foo<T>) => Foo<T>; | ||
declare function foo<T>(bar: Bar<T>): void; | ||
declare var bar: Bar<{}>; | ||
bar = foo; |
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.
Couldn't you just pass a type comparer function that checks the map? That way you could keep all of the logic right here and not have to add another parameter to compareSignaturesRelated.
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 tried this but because
compareTypes
isn't actually called in the tight recursive loop ofcompareSignaturesRelated
, I have to put the whole decision inside the type comparer:Now the inner loop of parameter checking is clean:
But I think this part of the algorithm reads better in situ, and the move actually requires more code churn at the call sites of
compareSignaturesRelatedTo
becausecreateRecursiveSignatureTypeComparer
has so many parameters.To help the code churn at call sites, I could instead just make a compareSignaturesRelated/compareSignaturesRelatedWorker pair in order to hide the creation of the map.
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.
Turns out there's an even simpler fix. I have put it up in #19107.