Skip to content

Commit 60d5813

Browse files
committed
Use same behavior for call expressions
1 parent 2522469 commit 60d5813

6 files changed

+62
-4
lines changed

Diff for: src/compiler/checker.ts

-4
Original file line numberDiff line numberDiff line change
@@ -35720,10 +35720,6 @@ namespace ts {
3572035720
}
3572135721

3572235722
const testedSymbol = testedNode && getSymbolAtLocation(testedNode);
35723-
if (!testedSymbol && !isPromise) {
35724-
return;
35725-
}
35726-
3572735723
const isUsed = testedSymbol && isBinaryExpression(condExpr.parent) && isSymbolUsedInBinaryExpressionChain(condExpr.parent, testedSymbol)
3572835724
|| testedSymbol && body && isSymbolUsedInConditionBody(condExpr, body, testedNode!, testedSymbol);
3572935725
if (!isUsed) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
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?
2+
3+
4+
==== tests/cases/compiler/truthinessCallExpressionCoercion4.ts (1 errors) ====
5+
const or = x => y => x || y;
6+
7+
if (or(true)) { // error
8+
~~~~~~~~
9+
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
10+
11+
}
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [truthinessCallExpressionCoercion4.ts]
2+
const or = x => y => x || y;
3+
4+
if (or(true)) { // error
5+
6+
}
7+
8+
9+
//// [truthinessCallExpressionCoercion4.js]
10+
var or = function (x) { return function (y) { return x || y; }; };
11+
if (or(true)) { // error
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/truthinessCallExpressionCoercion4.ts ===
2+
const or = x => y => x || y;
3+
>or : Symbol(or, Decl(truthinessCallExpressionCoercion4.ts, 0, 5))
4+
>x : Symbol(x, Decl(truthinessCallExpressionCoercion4.ts, 0, 10))
5+
>y : Symbol(y, Decl(truthinessCallExpressionCoercion4.ts, 0, 15))
6+
>x : Symbol(x, Decl(truthinessCallExpressionCoercion4.ts, 0, 10))
7+
>y : Symbol(y, Decl(truthinessCallExpressionCoercion4.ts, 0, 15))
8+
9+
if (or(true)) { // error
10+
>or : Symbol(or, Decl(truthinessCallExpressionCoercion4.ts, 0, 5))
11+
12+
}
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/truthinessCallExpressionCoercion4.ts ===
2+
const or = x => y => x || y;
3+
>or : (x: any) => (y: any) => any
4+
>x => y => x || y : (x: any) => (y: any) => any
5+
>x : any
6+
>y => x || y : (y: any) => any
7+
>y : any
8+
>x || y : any
9+
>x : any
10+
>y : any
11+
12+
if (or(true)) { // error
13+
>or(true) : (y: any) => any
14+
>or : (x: any) => (y: any) => any
15+
>true : true
16+
17+
}
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @strictNullChecks: true
2+
3+
const or = x => y => x || y;
4+
5+
if (or(true)) { // error
6+
7+
}

0 commit comments

Comments
 (0)