Fixed a bug in type narrowing for pattern matching in the negative (fall-through) case when the subject type contains an Any. This addresses #5492. (#5499)

Co-authored-by: Eric Traut <erictr@microsoft.com>
This commit is contained in:
Eric Traut 2023-07-14 04:53:53 +00:00 committed by GitHub
parent bb60966327
commit 6236155cb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -61,6 +61,7 @@ import {
import {
addConditionToType,
applySolvedTypeVars,
containsAnyOrUnknown,
convertToInstance,
doForEachSubtype,
getTypeCondition,
@ -207,7 +208,7 @@ function narrowTypeBasedOnSequencePattern(
}
let isPlausibleMatch = true;
let isDefiniteMatch = true;
let isDefiniteMatch = !containsAnyOrUnknown(type, /* recurse */ false);
const narrowedEntryTypes: Type[] = [];
let canNarrowTuple = entry.isTuple;

View File

@ -32,6 +32,14 @@ def test_unknown(value_to_match):
reveal_type(g1, expected_text="list[Unknown]")
def test_any(value_to_match: Any):
match value_to_match:
case [*a1]:
reveal_type(a1, expected_text="list[Any]")
case b1:
reveal_type(b1, expected_text="Any")
def test_list(value_to_match: List[str]):
match value_to_match:
case a1, a2: