Use same behavior for call expressions

This commit is contained in:
Andrew Branch
2021-06-24 14:31:53 -05:00
parent 252246976c
commit 60d58132e4
6 changed files with 62 additions and 4 deletions
-4
View File
@@ -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) {
@@ -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?
}
@@ -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
}
@@ -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))
}
@@ -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
}
@@ -0,0 +1,7 @@
// @strictNullChecks: true
const or = x => y => x || y;
if (or(true)) { // error
}