Skip to content

Commit 3ab305c

Browse files
committed
Moved TypeVar check to top of canAssignType.
1 parent 30b467e commit 3ab305c

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

server/src/analyzer/typeUtils.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,8 @@ export class TypeUtils {
7474
static canAssignType(destType: Type, srcType: Type, typeVarMap?: TypeVarMap,
7575
recursionCount = 0): boolean {
7676

77-
if (destType.isAny() || srcType.isAny()) {
78-
return true;
79-
}
80-
81-
if (srcType instanceof TypeVarType) {
82-
// This should happen only if we have a bug and forgot to specialize
83-
// the source type or the code being analyzed contains a bug where
84-
// a return type uses a type var that is not referenced elswhere
85-
// in a function.
86-
return false;
87-
}
88-
77+
// Before performing any other checks, see if the dest type is a
78+
// TypeVar that we are attempting to match.
8979
if (destType instanceof TypeVarType) {
9080
// If the dest type includes type variables, it is not yet
9181
// specialized, so the caller should have provided a typeVarMap.
@@ -101,6 +91,18 @@ export class TypeUtils {
10191
return this._canAssignToTypeVar(destType, srcType);
10292
}
10393

94+
if (srcType instanceof TypeVarType) {
95+
// This should happen only if we have a bug and forgot to specialize
96+
// the source type or the code being analyzed contains a bug where
97+
// a return type uses a type var that is not referenced elswhere
98+
// in a function.
99+
return false;
100+
}
101+
102+
if (destType.isAny() || srcType.isAny()) {
103+
return true;
104+
}
105+
104106
if (recursionCount > MaxCanAssignTypeRecursion) {
105107
return true;
106108
}

0 commit comments

Comments
 (0)