mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 16:06:39 +03:00
Fixed bug in canAssignType. We need to do matching of TypeVars before checking or other types.
This commit is contained in:
parent
32312ba36c
commit
70636da86c
@ -78,22 +78,6 @@ export class TypeUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (recursionCount > MaxCanAssignTypeRecursion) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (srcType instanceof UnionType) {
|
||||
// For union sources, all of the types need to be assignable to the dest.
|
||||
return srcType.getTypes().find(
|
||||
t => !this.canAssignType(destType, t, typeVarMap, recursionCount + 1)) === undefined;
|
||||
}
|
||||
|
||||
if (destType instanceof UnionType) {
|
||||
// For union destinations, we just need to match one of the types.
|
||||
return destType.getTypes().find(
|
||||
t => this.canAssignType(t, srcType, typeVarMap, recursionCount + 1)) !== undefined;
|
||||
}
|
||||
|
||||
if (srcType instanceof TypeVarType) {
|
||||
// This should happen only if we have a bug and forgot to specialize
|
||||
// the source type or the code being analyzed contains a bug where
|
||||
@ -117,6 +101,22 @@ export class TypeUtils {
|
||||
return this._canAssignToTypeVar(destType, srcType);
|
||||
}
|
||||
|
||||
if (recursionCount > MaxCanAssignTypeRecursion) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (srcType instanceof UnionType) {
|
||||
// For union sources, all of the types need to be assignable to the dest.
|
||||
return srcType.getTypes().find(
|
||||
t => !this.canAssignType(destType, t, typeVarMap, recursionCount + 1)) === undefined;
|
||||
}
|
||||
|
||||
if (destType instanceof UnionType) {
|
||||
// For union destinations, we just need to match one of the types.
|
||||
return destType.getTypes().find(
|
||||
t => this.canAssignType(t, srcType, typeVarMap, recursionCount + 1)) !== undefined;
|
||||
}
|
||||
|
||||
if (destType.category === TypeCategory.Unbound ||
|
||||
srcType.category === TypeCategory.Unbound) {
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user