diff --git a/internal/checker/checker.go b/internal/checker/checker.go index 74fbd0f01a..d35781ba8f 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -12264,7 +12264,9 @@ func (c *Checker) getSyntacticNullishnessSemantics(node *ast.Node) PredicateSema switch node.Kind { case ast.KindAwaitExpression, ast.KindCallExpression, + ast.KindTaggedTemplateExpression, ast.KindElementAccessExpression, + ast.KindMetaProperty, ast.KindNewExpression, ast.KindPropertyAccessExpression, ast.KindYieldExpression, @@ -12282,6 +12284,8 @@ func (c *Checker) getSyntacticNullishnessSemantics(node *ast.Node) PredicateSema ast.KindAmpersandAmpersandToken, ast.KindAmpersandAmpersandEqualsToken: return PredicateSemanticsSometimes + case ast.KindCommaToken: + return c.getSyntacticNullishnessSemantics(node.AsBinaryExpression().Right) } return PredicateSemanticsNever case ast.KindConditionalExpression: diff --git a/testdata/baselines/reference/submodule/compiler/predicateSemantics.errors.txt b/testdata/baselines/reference/submodule/compiler/predicateSemantics.errors.txt index 1b2f2291e4..c80dd47d19 100644 --- a/testdata/baselines/reference/submodule/compiler/predicateSemantics.errors.txt +++ b/testdata/baselines/reference/submodule/compiler/predicateSemantics.errors.txt @@ -9,17 +9,14 @@ predicateSemantics.ts(33,8): error TS2872: This kind of expression is always tru predicateSemantics.ts(34,11): error TS2872: This kind of expression is always truthy. predicateSemantics.ts(35,8): error TS2872: This kind of expression is always truthy. predicateSemantics.ts(36,8): error TS2872: This kind of expression is always truthy. -predicateSemantics.ts(50,14): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. predicateSemantics.ts(51,14): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. predicateSemantics.ts(52,14): error TS2695: Left side of comma operator is unused and has no side effects. predicateSemantics.ts(52,14): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. -predicateSemantics.ts(58,15): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. -predicateSemantics.ts(68,1): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. predicateSemantics.ts(70,1): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. predicateSemantics.ts(71,1): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. -==== predicateSemantics.ts (19 errors) ==== +==== predicateSemantics.ts (16 errors) ==== declare let cond: any; // OK: One or other operand is possibly nullish @@ -92,8 +89,6 @@ predicateSemantics.ts(71,1): error TS2869: Right operand of ?? is unreachable be const maybe = null as true | null; let i = 0; const d = (i++, maybe) ?? true; // ok - ~~~~~~~~~~ -!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. const e = (i++, i++) ?? true; // error ~~~~~~~~ !!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. @@ -108,8 +103,6 @@ predicateSemantics.ts(71,1): error TS2869: Right operand of ?? is unreachable be class X { constructor() { const p = new.target ?? 32; - ~~~~~~~~~~ -!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. } } @@ -120,8 +113,6 @@ predicateSemantics.ts(71,1): error TS2869: Right operand of ?? is unreachable be ): T | null; tag`foo${1}` ?? 32; // ok - ~~~~~~~~~~~~ -!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. `foo${1}` ?? 32; // error ~~~~~~~~~ diff --git a/testdata/baselines/reference/submodule/compiler/predicateSemantics.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/predicateSemantics.errors.txt.diff deleted file mode 100644 index 4bbaec851f..0000000000 --- a/testdata/baselines/reference/submodule/compiler/predicateSemantics.errors.txt.diff +++ /dev/null @@ -1,48 +0,0 @@ ---- old.predicateSemantics.errors.txt -+++ new.predicateSemantics.errors.txt -@@= skipped -8, +8 lines =@@ - predicateSemantics.ts(34,11): error TS2872: This kind of expression is always truthy. - predicateSemantics.ts(35,8): error TS2872: This kind of expression is always truthy. - predicateSemantics.ts(36,8): error TS2872: This kind of expression is always truthy. -+predicateSemantics.ts(50,14): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. - predicateSemantics.ts(51,14): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. - predicateSemantics.ts(52,14): error TS2695: Left side of comma operator is unused and has no side effects. - predicateSemantics.ts(52,14): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. -+predicateSemantics.ts(58,15): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. -+predicateSemantics.ts(68,1): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. - predicateSemantics.ts(70,1): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. - predicateSemantics.ts(71,1): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. - - --==== predicateSemantics.ts (16 errors) ==== -+==== predicateSemantics.ts (19 errors) ==== - declare let cond: any; - - // OK: One or other operand is possibly nullish -@@= skipped -80, +83 lines =@@ - const maybe = null as true | null; - let i = 0; - const d = (i++, maybe) ?? true; // ok -+ ~~~~~~~~~~ -+!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. - const e = (i++, i++) ?? true; // error - ~~~~~~~~ - !!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. -@@= skipped -14, +16 lines =@@ - class X { - constructor() { - const p = new.target ?? 32; -+ ~~~~~~~~~~ -+!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. - } - } - -@@= skipped -10, +12 lines =@@ - ): T | null; - - tag`foo${1}` ?? 32; // ok -+ ~~~~~~~~~~~~ -+!!! error TS2869: Right operand of ?? is unreachable because the left operand is never nullish. - - `foo${1}` ?? 32; // error - ~~~~~~~~~ \ No newline at end of file