Skip to content

Port getSyntacticNullishnessSemantics changes #1040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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.
}
}

Expand All @@ -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
~~~~~~~~~
Expand Down

This file was deleted.