Fixed a bug that results in incorrect type evaluation when a sequence pattern in a match statement includes a * element and the subject includes a tuple with an element with indeterminate length. This addresses #7613. (#7616)

This commit is contained in:
Eric Traut 2024-04-04 10:06:35 -07:00 committed by GitHub
parent 26db037205
commit 476447cb65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -1290,7 +1290,7 @@ function getSequencePatternInfo(
typeArgs.splice(tupleIndeterminateIndex, 0, typeArgs[tupleIndeterminateIndex]);
}
if (typeArgs.length > patternEntryCount) {
if (typeArgs.length > patternEntryCount && patternStarEntryIndex === undefined) {
typeArgs.splice(tupleIndeterminateIndex, 1);
}
}

View File

@ -479,3 +479,12 @@ def test_unbounded_tuple(
reveal_type(x, expected_text="int")
reveal_type(y, expected_text="str")
reveal_type(z, expected_text="complex")
def test_unbounded_tuple_2(subj: tuple[int, str, Unpack[tuple[range, ...]]]) -> None:
match subj:
case [1, *ts1]:
reveal_type(ts1, expected_text="list[str | range]")
case [1, "", *ts2]:
reveal_type(ts2, expected_text="list[range]")