Fixed a few more bugs found with manual testing and code review.

This commit is contained in:
Eric Traut 2020-03-21 00:02:51 -06:00
parent 911e42c91c
commit 7ae0d93829
2 changed files with 17 additions and 5 deletions

View File

@ -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()}'`

View File

@ -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(() => {