From 7ae0d93829633f64b9947bfe99efc84a63509d92 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Sat, 21 Mar 2020 00:02:51 -0600 Subject: [PATCH] Fixed a few more bugs found with manual testing and code review. --- server/src/analyzer/program.ts | 14 ++++++++++++-- server/src/analyzer/typeEvaluator.ts | 8 +++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/server/src/analyzer/program.ts b/server/src/analyzer/program.ts index 3d3680146..eafbc71c9 100644 --- a/server/src/analyzer/program.ts +++ b/server/src/analyzer/program.ts @@ -552,6 +552,16 @@ export class Program { return false; } + // Don't bother checking third-party imports or typeshed files unless they're open. + if ( + fileToCheck.isThirdPartyImport || + (fileToCheck.isTypeshedFile && this._configOptions.diagnosticSettings.reportTypeshedErrors === 'none') + ) { + if (!fileToCheck.isOpenByClient) { + return false; + } + } + if (this._configOptions.checkOnlyOpenFiles && !fileToCheck.isOpenByClient) { return false; } @@ -694,7 +704,7 @@ export class Program { const fileDiagnostics: FileDiagnostics[] = this._removeUnneededFiles(); this._sourceFileList.forEach(sourceFileInfo => { - if (!options.checkOnlyOpenFiles || sourceFileInfo.isOpenByClient) { + if (sourceFileInfo.isOpenByClient || (!options.checkOnlyOpenFiles && !sourceFileInfo.isThirdPartyImport)) { const diagnostics = sourceFileInfo.sourceFile.getDiagnostics( options, sourceFileInfo.diagnosticsVersion @@ -1148,7 +1158,7 @@ export class Program { } }); } else if (options.verboseOutput) { - if (!sourceFileInfo.isTypeshedFile || options.diagnosticSettings.reportTypeshedErrors) { + if (!sourceFileInfo.isTypeshedFile || options.diagnosticSettings.reportTypeshedErrors !== 'none') { this._console.log( `Could not import '${importResult.importName}' ` + `in file '${sourceFileInfo.sourceFile.getFilePath()}'` diff --git a/server/src/analyzer/typeEvaluator.ts b/server/src/analyzer/typeEvaluator.ts index 2c50b81cd..8332019f2 100644 --- a/server/src/analyzer/typeEvaluator.ts +++ b/server/src/analyzer/typeEvaluator.ts @@ -9653,6 +9653,11 @@ export function createTypeEvaluator(importLookup: ImportLookup): TypeEvaluator { function getFunctionInferredReturnType(type: FunctionType, args?: ValidateArgTypeParams[]) { let returnType: Type | undefined; + // Don't attempt to infer the return type for a stub file. + if (FunctionType.isStubDefinition(type)) { + return UnknownType.create(); + } + // If the return type has already been lazily evaluated, // don't bother computing it again. if (type.inferredReturnType) { @@ -9661,9 +9666,6 @@ export function createTypeEvaluator(importLookup: ImportLookup): TypeEvaluator { if (type.details.declaration) { const functionNode = type.details.declaration.node; - // We should never get here if there is a type annotation. - assert(!functionNode.returnTypeAnnotation); - // Temporarily disable speculative mode while we // lazily evaluate the return type. disableSpeculativeMode(() => {