You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Broken double inference step in variadic tuple types when rest elements come into playΒ #52017
While #51157 improves the situation a little bit for the extends [any?] part, it doesn't handle 2 (or more) variadic elements in the target type here. There is no code to support such a case there - which kinda makes sense since this didn't make a lot of sense prior toinfer extends syntax and that is a fairly new addition.
Fixing this would require rewriting the whole part of inferFromObjectTypes that relates to tuples. Right now the logic there tries to "pattern match" some specific situations but with infer extends we could support a dynamic number of variadic elements (if they are constrained with extends).
For similar reasons your original repro here doesn't work - such a mix of a variadic and rest elements is just not handled at all by the current logic.
I'll keep thinking about how to rewrite this whole bit to handle both cases - if you'd like to brainstorm how the improved algorithm could work, my DMs are open π
Activity
jfet97 commentedon Dec 25, 2022
Pinging Mateusz BurzyΕski (@Andarist) as requested from him.
Andarist commentedon Dec 26, 2022
Potentially a simpler version (with a single step) of this conditional type could work here as well but it doesn't work either:
While #51157 improves the situation a little bit for the
extends [any?]part, it doesn't handle 2 (or more) variadic elements in the target type here. There is no code to support such a case there - which kinda makes sense since this didn't make a lot of sense prior toinfer extendssyntax and that is a fairly new addition.Fixing this would require rewriting the whole part of
inferFromObjectTypesthat relates to tuples. Right now the logic there tries to "pattern match" some specific situations but withinfer extendswe could support a dynamic number of variadic elements (if they are constrained withextends).For similar reasons your original repro here doesn't work - such a mix of a variadic and rest elements is just not handled at all by the current logic.
I'll keep thinking about how to rewrite this whole bit to handle both cases - if you'd like to brainstorm how the improved algorithm could work, my DMs are open π
fatcerberus commentedon Dec 26, 2022
Isn't
[ ...infer HEAD, ...infer TAIL ]ambiguous since the input tuple could be any length and the choice of where to split is arbitrary?Andarist commentedon Dec 26, 2022
in Andrea Simone Costa (@jfet97)βs example
TAILis being simply spread, in my exampleHEADhas a fixed-size constraint so it isnβt ambiguous