-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Distribute indexed accesses when simplifying them #26281
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1ff6007
unknownify accesses
weswigham 87613bc
Move to simplify to break less with fewer changes
weswigham c881d97
Accept baselines for now
weswigham 518046c
Always propegate any as an index type
weswigham 17d37ec
Fix flow control in the presence of simplifiable types
weswigham 89b9e6e
Add spy repro from #25181
weswigham 02bd1a1
Merge branch 'master' into unknownify-accesses
weswigham 5bf01b3
Retain errorType when it is used as a marker for the lack of a constr…
weswigham c68d37a
Small refinement
weswigham bbb1164
Merge branch 'master' into unknownify-accesses
weswigham 82b8a4f
Add new test
weswigham 98e9b3e
Move most potentially recursive types from isIdenticalTo into structu…
weswigham 22b9a16
Fix nits
weswigham 37e5f6d
Doesnt need to be undefineable at all
weswigham 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
36 changes: 36 additions & 0 deletions
36
tests/baselines/reference/varianceCallbacksAndIndexedAccesses.js
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,36 @@ | ||
//// [varianceCallbacksAndIndexedAccesses.ts] | ||
type Source = { | ||
<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; | ||
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; | ||
} | ||
|
||
interface Action1<T> { | ||
(arg: T): void; | ||
} | ||
interface MessageEventLike<T> { | ||
source: WindowLike<T>; | ||
origin: string; | ||
data: T; | ||
} | ||
interface PostMessageObject<T> { | ||
postMessage(message: T, host: string): void; | ||
} | ||
interface WindowLike<T> extends PostMessageObject<T> { | ||
addEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void; | ||
addEventListener(type: string, handler: Action1<any>): void; | ||
removeEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void; | ||
removeEventListener(type: string, handler: Action1<any>): void; | ||
} | ||
type Target = { | ||
(type: "message", handler: Action1<MessageEventLike<any>>): void; | ||
(type: string, handler: Action1<any>): void; | ||
}; | ||
|
||
function f1(s: Source, t: Target) { | ||
t = s; | ||
} | ||
|
||
//// [varianceCallbacksAndIndexedAccesses.js] | ||
function f1(s, t) { | ||
t = s; | ||
} |
121 changes: 121 additions & 0 deletions
121
tests/baselines/reference/varianceCallbacksAndIndexedAccesses.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,121 @@ | ||
=== tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts === | ||
type Source = { | ||
>Source : Symbol(Source, Decl(varianceCallbacksAndIndexedAccesses.ts, 0, 0)) | ||
|
||
<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; | ||
>K : Symbol(K, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 5)) | ||
>WindowEventMap : Symbol(WindowEventMap, Decl(lib.dom.d.ts, --, --)) | ||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 37)) | ||
>K : Symbol(K, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 5)) | ||
>listener : Symbol(listener, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 45)) | ||
>this : Symbol(this, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 57)) | ||
>Window : Symbol(Window, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) | ||
>ev : Symbol(ev, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 70)) | ||
>WindowEventMap : Symbol(WindowEventMap, Decl(lib.dom.d.ts, --, --)) | ||
>K : Symbol(K, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 5)) | ||
>options : Symbol(options, Decl(varianceCallbacksAndIndexedAccesses.ts, 1, 101)) | ||
>AddEventListenerOptions : Symbol(AddEventListenerOptions, Decl(lib.dom.d.ts, --, --)) | ||
|
||
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; | ||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 2, 3)) | ||
>listener : Symbol(listener, Decl(varianceCallbacksAndIndexedAccesses.ts, 2, 16)) | ||
>EventListenerOrEventListenerObject : Symbol(EventListenerOrEventListenerObject, Decl(lib.dom.d.ts, --, --)) | ||
>options : Symbol(options, Decl(varianceCallbacksAndIndexedAccesses.ts, 2, 62)) | ||
>AddEventListenerOptions : Symbol(AddEventListenerOptions, Decl(lib.dom.d.ts, --, --)) | ||
} | ||
|
||
interface Action1<T> { | ||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) | ||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 5, 18)) | ||
|
||
(arg: T): void; | ||
>arg : Symbol(arg, Decl(varianceCallbacksAndIndexedAccesses.ts, 6, 5)) | ||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 5, 18)) | ||
} | ||
interface MessageEventLike<T> { | ||
>MessageEventLike : Symbol(MessageEventLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 7, 1)) | ||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 8, 27)) | ||
|
||
source: WindowLike<T>; | ||
>source : Symbol(MessageEventLike.source, Decl(varianceCallbacksAndIndexedAccesses.ts, 8, 31)) | ||
>WindowLike : Symbol(WindowLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 15, 1)) | ||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 8, 27)) | ||
|
||
origin: string; | ||
>origin : Symbol(MessageEventLike.origin, Decl(varianceCallbacksAndIndexedAccesses.ts, 9, 26)) | ||
|
||
data: T; | ||
>data : Symbol(MessageEventLike.data, Decl(varianceCallbacksAndIndexedAccesses.ts, 10, 19)) | ||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 8, 27)) | ||
} | ||
interface PostMessageObject<T> { | ||
>PostMessageObject : Symbol(PostMessageObject, Decl(varianceCallbacksAndIndexedAccesses.ts, 12, 1)) | ||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 13, 28)) | ||
|
||
postMessage(message: T, host: string): void; | ||
>postMessage : Symbol(PostMessageObject.postMessage, Decl(varianceCallbacksAndIndexedAccesses.ts, 13, 32)) | ||
>message : Symbol(message, Decl(varianceCallbacksAndIndexedAccesses.ts, 14, 16)) | ||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 13, 28)) | ||
>host : Symbol(host, Decl(varianceCallbacksAndIndexedAccesses.ts, 14, 27)) | ||
} | ||
interface WindowLike<T> extends PostMessageObject<T> { | ||
>WindowLike : Symbol(WindowLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 15, 1)) | ||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 21)) | ||
>PostMessageObject : Symbol(PostMessageObject, Decl(varianceCallbacksAndIndexedAccesses.ts, 12, 1)) | ||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 21)) | ||
|
||
addEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void; | ||
>addEventListener : Symbol(WindowLike.addEventListener, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 54), Decl(varianceCallbacksAndIndexedAccesses.ts, 17, 83)) | ||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 17, 21)) | ||
>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 17, 37)) | ||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) | ||
>MessageEventLike : Symbol(MessageEventLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 7, 1)) | ||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 21)) | ||
|
||
addEventListener(type: string, handler: Action1<any>): void; | ||
>addEventListener : Symbol(WindowLike.addEventListener, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 54), Decl(varianceCallbacksAndIndexedAccesses.ts, 17, 83)) | ||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 18, 21)) | ||
>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 18, 34)) | ||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) | ||
|
||
removeEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void; | ||
>removeEventListener : Symbol(WindowLike.removeEventListener, Decl(varianceCallbacksAndIndexedAccesses.ts, 18, 64), Decl(varianceCallbacksAndIndexedAccesses.ts, 19, 86)) | ||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 19, 24)) | ||
>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 19, 40)) | ||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) | ||
>MessageEventLike : Symbol(MessageEventLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 7, 1)) | ||
>T : Symbol(T, Decl(varianceCallbacksAndIndexedAccesses.ts, 16, 21)) | ||
|
||
removeEventListener(type: string, handler: Action1<any>): void; | ||
>removeEventListener : Symbol(WindowLike.removeEventListener, Decl(varianceCallbacksAndIndexedAccesses.ts, 18, 64), Decl(varianceCallbacksAndIndexedAccesses.ts, 19, 86)) | ||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 20, 24)) | ||
>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 20, 37)) | ||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) | ||
} | ||
type Target = { | ||
>Target : Symbol(Target, Decl(varianceCallbacksAndIndexedAccesses.ts, 21, 1)) | ||
|
||
(type: "message", handler: Action1<MessageEventLike<any>>): void; | ||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 23, 5)) | ||
>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 23, 21)) | ||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) | ||
>MessageEventLike : Symbol(MessageEventLike, Decl(varianceCallbacksAndIndexedAccesses.ts, 7, 1)) | ||
|
||
(type: string, handler: Action1<any>): void; | ||
>type : Symbol(type, Decl(varianceCallbacksAndIndexedAccesses.ts, 24, 5)) | ||
>handler : Symbol(handler, Decl(varianceCallbacksAndIndexedAccesses.ts, 24, 18)) | ||
>Action1 : Symbol(Action1, Decl(varianceCallbacksAndIndexedAccesses.ts, 3, 1)) | ||
|
||
}; | ||
|
||
function f1(s: Source, t: Target) { | ||
>f1 : Symbol(f1, Decl(varianceCallbacksAndIndexedAccesses.ts, 25, 2)) | ||
>s : Symbol(s, Decl(varianceCallbacksAndIndexedAccesses.ts, 27, 12)) | ||
>Source : Symbol(Source, Decl(varianceCallbacksAndIndexedAccesses.ts, 0, 0)) | ||
>t : Symbol(t, Decl(varianceCallbacksAndIndexedAccesses.ts, 27, 22)) | ||
>Target : Symbol(Target, Decl(varianceCallbacksAndIndexedAccesses.ts, 21, 1)) | ||
|
||
t = s; | ||
>t : Symbol(t, Decl(varianceCallbacksAndIndexedAccesses.ts, 27, 22)) | ||
>s : Symbol(s, Decl(varianceCallbacksAndIndexedAccesses.ts, 27, 12)) | ||
} |
81 changes: 81 additions & 0 deletions
81
tests/baselines/reference/varianceCallbacksAndIndexedAccesses.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,81 @@ | ||
=== tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts === | ||
type Source = { | ||
>Source : Source | ||
|
||
<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; | ||
>type : K | ||
>listener : (this: Window, ev: WindowEventMap[K]) => any | ||
>this : Window | ||
>ev : WindowEventMap[K] | ||
>options : boolean | AddEventListenerOptions | ||
|
||
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; | ||
>type : string | ||
>listener : EventListenerOrEventListenerObject | ||
>options : boolean | AddEventListenerOptions | ||
} | ||
|
||
interface Action1<T> { | ||
(arg: T): void; | ||
>arg : T | ||
} | ||
interface MessageEventLike<T> { | ||
source: WindowLike<T>; | ||
>source : WindowLike<T> | ||
|
||
origin: string; | ||
>origin : string | ||
|
||
data: T; | ||
>data : T | ||
} | ||
interface PostMessageObject<T> { | ||
postMessage(message: T, host: string): void; | ||
>postMessage : (message: T, host: string) => void | ||
>message : T | ||
>host : string | ||
} | ||
interface WindowLike<T> extends PostMessageObject<T> { | ||
addEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void; | ||
>addEventListener : { (type: "message", handler: Action1<MessageEventLike<T>>): void; (type: string, handler: Action1<any>): void; } | ||
>type : "message" | ||
>handler : Action1<MessageEventLike<T>> | ||
|
||
addEventListener(type: string, handler: Action1<any>): void; | ||
>addEventListener : { (type: "message", handler: Action1<MessageEventLike<T>>): void; (type: string, handler: Action1<any>): void; } | ||
>type : string | ||
>handler : Action1<any> | ||
|
||
removeEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void; | ||
>removeEventListener : { (type: "message", handler: Action1<MessageEventLike<T>>): void; (type: string, handler: Action1<any>): void; } | ||
>type : "message" | ||
>handler : Action1<MessageEventLike<T>> | ||
|
||
removeEventListener(type: string, handler: Action1<any>): void; | ||
>removeEventListener : { (type: "message", handler: Action1<MessageEventLike<T>>): void; (type: string, handler: Action1<any>): void; } | ||
>type : string | ||
>handler : Action1<any> | ||
} | ||
type Target = { | ||
>Target : Target | ||
|
||
(type: "message", handler: Action1<MessageEventLike<any>>): void; | ||
>type : "message" | ||
>handler : Action1<MessageEventLike<any>> | ||
|
||
(type: string, handler: Action1<any>): void; | ||
>type : string | ||
>handler : Action1<any> | ||
|
||
}; | ||
|
||
function f1(s: Source, t: Target) { | ||
>f1 : (s: Source, t: Target) => void | ||
>s : Source | ||
>t : Target | ||
|
||
t = s; | ||
>t = s : Source | ||
>t : Target | ||
>s : Source | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/cases/compiler/varianceCallbacksAndIndexedAccesses.ts
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,32 @@ | ||
|
||
|
||
type Source = { | ||
<K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; | ||
(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; | ||
} | ||
|
||
interface Action1<T> { | ||
(arg: T): void; | ||
} | ||
interface MessageEventLike<T> { | ||
source: WindowLike<T>; | ||
origin: string; | ||
data: T; | ||
} | ||
interface PostMessageObject<T> { | ||
postMessage(message: T, host: string): void; | ||
} | ||
interface WindowLike<T> extends PostMessageObject<T> { | ||
addEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void; | ||
addEventListener(type: string, handler: Action1<any>): void; | ||
removeEventListener(type: "message", handler: Action1<MessageEventLike<T>>): void; | ||
removeEventListener(type: string, handler: Action1<any>): void; | ||
} | ||
type Target = { | ||
(type: "message", handler: Action1<MessageEventLike<any>>): void; | ||
(type: string, handler: Action1<any>): void; | ||
}; | ||
|
||
function f1(s: Source, t: Target) { | ||
t = s; | ||
} |
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 pretty sure this assignment is actually unsafe. Like, callback variance checks should prevent this from succeeding because
Target
's callbacks don't handle a wide enough range of things, but because we overwriteK
withany
for an erased comparison andWindowEventMap[any]
isany
it succeeds.