A few simplifications...

This commit is contained in:
Eric Traut 2019-11-10 20:55:17 -08:00
parent 20163520c3
commit 80e600738c
2 changed files with 3 additions and 24 deletions

View File

@ -289,7 +289,6 @@ export class Binder extends ParseTreeWalker {
} }
visitFunction(node: FunctionNode): boolean { visitFunction(node: FunctionNode): boolean {
const symbol = this._bindNameToScope(this._currentScope, node.name.nameToken.value); const symbol = this._bindNameToScope(this._currentScope, node.name.nameToken.value);
const containingClassNode = ParseTreeUtils.getEnclosingClass(node, true); const containingClassNode = ParseTreeUtils.getEnclosingClass(node, true);
const declarationType = containingClassNode ? const declarationType = containingClassNode ?
@ -384,7 +383,7 @@ export class Binder extends ParseTreeWalker {
}); });
} }
this._createAssignmentTargetFlowNodes(paramNode.name); this._createFlowAssignment(paramNode.name);
} }
}); });
@ -442,7 +441,7 @@ export class Binder extends ParseTreeWalker {
}); });
} }
this._createAssignmentTargetFlowNodes(paramNode.name); this._createFlowAssignment(paramNode.name);
this.walk(paramNode.name); this.walk(paramNode.name);
} }
}); });

View File

@ -219,8 +219,6 @@ export interface TypeEvaluator {
getTypeOfImportAsTarget: (node: ImportAsNode) => Type | undefined; getTypeOfImportAsTarget: (node: ImportAsNode) => Type | undefined;
getTypeOfImportFromTarget: (node: ImportFromAsNode) => Type | undefined; getTypeOfImportFromTarget: (node: ImportFromAsNode) => Type | undefined;
getTypingType: (node: ParseNode, symbolName: string) => Type | undefined;
getDeclaredTypeForExpression: (expression: ExpressionNode) => Type | undefined; getDeclaredTypeForExpression: (expression: ExpressionNode) => Type | undefined;
isAnnotationLiteralValue: (node: StringListNode) => boolean; isAnnotationLiteralValue: (node: StringListNode) => boolean;
@ -230,10 +228,6 @@ export interface TypeEvaluator {
transformTypeForPossibleEnumClass: (node: NameNode, typeOfExpr: Type) => Type; transformTypeForPossibleEnumClass: (node: NameNode, typeOfExpr: Type) => Type;
assignTypeToNameNode: (nameNode: NameNode, type: Type, srcExpression?: ParseNode) => void;
assignTypeToExpression: (target: ExpressionNode, type: Type, srcExpr?: ExpressionNode,
targetOfInterest?: ExpressionNode) => Type | undefined;
updateExpressionTypeForNode: (node: ParseNode, exprType: Type) => void; updateExpressionTypeForNode: (node: ParseNode, exprType: Type) => void;
addError: (message: string, node: ParseNode) => Diagnostic | undefined; addError: (message: string, node: ParseNode) => Diagnostic | undefined;
@ -245,7 +239,6 @@ export interface TypeEvaluator {
} }
export function createTypeEvaluator(importLookup: ImportLookup): TypeEvaluator { export function createTypeEvaluator(importLookup: ImportLookup): TypeEvaluator {
let isSpeculativeMode = false; let isSpeculativeMode = false;
const typeResolutionRecursionMap = new Map<number, true>(); const typeResolutionRecursionMap = new Map<number, true>();
@ -253,14 +246,6 @@ export function createTypeEvaluator(importLookup: ImportLookup): TypeEvaluator {
return getTypeOfExpression(node, usage, flags).type; return getTypeOfExpression(node, usage, flags).type;
} }
function getTypeNoCache(node: ExpressionNode, usage: EvaluatorUsage = { method: 'get' }, flags = EvaluatorFlags.None): Type {
let type: Type | undefined;
useSpeculativeMode(() => {
type = getTypeOfExpression(node, usage, flags).type;
});
return type!;
}
function getTypeOfAnnotation(node: ExpressionNode): Type { function getTypeOfAnnotation(node: ExpressionNode): Type {
const fileInfo = getFileInfo(node); const fileInfo = getFileInfo(node);
@ -390,9 +375,7 @@ export function createTypeEvaluator(importLookup: ImportLookup): TypeEvaluator {
} }
case ParseNodeType.MemberAccess: { case ParseNodeType.MemberAccess: {
// Get the base type but do so speculative because we're going to call again const baseType = getType(expression.leftExpression);
// with a 'set' usage type below, and we don't want to skip that logic.
const baseType = getTypeNoCache(expression.leftExpression);
let classMemberInfo: ClassMember | undefined; let classMemberInfo: ClassMember | undefined;
if (baseType.category === TypeCategory.Object) { if (baseType.category === TypeCategory.Object) {
@ -7115,14 +7098,11 @@ export function createTypeEvaluator(importLookup: ImportLookup): TypeEvaluator {
getTypeOfWithItemTarget, getTypeOfWithItemTarget,
getTypeOfImportAsTarget, getTypeOfImportAsTarget,
getTypeOfImportFromTarget, getTypeOfImportFromTarget,
getTypingType,
getDeclaredTypeForExpression, getDeclaredTypeForExpression,
isAnnotationLiteralValue, isAnnotationLiteralValue,
isAfterNodeReachable, isAfterNodeReachable,
isNodeReachable, isNodeReachable,
transformTypeForPossibleEnumClass, transformTypeForPossibleEnumClass,
assignTypeToNameNode,
assignTypeToExpression,
updateExpressionTypeForNode, updateExpressionTypeForNode,
addError, addError,
addWarning, addWarning,