fix Passing an unpacked tuple of types as type arguments to the type parameters [T, *Ts] gets error #2363#2364
fix Passing an unpacked tuple of types as type arguments to the type parameters [T, *Ts] gets error #2363#2364asukaminato0721 wants to merge 2 commits intofacebook:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Fixes #2363 by allowing unpacked concrete tuple type arguments (via *tuple[...] or Unpack[tuple[...]]) to expand into multiple type arguments before class/type specialization, so they can correctly bind leading type parameters like [T, *Ts].
Changes:
- Expand unpacked tuple type arguments in
create_targsbefore matching them toTParams. - Add a regression test covering concrete tuple unpacking into
[T, *Ts].
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyrefly/lib/alt/class/targs.rs |
Expands unpacked tuple type arguments prior to specialization to allow them to fill multiple parameters. |
pyrefly/lib/test/type_var_tuple.rs |
Adds a regression test ensuring Cls[*tuple[...]] and Cls[Unpack[tuple[...]]] work with [T, *Ts]. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Type::Unpack(box Type::Tuple(Tuple::Concrete(elts))) => { | ||
| expanded.extend(elts); | ||
| } | ||
| Type::Unpack(box Type::Tuple(Tuple::Unpacked(box (prefix, middle, suffix)))) => { |
There was a problem hiding this comment.
i think we should have a test case for this
|
also, it might be good to fix the conformance bug while we're at it |
| fn expand_unpacked_targs(&self, targs: Vec<Type>) -> Vec<Type> { | ||
| let mut expanded = Vec::with_capacity(targs.len()); | ||
| for arg in targs { | ||
| match arg { |
There was a problem hiding this comment.
how should we handle Unpack[*tuple[T, ...]]?
This comment has been minimized.
This comment has been minimized.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
@yangdanny97 @asukaminato0721 Is this PR supposed to address this test? |
Summary
Fixes #2363
Expand unpacked tuple type arguments before specialization so
Cls[*tuple[...]]andCls[Unpack[tuple[...]]]can fill leading type parameters.Test Plan
Added a regression test covering concrete tuple unpacking into
[T, *Ts]