Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/pyright-internal/src/analyzer/patternMatching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,15 @@ function narrowTypeBasedOnValuePattern(
(subjectSubtypeExpanded) => {
// If this is a negative test, see if it's an enum value.
if (!isPositiveTest) {
if (
isInstantiableClass(subjectSubtypeExpanded) &&
isInstantiableClass(valueSubtypeExpanded) &&
isSameWithoutLiteralValue(subjectSubtypeExpanded, valueSubtypeExpanded)
) {
if (ClassType.isFinal(subjectSubtypeExpanded) || !subjectSubtypeExpanded.priv.includeSubclasses) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue · Please address or respond

This condition exceeds the repository's enforced 120-character Prettier formatting limit. Please wrap the clauses before merging.

return undefined;
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning · Non-blocking recommendation

Add regression coverage showing that a final class-object match is exhaustive and an equivalent non-final class remains non-exhaustive. This analyzer behavior change currently has no test specification.

if (
isClassInstance(subjectSubtypeExpanded) &&
isClassInstance(valueSubtypeExpanded) &&
Expand Down