Fixed bug that results in false positive error under certain circumstances when solving type variables that involve literal values. This addresses #8133 and #8048. (#8603)

This commit is contained in:
Eric Traut 2024-07-30 10:48:06 -07:00 committed by GitHub
parent 74345cc15f
commit 6913347aa8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 6 deletions

View File

@ -24859,11 +24859,21 @@ export function createTypeEvaluator(
let doSpecializationStep = false;
if ((flags & AssignTypeFlags.OverloadOverlap) === 0) {
const isFirstPass = (flags & AssignTypeFlags.ArgAssignmentFirstPass) !== 0;
if ((flags & AssignTypeFlags.ReverseTypeVarMatching) === 0) {
specializedDestType = applySolvedTypeVars(destType, destTypeVarContext, { useLowerBoundOnly: true });
if (!isFirstPass) {
specializedDestType = applySolvedTypeVars(destType, destTypeVarContext, {
useLowerBoundOnly: true,
});
}
doSpecializationStep = requiresSpecialization(specializedDestType);
} else {
specializedSrcType = applySolvedTypeVars(srcType, srcTypeVarContext, { useLowerBoundOnly: true });
if (!isFirstPass) {
specializedSrcType = applySolvedTypeVars(srcType, srcTypeVarContext, {
useLowerBoundOnly: true,
});
}
doSpecializationStep = requiresSpecialization(specializedSrcType);
}
}

View File

@ -3,7 +3,6 @@
from typing import Callable, Generic, Literal, TypeVar
FileChanges = dict[str, Literal["created", "edited", "removed"]]
changes: FileChanges = {}
@ -66,6 +65,4 @@ def func8(a: _T, b: Callable[[list[_T]], None]) -> _T:
def func9(v: Callable[[list[int]], None]):
func8(b=v, a=1)
# This should also type check without error, but it doesn't currently.
# See issue #8048.
# func8(a=1, b=v)
func8(a=1, b=v)