From 60d58132e4ecfba063b5c9df06acdd05b25decdf Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 24 Jun 2021 14:31:53 -0500 Subject: [PATCH] Use same behavior for call expressions --- src/compiler/checker.ts | 4 ---- ...ruthinessCallExpressionCoercion4.errors.txt | 12 ++++++++++++ .../truthinessCallExpressionCoercion4.js | 12 ++++++++++++ .../truthinessCallExpressionCoercion4.symbols | 13 +++++++++++++ .../truthinessCallExpressionCoercion4.types | 18 ++++++++++++++++++ .../truthinessCallExpressionCoercion4.ts | 7 +++++++ 6 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/truthinessCallExpressionCoercion4.errors.txt create mode 100644 tests/baselines/reference/truthinessCallExpressionCoercion4.js create mode 100644 tests/baselines/reference/truthinessCallExpressionCoercion4.symbols create mode 100644 tests/baselines/reference/truthinessCallExpressionCoercion4.types create mode 100644 tests/cases/compiler/truthinessCallExpressionCoercion4.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 08c6f9732f5..5a1cbf6d626 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -35720,10 +35720,6 @@ namespace ts { } const testedSymbol = testedNode && getSymbolAtLocation(testedNode); - if (!testedSymbol && !isPromise) { - return; - } - const isUsed = testedSymbol && isBinaryExpression(condExpr.parent) && isSymbolUsedInBinaryExpressionChain(condExpr.parent, testedSymbol) || testedSymbol && body && isSymbolUsedInConditionBody(condExpr, body, testedNode!, testedSymbol); if (!isUsed) { diff --git a/tests/baselines/reference/truthinessCallExpressionCoercion4.errors.txt b/tests/baselines/reference/truthinessCallExpressionCoercion4.errors.txt new file mode 100644 index 00000000000..225d7a91175 --- /dev/null +++ b/tests/baselines/reference/truthinessCallExpressionCoercion4.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/truthinessCallExpressionCoercion4.ts(3,5): error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? + + +==== tests/cases/compiler/truthinessCallExpressionCoercion4.ts (1 errors) ==== + const or = x => y => x || y; + + if (or(true)) { // error + ~~~~~~~~ +!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead? + + } + \ No newline at end of file diff --git a/tests/baselines/reference/truthinessCallExpressionCoercion4.js b/tests/baselines/reference/truthinessCallExpressionCoercion4.js new file mode 100644 index 00000000000..3b5cace6ae0 --- /dev/null +++ b/tests/baselines/reference/truthinessCallExpressionCoercion4.js @@ -0,0 +1,12 @@ +//// [truthinessCallExpressionCoercion4.ts] +const or = x => y => x || y; + +if (or(true)) { // error + +} + + +//// [truthinessCallExpressionCoercion4.js] +var or = function (x) { return function (y) { return x || y; }; }; +if (or(true)) { // error +} diff --git a/tests/baselines/reference/truthinessCallExpressionCoercion4.symbols b/tests/baselines/reference/truthinessCallExpressionCoercion4.symbols new file mode 100644 index 00000000000..7880b68f4f6 --- /dev/null +++ b/tests/baselines/reference/truthinessCallExpressionCoercion4.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/truthinessCallExpressionCoercion4.ts === +const or = x => y => x || y; +>or : Symbol(or, Decl(truthinessCallExpressionCoercion4.ts, 0, 5)) +>x : Symbol(x, Decl(truthinessCallExpressionCoercion4.ts, 0, 10)) +>y : Symbol(y, Decl(truthinessCallExpressionCoercion4.ts, 0, 15)) +>x : Symbol(x, Decl(truthinessCallExpressionCoercion4.ts, 0, 10)) +>y : Symbol(y, Decl(truthinessCallExpressionCoercion4.ts, 0, 15)) + +if (or(true)) { // error +>or : Symbol(or, Decl(truthinessCallExpressionCoercion4.ts, 0, 5)) + +} + diff --git a/tests/baselines/reference/truthinessCallExpressionCoercion4.types b/tests/baselines/reference/truthinessCallExpressionCoercion4.types new file mode 100644 index 00000000000..8c859b4a452 --- /dev/null +++ b/tests/baselines/reference/truthinessCallExpressionCoercion4.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/truthinessCallExpressionCoercion4.ts === +const or = x => y => x || y; +>or : (x: any) => (y: any) => any +>x => y => x || y : (x: any) => (y: any) => any +>x : any +>y => x || y : (y: any) => any +>y : any +>x || y : any +>x : any +>y : any + +if (or(true)) { // error +>or(true) : (y: any) => any +>or : (x: any) => (y: any) => any +>true : true + +} + diff --git a/tests/cases/compiler/truthinessCallExpressionCoercion4.ts b/tests/cases/compiler/truthinessCallExpressionCoercion4.ts new file mode 100644 index 00000000000..cd7af968d7a --- /dev/null +++ b/tests/cases/compiler/truthinessCallExpressionCoercion4.ts @@ -0,0 +1,7 @@ +// @strictNullChecks: true + +const or = x => y => x || y; + +if (or(true)) { // error + +}