mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-15 05:55:11 -05:00
fix(41492): make more friendly handling the missing call function in binary expressions (#41502)
This commit is contained in:
@@ -34029,7 +34029,16 @@ namespace ts {
|
||||
|
||||
function isFunctionUsedInBinaryExpressionChain(node: Node, testedSymbol: Symbol): boolean {
|
||||
while (isBinaryExpression(node) && node.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken) {
|
||||
if (isCallExpression(node.right) && testedSymbol === getSymbolAtLocation(node.right.expression)) {
|
||||
const isUsed = forEachChild(node.right, function visit(child): boolean | undefined {
|
||||
if (isIdentifier(child)) {
|
||||
const symbol = getSymbolAtLocation(child);
|
||||
if (symbol && symbol === testedSymbol) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return forEachChild(child, visit);
|
||||
});
|
||||
if (isUsed) {
|
||||
return true;
|
||||
}
|
||||
node = node.parent;
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(3,5): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(6,10): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(30,18): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(36,46): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(47,5): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(50,10): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(66,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(69,14): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(11,5): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(14,10): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(41,18): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(47,46): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(58,5): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(61,10): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(81,5): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(91,9): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
tests/cases/compiler/truthinessCallExpressionCoercion2.ts(94,14): error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
|
||||
|
||||
==== tests/cases/compiler/truthinessCallExpressionCoercion2.ts (8 errors) ====
|
||||
==== tests/cases/compiler/truthinessCallExpressionCoercion2.ts (9 errors) ====
|
||||
declare class A {
|
||||
static from(): string;
|
||||
}
|
||||
|
||||
declare class B {
|
||||
static from(): string;
|
||||
}
|
||||
|
||||
function test(required1: () => boolean, required2: () => boolean, optional?: () => boolean) {
|
||||
// error
|
||||
required1 && console.log('required');
|
||||
@@ -41,6 +50,9 @@ tests/cases/compiler/truthinessCallExpressionCoercion2.ts(69,14): error TS2774:
|
||||
// ok
|
||||
required1 && required2 && required1() && required2();
|
||||
|
||||
// ok
|
||||
[].forEach((f: () => void) => f && f.apply(parent, []));
|
||||
|
||||
// error
|
||||
required1 && required2 && required1() && console.log('foo');
|
||||
~~~~~~~~~
|
||||
@@ -77,6 +89,22 @@ tests/cases/compiler/truthinessCallExpressionCoercion2.ts(69,14): error TS2774:
|
||||
|
||||
// ok
|
||||
x.foo.bar && 1 && x.foo.bar();
|
||||
|
||||
// ok
|
||||
const y = A.from && (A.from as Function) !== B.from ? true : false;
|
||||
y;
|
||||
|
||||
const x1 = {
|
||||
a: { b: { c: () => {} } }
|
||||
}
|
||||
const x2 = {
|
||||
a: { b: { c: () => {} } }
|
||||
}
|
||||
|
||||
// error
|
||||
x1.a.b.c && x2.a.b.c();
|
||||
~~~~~~~~
|
||||
!!! error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?
|
||||
}
|
||||
|
||||
class Foo {
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
//// [truthinessCallExpressionCoercion2.ts]
|
||||
declare class A {
|
||||
static from(): string;
|
||||
}
|
||||
|
||||
declare class B {
|
||||
static from(): string;
|
||||
}
|
||||
|
||||
function test(required1: () => boolean, required2: () => boolean, optional?: () => boolean) {
|
||||
// error
|
||||
required1 && console.log('required');
|
||||
@@ -27,6 +35,9 @@ function test(required1: () => boolean, required2: () => boolean, optional?: ()
|
||||
// ok
|
||||
required1 && required2 && required1() && required2();
|
||||
|
||||
// ok
|
||||
[].forEach((f: () => void) => f && f.apply(parent, []));
|
||||
|
||||
// error
|
||||
required1 && required2 && required1() && console.log('foo');
|
||||
}
|
||||
@@ -55,6 +66,20 @@ function checksPropertyAccess() {
|
||||
|
||||
// ok
|
||||
x.foo.bar && 1 && x.foo.bar();
|
||||
|
||||
// ok
|
||||
const y = A.from && (A.from as Function) !== B.from ? true : false;
|
||||
y;
|
||||
|
||||
const x1 = {
|
||||
a: { b: { c: () => {} } }
|
||||
}
|
||||
const x2 = {
|
||||
a: { b: { c: () => {} } }
|
||||
}
|
||||
|
||||
// error
|
||||
x1.a.b.c && x2.a.b.c();
|
||||
}
|
||||
|
||||
class Foo {
|
||||
@@ -101,6 +126,8 @@ function test(required1, required2, optional) {
|
||||
required1() && console.log('required call');
|
||||
// ok
|
||||
required1 && required2 && required1() && required2();
|
||||
// ok
|
||||
[].forEach(function (f) { return f && f.apply(parent, []); });
|
||||
// error
|
||||
required1 && required2 && required1() && console.log('foo');
|
||||
}
|
||||
@@ -123,6 +150,17 @@ function checksPropertyAccess() {
|
||||
x.foo.bar && x.foo.bar();
|
||||
// ok
|
||||
x.foo.bar && 1 && x.foo.bar();
|
||||
// ok
|
||||
var y = A.from && A.from !== B.from ? true : false;
|
||||
y;
|
||||
var x1 = {
|
||||
a: { b: { c: function () { } } }
|
||||
};
|
||||
var x2 = {
|
||||
a: { b: { c: function () { } } }
|
||||
};
|
||||
// error
|
||||
x1.a.b.c && x2.a.b.c();
|
||||
}
|
||||
var Foo = /** @class */ (function () {
|
||||
function Foo() {
|
||||
|
||||
@@ -1,81 +1,106 @@
|
||||
=== tests/cases/compiler/truthinessCallExpressionCoercion2.ts ===
|
||||
declare class A {
|
||||
>A : Symbol(A, Decl(truthinessCallExpressionCoercion2.ts, 0, 0))
|
||||
|
||||
static from(): string;
|
||||
>from : Symbol(A.from, Decl(truthinessCallExpressionCoercion2.ts, 0, 17))
|
||||
}
|
||||
|
||||
declare class B {
|
||||
>B : Symbol(B, Decl(truthinessCallExpressionCoercion2.ts, 2, 1))
|
||||
|
||||
static from(): string;
|
||||
>from : Symbol(B.from, Decl(truthinessCallExpressionCoercion2.ts, 4, 17))
|
||||
}
|
||||
|
||||
function test(required1: () => boolean, required2: () => boolean, optional?: () => boolean) {
|
||||
>test : Symbol(test, Decl(truthinessCallExpressionCoercion2.ts, 0, 0))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required2 : Symbol(required2, Decl(truthinessCallExpressionCoercion2.ts, 0, 39))
|
||||
>optional : Symbol(optional, Decl(truthinessCallExpressionCoercion2.ts, 0, 65))
|
||||
>test : Symbol(test, Decl(truthinessCallExpressionCoercion2.ts, 6, 1))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
>required2 : Symbol(required2, Decl(truthinessCallExpressionCoercion2.ts, 8, 39))
|
||||
>optional : Symbol(optional, Decl(truthinessCallExpressionCoercion2.ts, 8, 65))
|
||||
|
||||
// error
|
||||
required1 && console.log('required');
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
// error
|
||||
1 && required1 && console.log('required');
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
// ok
|
||||
required1 && required1();
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
|
||||
// ok
|
||||
required1 && 1 && required1();
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
|
||||
// ok
|
||||
optional && console.log('optional');
|
||||
>optional : Symbol(optional, Decl(truthinessCallExpressionCoercion2.ts, 0, 65))
|
||||
>optional : Symbol(optional, Decl(truthinessCallExpressionCoercion2.ts, 8, 65))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
// ok
|
||||
1 && optional && console.log('optional');
|
||||
>optional : Symbol(optional, Decl(truthinessCallExpressionCoercion2.ts, 0, 65))
|
||||
>optional : Symbol(optional, Decl(truthinessCallExpressionCoercion2.ts, 8, 65))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
// ok
|
||||
!!required1 && console.log('not required');
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
// ok
|
||||
required1() && console.log('required call');
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
// ok
|
||||
required1 && required2 && required1() && required2();
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required2 : Symbol(required2, Decl(truthinessCallExpressionCoercion2.ts, 0, 39))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required2 : Symbol(required2, Decl(truthinessCallExpressionCoercion2.ts, 0, 39))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
>required2 : Symbol(required2, Decl(truthinessCallExpressionCoercion2.ts, 8, 39))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
>required2 : Symbol(required2, Decl(truthinessCallExpressionCoercion2.ts, 8, 39))
|
||||
|
||||
// ok
|
||||
[].forEach((f: () => void) => f && f.apply(parent, []));
|
||||
>[].forEach : Symbol(Array.forEach, Decl(lib.es5.d.ts, --, --))
|
||||
>forEach : Symbol(Array.forEach, Decl(lib.es5.d.ts, --, --))
|
||||
>f : Symbol(f, Decl(truthinessCallExpressionCoercion2.ts, 37, 16))
|
||||
>f : Symbol(f, Decl(truthinessCallExpressionCoercion2.ts, 37, 16))
|
||||
>f.apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --))
|
||||
>f : Symbol(f, Decl(truthinessCallExpressionCoercion2.ts, 37, 16))
|
||||
>apply : Symbol(Function.apply, Decl(lib.es5.d.ts, --, --))
|
||||
>parent : Symbol(parent, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
// error
|
||||
required1 && required2 && required1() && console.log('foo');
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required2 : Symbol(required2, Decl(truthinessCallExpressionCoercion2.ts, 0, 39))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 0, 14))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
>required2 : Symbol(required2, Decl(truthinessCallExpressionCoercion2.ts, 8, 39))
|
||||
>required1 : Symbol(required1, Decl(truthinessCallExpressionCoercion2.ts, 8, 14))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
}
|
||||
|
||||
function checksConsole() {
|
||||
>checksConsole : Symbol(checksConsole, Decl(truthinessCallExpressionCoercion2.ts, 30, 1))
|
||||
>checksConsole : Symbol(checksConsole, Decl(truthinessCallExpressionCoercion2.ts, 41, 1))
|
||||
|
||||
// error
|
||||
typeof window !== 'undefined' && window.console &&
|
||||
@@ -101,123 +126,174 @@ function checksConsole() {
|
||||
}
|
||||
|
||||
function checksPropertyAccess() {
|
||||
>checksPropertyAccess : Symbol(checksPropertyAccess, Decl(truthinessCallExpressionCoercion2.ts, 36, 1))
|
||||
>checksPropertyAccess : Symbol(checksPropertyAccess, Decl(truthinessCallExpressionCoercion2.ts, 47, 1))
|
||||
|
||||
const x = {
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 39, 9))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 50, 9))
|
||||
|
||||
foo: {
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
|
||||
bar() { return true; }
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
}
|
||||
}
|
||||
|
||||
// error
|
||||
x.foo.bar && console.log('x.foo.bar');
|
||||
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 39, 9))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 50, 9))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
// error
|
||||
1 && x.foo.bar && console.log('x.foo.bar');
|
||||
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 39, 9))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 50, 9))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
// ok
|
||||
x.foo.bar && x.foo.bar();
|
||||
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 39, 9))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 39, 9))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 50, 9))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 50, 9))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
|
||||
// ok
|
||||
x.foo.bar && 1 && x.foo.bar();
|
||||
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 39, 9))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 39, 9))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 39, 15))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 40, 14))
|
||||
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 50, 9))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
>x.foo.bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
>x.foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
>x : Symbol(x, Decl(truthinessCallExpressionCoercion2.ts, 50, 9))
|
||||
>foo : Symbol(foo, Decl(truthinessCallExpressionCoercion2.ts, 50, 15))
|
||||
>bar : Symbol(bar, Decl(truthinessCallExpressionCoercion2.ts, 51, 14))
|
||||
|
||||
// ok
|
||||
const y = A.from && (A.from as Function) !== B.from ? true : false;
|
||||
>y : Symbol(y, Decl(truthinessCallExpressionCoercion2.ts, 69, 9))
|
||||
>A.from : Symbol(A.from, Decl(truthinessCallExpressionCoercion2.ts, 0, 17))
|
||||
>A : Symbol(A, Decl(truthinessCallExpressionCoercion2.ts, 0, 0))
|
||||
>from : Symbol(A.from, Decl(truthinessCallExpressionCoercion2.ts, 0, 17))
|
||||
>A.from : Symbol(A.from, Decl(truthinessCallExpressionCoercion2.ts, 0, 17))
|
||||
>A : Symbol(A, Decl(truthinessCallExpressionCoercion2.ts, 0, 0))
|
||||
>from : Symbol(A.from, Decl(truthinessCallExpressionCoercion2.ts, 0, 17))
|
||||
>Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
|
||||
>B.from : Symbol(B.from, Decl(truthinessCallExpressionCoercion2.ts, 4, 17))
|
||||
>B : Symbol(B, Decl(truthinessCallExpressionCoercion2.ts, 2, 1))
|
||||
>from : Symbol(B.from, Decl(truthinessCallExpressionCoercion2.ts, 4, 17))
|
||||
|
||||
y;
|
||||
>y : Symbol(y, Decl(truthinessCallExpressionCoercion2.ts, 69, 9))
|
||||
|
||||
const x1 = {
|
||||
>x1 : Symbol(x1, Decl(truthinessCallExpressionCoercion2.ts, 72, 9))
|
||||
|
||||
a: { b: { c: () => {} } }
|
||||
>a : Symbol(a, Decl(truthinessCallExpressionCoercion2.ts, 72, 16))
|
||||
>b : Symbol(b, Decl(truthinessCallExpressionCoercion2.ts, 73, 12))
|
||||
>c : Symbol(c, Decl(truthinessCallExpressionCoercion2.ts, 73, 17))
|
||||
}
|
||||
const x2 = {
|
||||
>x2 : Symbol(x2, Decl(truthinessCallExpressionCoercion2.ts, 75, 9))
|
||||
|
||||
a: { b: { c: () => {} } }
|
||||
>a : Symbol(a, Decl(truthinessCallExpressionCoercion2.ts, 75, 16))
|
||||
>b : Symbol(b, Decl(truthinessCallExpressionCoercion2.ts, 76, 12))
|
||||
>c : Symbol(c, Decl(truthinessCallExpressionCoercion2.ts, 76, 17))
|
||||
}
|
||||
|
||||
// error
|
||||
x1.a.b.c && x2.a.b.c();
|
||||
>x1.a.b.c : Symbol(c, Decl(truthinessCallExpressionCoercion2.ts, 73, 17))
|
||||
>x1.a.b : Symbol(b, Decl(truthinessCallExpressionCoercion2.ts, 73, 12))
|
||||
>x1.a : Symbol(a, Decl(truthinessCallExpressionCoercion2.ts, 72, 16))
|
||||
>x1 : Symbol(x1, Decl(truthinessCallExpressionCoercion2.ts, 72, 9))
|
||||
>a : Symbol(a, Decl(truthinessCallExpressionCoercion2.ts, 72, 16))
|
||||
>b : Symbol(b, Decl(truthinessCallExpressionCoercion2.ts, 73, 12))
|
||||
>c : Symbol(c, Decl(truthinessCallExpressionCoercion2.ts, 73, 17))
|
||||
>x2.a.b.c : Symbol(c, Decl(truthinessCallExpressionCoercion2.ts, 76, 17))
|
||||
>x2.a.b : Symbol(b, Decl(truthinessCallExpressionCoercion2.ts, 76, 12))
|
||||
>x2.a : Symbol(a, Decl(truthinessCallExpressionCoercion2.ts, 75, 16))
|
||||
>x2 : Symbol(x2, Decl(truthinessCallExpressionCoercion2.ts, 75, 9))
|
||||
>a : Symbol(a, Decl(truthinessCallExpressionCoercion2.ts, 75, 16))
|
||||
>b : Symbol(b, Decl(truthinessCallExpressionCoercion2.ts, 76, 12))
|
||||
>c : Symbol(c, Decl(truthinessCallExpressionCoercion2.ts, 76, 17))
|
||||
}
|
||||
|
||||
class Foo {
|
||||
>Foo : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 56, 1))
|
||||
>Foo : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 81, 1))
|
||||
|
||||
optional?: () => boolean;
|
||||
>optional : Symbol(Foo.optional, Decl(truthinessCallExpressionCoercion2.ts, 58, 11))
|
||||
>optional : Symbol(Foo.optional, Decl(truthinessCallExpressionCoercion2.ts, 83, 11))
|
||||
|
||||
required() {
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
|
||||
return true;
|
||||
}
|
||||
test() {
|
||||
>test : Symbol(Foo.test, Decl(truthinessCallExpressionCoercion2.ts, 62, 5))
|
||||
>test : Symbol(Foo.test, Decl(truthinessCallExpressionCoercion2.ts, 87, 5))
|
||||
|
||||
// error
|
||||
this.required && console.log('required');
|
||||
>this.required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 56, 1))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>this.required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 81, 1))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
// error
|
||||
1 && this.required && console.log('required');
|
||||
>this.required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 56, 1))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>this.required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 81, 1))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
// ok
|
||||
this.required && this.required();
|
||||
>this.required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 56, 1))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>this.required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 56, 1))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>this.required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 81, 1))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
>this.required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 81, 1))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
|
||||
// ok
|
||||
this.required && 1 && this.required();
|
||||
>this.required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 56, 1))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>this.required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 56, 1))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 59, 29))
|
||||
>this.required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 81, 1))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
>this.required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 81, 1))
|
||||
>required : Symbol(Foo.required, Decl(truthinessCallExpressionCoercion2.ts, 84, 29))
|
||||
|
||||
// ok
|
||||
1 && this.optional && console.log('optional');
|
||||
>this.optional : Symbol(Foo.optional, Decl(truthinessCallExpressionCoercion2.ts, 58, 11))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 56, 1))
|
||||
>optional : Symbol(Foo.optional, Decl(truthinessCallExpressionCoercion2.ts, 58, 11))
|
||||
>this.optional : Symbol(Foo.optional, Decl(truthinessCallExpressionCoercion2.ts, 83, 11))
|
||||
>this : Symbol(Foo, Decl(truthinessCallExpressionCoercion2.ts, 81, 1))
|
||||
>optional : Symbol(Foo.optional, Decl(truthinessCallExpressionCoercion2.ts, 83, 11))
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
=== tests/cases/compiler/truthinessCallExpressionCoercion2.ts ===
|
||||
declare class A {
|
||||
>A : A
|
||||
|
||||
static from(): string;
|
||||
>from : () => string
|
||||
}
|
||||
|
||||
declare class B {
|
||||
>B : B
|
||||
|
||||
static from(): string;
|
||||
>from : () => string
|
||||
}
|
||||
|
||||
function test(required1: () => boolean, required2: () => boolean, optional?: () => boolean) {
|
||||
>test : (required1: () => boolean, required2: () => boolean, optional?: (() => boolean) | undefined) => void
|
||||
>required1 : () => boolean
|
||||
@@ -100,6 +114,23 @@ function test(required1: () => boolean, required2: () => boolean, optional?: ()
|
||||
>required2() : boolean
|
||||
>required2 : () => boolean
|
||||
|
||||
// ok
|
||||
[].forEach((f: () => void) => f && f.apply(parent, []));
|
||||
>[].forEach((f: () => void) => f && f.apply(parent, [])) : void
|
||||
>[].forEach : (callbackfn: (value: never, index: number, array: never[]) => void, thisArg?: any) => void
|
||||
>[] : never[]
|
||||
>forEach : (callbackfn: (value: never, index: number, array: never[]) => void, thisArg?: any) => void
|
||||
>(f: () => void) => f && f.apply(parent, []) : (f: () => void) => any
|
||||
>f : () => void
|
||||
>f && f.apply(parent, []) : any
|
||||
>f : () => void
|
||||
>f.apply(parent, []) : any
|
||||
>f.apply : (this: Function, thisArg: any, argArray?: any) => any
|
||||
>f : () => void
|
||||
>apply : (this: Function, thisArg: any, argArray?: any) => any
|
||||
>parent : Window
|
||||
>[] : never[]
|
||||
|
||||
// error
|
||||
required1 && required2 && required1() && console.log('foo');
|
||||
>required1 && required2 && required1() && console.log('foo') : false | void
|
||||
@@ -233,6 +264,73 @@ function checksPropertyAccess() {
|
||||
>x : { foo: { bar(): boolean; }; }
|
||||
>foo : { bar(): boolean; }
|
||||
>bar : () => boolean
|
||||
|
||||
// ok
|
||||
const y = A.from && (A.from as Function) !== B.from ? true : false;
|
||||
>y : boolean
|
||||
>A.from && (A.from as Function) !== B.from ? true : false : boolean
|
||||
>A.from && (A.from as Function) !== B.from : boolean
|
||||
>A.from : () => string
|
||||
>A : typeof A
|
||||
>from : () => string
|
||||
>(A.from as Function) !== B.from : boolean
|
||||
>(A.from as Function) : Function
|
||||
>A.from as Function : Function
|
||||
>A.from : () => string
|
||||
>A : typeof A
|
||||
>from : () => string
|
||||
>B.from : () => string
|
||||
>B : typeof B
|
||||
>from : () => string
|
||||
>true : true
|
||||
>false : false
|
||||
|
||||
y;
|
||||
>y : boolean
|
||||
|
||||
const x1 = {
|
||||
>x1 : { a: { b: { c: () => void; }; }; }
|
||||
>{ a: { b: { c: () => {} } } } : { a: { b: { c: () => void; }; }; }
|
||||
|
||||
a: { b: { c: () => {} } }
|
||||
>a : { b: { c: () => void; }; }
|
||||
>{ b: { c: () => {} } } : { b: { c: () => void; }; }
|
||||
>b : { c: () => void; }
|
||||
>{ c: () => {} } : { c: () => void; }
|
||||
>c : () => void
|
||||
>() => {} : () => void
|
||||
}
|
||||
const x2 = {
|
||||
>x2 : { a: { b: { c: () => void; }; }; }
|
||||
>{ a: { b: { c: () => {} } } } : { a: { b: { c: () => void; }; }; }
|
||||
|
||||
a: { b: { c: () => {} } }
|
||||
>a : { b: { c: () => void; }; }
|
||||
>{ b: { c: () => {} } } : { b: { c: () => void; }; }
|
||||
>b : { c: () => void; }
|
||||
>{ c: () => {} } : { c: () => void; }
|
||||
>c : () => void
|
||||
>() => {} : () => void
|
||||
}
|
||||
|
||||
// error
|
||||
x1.a.b.c && x2.a.b.c();
|
||||
>x1.a.b.c && x2.a.b.c() : void
|
||||
>x1.a.b.c : () => void
|
||||
>x1.a.b : { c: () => void; }
|
||||
>x1.a : { b: { c: () => void; }; }
|
||||
>x1 : { a: { b: { c: () => void; }; }; }
|
||||
>a : { b: { c: () => void; }; }
|
||||
>b : { c: () => void; }
|
||||
>c : () => void
|
||||
>x2.a.b.c() : void
|
||||
>x2.a.b.c : () => void
|
||||
>x2.a.b : { c: () => void; }
|
||||
>x2.a : { b: { c: () => void; }; }
|
||||
>x2 : { a: { b: { c: () => void; }; }; }
|
||||
>a : { b: { c: () => void; }; }
|
||||
>b : { c: () => void; }
|
||||
>c : () => void
|
||||
}
|
||||
|
||||
class Foo {
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
// @strictNullChecks: true
|
||||
// @lib: esnext,dom
|
||||
|
||||
declare class A {
|
||||
static from(): string;
|
||||
}
|
||||
|
||||
declare class B {
|
||||
static from(): string;
|
||||
}
|
||||
|
||||
function test(required1: () => boolean, required2: () => boolean, optional?: () => boolean) {
|
||||
// error
|
||||
required1 && console.log('required');
|
||||
@@ -29,6 +37,9 @@ function test(required1: () => boolean, required2: () => boolean, optional?: ()
|
||||
// ok
|
||||
required1 && required2 && required1() && required2();
|
||||
|
||||
// ok
|
||||
[].forEach((f: () => void) => f && f.apply(parent, []));
|
||||
|
||||
// error
|
||||
required1 && required2 && required1() && console.log('foo');
|
||||
}
|
||||
@@ -57,6 +68,20 @@ function checksPropertyAccess() {
|
||||
|
||||
// ok
|
||||
x.foo.bar && 1 && x.foo.bar();
|
||||
|
||||
// ok
|
||||
const y = A.from && (A.from as Function) !== B.from ? true : false;
|
||||
y;
|
||||
|
||||
const x1 = {
|
||||
a: { b: { c: () => {} } }
|
||||
}
|
||||
const x2 = {
|
||||
a: { b: { c: () => {} } }
|
||||
}
|
||||
|
||||
// error
|
||||
x1.a.b.c && x2.a.b.c();
|
||||
}
|
||||
|
||||
class Foo {
|
||||
|
||||
Reference in New Issue
Block a user