Skip to content

Commit

Permalink
Use same behavior for call expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Jun 24, 2021
1 parent 2522469 commit 60d5813
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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?

}

12 changes: 12 additions & 0 deletions tests/baselines/reference/truthinessCallExpressionCoercion4.js
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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))

}

18 changes: 18 additions & 0 deletions tests/baselines/reference/truthinessCallExpressionCoercion4.types
Original file line number Diff line number Diff line change
@@ -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

}

7 changes: 7 additions & 0 deletions tests/cases/compiler/truthinessCallExpressionCoercion4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @strictNullChecks: true

const or = x => y => x || y;

if (or(true)) { // error

}

0 comments on commit 60d5813

Please sign in to comment.