Skip to content

Commit e17d915

Browse files
authored
Merge branch 'main' into port/import-defer
2 parents 2c010fc + ed2d8c9 commit e17d915

File tree

6 files changed

+86
-153
lines changed

6 files changed

+86
-153
lines changed

internal/checker/checker.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12410,17 +12410,32 @@ func (c *Checker) checkNullishCoalesceOperands(left *ast.Node, right *ast.Node)
1241012410
if ast.IsBinaryExpression(right) && ast.IsLogicalBinaryOperator(right.AsBinaryExpression().OperatorToken.Kind) {
1241112411
c.grammarErrorOnNode(right, diagnostics.X_0_and_1_operations_cannot_be_mixed_without_parentheses, scanner.TokenToString(right.AsBinaryExpression().OperatorToken.Kind), scanner.TokenToString(ast.KindQuestionQuestionToken))
1241212412
}
12413+
c.checkNullishCoalesceOperandLeft(left)
12414+
c.checkNullishCoalesceOperandRight(right)
12415+
}
12416+
12417+
func (c *Checker) checkNullishCoalesceOperandLeft(left *ast.Node) {
1241312418
leftTarget := ast.SkipOuterExpressions(left, ast.OEKAll)
1241412419
nullishSemantics := c.getSyntacticNullishnessSemantics(leftTarget)
1241512420
if nullishSemantics != PredicateSemanticsSometimes {
12416-
if left.Parent.Parent.Kind == ast.KindBinaryExpression {
12417-
c.error(leftTarget, diagnostics.This_binary_expression_is_never_nullish_Are_you_missing_parentheses)
12421+
if nullishSemantics == PredicateSemanticsAlways {
12422+
c.error(leftTarget, diagnostics.This_expression_is_always_nullish)
1241812423
} else {
12419-
if nullishSemantics == PredicateSemanticsAlways {
12420-
c.error(leftTarget, diagnostics.This_expression_is_always_nullish)
12421-
} else {
12422-
c.error(leftTarget, diagnostics.Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish)
12423-
}
12424+
c.error(leftTarget, diagnostics.Right_operand_of_is_unreachable_because_the_left_operand_is_never_nullish)
12425+
}
12426+
}
12427+
}
12428+
12429+
func (c *Checker) checkNullishCoalesceOperandRight(right *ast.Node) {
12430+
binaryExpression := right.Parent
12431+
if binaryExpression.Parent != nil && ast.IsBinaryExpression(binaryExpression.Parent) && binaryExpression.Parent.AsBinaryExpression().OperatorToken.Kind == ast.KindQuestionQuestionToken {
12432+
rightTarget := ast.SkipOuterExpressions(right, ast.OEKAll)
12433+
nullishSemantics := c.getSyntacticNullishnessSemantics(rightTarget)
12434+
switch nullishSemantics {
12435+
case PredicateSemanticsAlways:
12436+
c.error(rightTarget, diagnostics.This_expression_is_always_nullish)
12437+
case PredicateSemanticsNever:
12438+
c.error(rightTarget, diagnostics.This_expression_is_never_nullish)
1242412439
}
1242512440
}
1242612441
}

internal/parser/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4340,6 +4340,7 @@ func (p *Parser) parseArrowFunctionExpressionBody(isAsync bool, allowReturnTypeI
43404340
}
43414341
saveContextFlags := p.contextFlags
43424342
p.setContextFlags(ast.NodeFlagsAwaitContext, isAsync)
4343+
p.setContextFlags(ast.NodeFlagsYieldContext, false)
43434344
node := p.parseAssignmentExpressionOrHigherWorker(allowReturnTypeInArrowFunction)
43444345
p.contextFlags = saveContextFlags
43454346
return node

testdata/baselines/reference/submodule/compiler/predicateSemantics.errors.txt

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,27 @@ predicateSemantics.ts(28,13): error TS2871: This expression is always nullish.
66
predicateSemantics.ts(29,13): error TS2871: This expression is always nullish.
77
predicateSemantics.ts(30,13): error TS2872: This kind of expression is always truthy.
88
predicateSemantics.ts(31,13): error TS2872: This kind of expression is always truthy.
9-
predicateSemantics.ts(32,13): error TS2870: This binary expression is never nullish. Are you missing parentheses?
10-
predicateSemantics.ts(33,13): error TS2870: This binary expression is never nullish. Are you missing parentheses?
11-
predicateSemantics.ts(34,13): error TS2870: This binary expression is never nullish. Are you missing parentheses?
9+
predicateSemantics.ts(32,13): error TS2871: This expression is always nullish.
10+
predicateSemantics.ts(32,21): error TS2871: This expression is always nullish.
11+
predicateSemantics.ts(33,13): error TS2871: This expression is always nullish.
12+
predicateSemantics.ts(34,13): error TS2871: This expression is always nullish.
13+
predicateSemantics.ts(34,22): error TS2871: This expression is always nullish.
14+
predicateSemantics.ts(36,20): error TS2871: This expression is always nullish.
15+
predicateSemantics.ts(37,20): error TS2871: This expression is always nullish.
1216
predicateSemantics.ts(38,21): error TS2871: This expression is always nullish.
1317
predicateSemantics.ts(39,21): error TS2871: This expression is always nullish.
14-
predicateSemantics.ts(40,21): error TS2870: This binary expression is never nullish. Are you missing parentheses?
15-
predicateSemantics.ts(45,13): error TS2870: This binary expression is never nullish. Are you missing parentheses?
16-
predicateSemantics.ts(46,13): error TS2870: This binary expression is never nullish. Are you missing parentheses?
17-
predicateSemantics.ts(47,13): error TS2870: This binary expression is never nullish. Are you missing parentheses?
18+
predicateSemantics.ts(40,21): error TS2871: This expression is always nullish.
19+
predicateSemantics.ts(40,29): error TS2871: This expression is always nullish.
20+
predicateSemantics.ts(41,21): error TS2871: This expression is always nullish.
21+
predicateSemantics.ts(42,20): error TS2881: This expression is never nullish.
22+
predicateSemantics.ts(43,21): error TS2881: This expression is never nullish.
23+
predicateSemantics.ts(45,13): error TS2871: This expression is always nullish.
24+
predicateSemantics.ts(45,21): error TS2871: This expression is always nullish.
25+
predicateSemantics.ts(45,29): error TS2871: This expression is always nullish.
26+
predicateSemantics.ts(46,13): error TS2871: This expression is always nullish.
27+
predicateSemantics.ts(46,21): error TS2881: This expression is never nullish.
28+
predicateSemantics.ts(47,13): error TS2871: This expression is always nullish.
29+
predicateSemantics.ts(47,22): error TS2881: This expression is never nullish.
1830
predicateSemantics.ts(50,8): error TS2872: This kind of expression is always truthy.
1931
predicateSemantics.ts(51,11): error TS2872: This kind of expression is always truthy.
2032
predicateSemantics.ts(52,8): error TS2872: This kind of expression is always truthy.
@@ -26,7 +38,7 @@ predicateSemantics.ts(89,1): error TS2869: Right operand of ?? is unreachable be
2638
predicateSemantics.ts(90,1): error TS2869: Right operand of ?? is unreachable because the left operand is never nullish.
2739

2840

29-
==== predicateSemantics.ts (26 errors) ====
41+
==== predicateSemantics.ts (38 errors) ====
3042
declare let opt: number | undefined;
3143

3244
// OK: One or other operand is possibly nullish
@@ -76,16 +88,24 @@ predicateSemantics.ts(90,1): error TS2869: Right operand of ?? is unreachable be
7688
!!! error TS2872: This kind of expression is always truthy.
7789
const p07 = null ?? null ?? null;
7890
~~~~
79-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
91+
!!! error TS2871: This expression is always nullish.
92+
~~~~
93+
!!! error TS2871: This expression is always nullish.
8094
const p08 = null ?? opt ?? null;
8195
~~~~
82-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
96+
!!! error TS2871: This expression is always nullish.
8397
const p09 = null ?? (opt ? null : undefined) ?? null;
8498
~~~~
85-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
99+
!!! error TS2871: This expression is always nullish.
100+
~~~~~~~~~~~~~~~~~~~~~~
101+
!!! error TS2871: This expression is always nullish.
86102

87103
const p10 = opt ?? null ?? 1;
104+
~~~~
105+
!!! error TS2871: This expression is always nullish.
88106
const p11 = opt ?? null ?? null;
107+
~~~~
108+
!!! error TS2871: This expression is always nullish.
89109
const p12 = opt ?? (null ?? 1);
90110
~~~~
91111
!!! error TS2871: This expression is always nullish.
@@ -94,20 +114,36 @@ predicateSemantics.ts(90,1): error TS2869: Right operand of ?? is unreachable be
94114
!!! error TS2871: This expression is always nullish.
95115
const p14 = opt ?? (null ?? null ?? null);
96116
~~~~
97-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
117+
!!! error TS2871: This expression is always nullish.
118+
~~~~
119+
!!! error TS2871: This expression is always nullish.
98120
const p15 = opt ?? (opt ? null : undefined) ?? null;
121+
~~~~~~~~~~~~~~~~~~~~~~
122+
!!! error TS2871: This expression is always nullish.
99123
const p16 = opt ?? 1 ?? 2;
124+
~
125+
!!! error TS2881: This expression is never nullish.
100126
const p17 = opt ?? (opt ? 1 : 2) ?? 3;
127+
~~~~~~~~~~~
128+
!!! error TS2881: This expression is never nullish.
101129

102130
const p21 = null ?? null ?? null ?? null;
103131
~~~~
104-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
132+
!!! error TS2871: This expression is always nullish.
133+
~~~~
134+
!!! error TS2871: This expression is always nullish.
135+
~~~~
136+
!!! error TS2871: This expression is always nullish.
105137
const p22 = null ?? 1 ?? 1;
106138
~~~~
107-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
139+
!!! error TS2871: This expression is always nullish.
140+
~
141+
!!! error TS2881: This expression is never nullish.
108142
const p23 = null ?? (opt ? 1 : 2) ?? 1;
109143
~~~~
110-
!!! error TS2870: This binary expression is never nullish. Are you missing parentheses?
144+
!!! error TS2871: This expression is always nullish.
145+
~~~~~~~~~~~
146+
!!! error TS2881: This expression is never nullish.
111147

112148
// Outer expression tests
113149
while ({} as any) { }

testdata/baselines/reference/submodule/compiler/predicateSemantics.errors.txt.diff

Lines changed: 0 additions & 115 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
YieldExpression20_es6.ts(3,8): error TS1163: A 'yield' expression is only allowed in a generator body.
2+
3+
4+
==== YieldExpression20_es6.ts (1 errors) ====
5+
function* test() {
6+
return () => ({
7+
b: yield 2, // error
8+
~~~~~
9+
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
10+
});
11+
}
12+

testdata/baselines/reference/submodule/conformance/YieldExpression20_es6.errors.txt.diff

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)