Skip to content

Commit 538ffd8

Browse files
committed
fix missing error
1 parent 85937ab commit 538ffd8

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/compiler/checker.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40441,8 +40441,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4044140441
grammarErrorOnNode(left, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(SyntaxKind.QuestionQuestionToken), tokenToString(operatorToken.kind));
4044240442
}
4044340443
}
40444-
else if (isBinaryExpression(node.left) && node.left.operatorToken.kind === SyntaxKind.BarBarToken) {
40445-
grammarErrorOnNode(node.left, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(node.left.operatorToken.kind), tokenToString(SyntaxKind.QuestionQuestionToken));
40444+
else if (isBinaryExpression(node.left)) {
40445+
const { operatorToken } = node.left;
40446+
if (operatorToken.kind === SyntaxKind.BarBarToken || operatorToken.kind === SyntaxKind.AmpersandAmpersandToken) {
40447+
grammarErrorOnNode(node.left, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(operatorToken.kind), tokenToString(SyntaxKind.QuestionQuestionToken));
40448+
}
4044640449
}
4044740450
else if (isBinaryExpression(node.right) && node.right.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken) {
4044840451
grammarErrorOnNode(node.right, Diagnostics._0_and_1_operations_cannot_be_mixed_without_parentheses, tokenToString(SyntaxKind.QuestionQuestionToken), tokenToString(node.right.operatorToken.kind));

tests/baselines/reference/nullishCoalescingOperator5.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
nullishCoalescingOperator5.ts(6,1): error TS5076: '??' and '||' operations cannot be mixed without parentheses.
22
nullishCoalescingOperator5.ts(9,1): error TS5076: '||' and '??' operations cannot be mixed without parentheses.
33
nullishCoalescingOperator5.ts(12,6): error TS5076: '??' and '&&' operations cannot be mixed without parentheses.
4+
nullishCoalescingOperator5.ts(15,1): error TS5076: '&&' and '??' operations cannot be mixed without parentheses.
45

56

6-
==== nullishCoalescingOperator5.ts (3 errors) ====
7+
==== nullishCoalescingOperator5.ts (4 errors) ====
78
declare const a: string | undefined
89
declare const b: string | undefined
910
declare const c: string | undefined
@@ -25,6 +26,8 @@ nullishCoalescingOperator5.ts(12,6): error TS5076: '??' and '&&' operations cann
2526

2627
// should be a syntax error
2728
a && b ?? c;
29+
~~~~~~
30+
!!! error TS5076: '&&' and '??' operations cannot be mixed without parentheses.
2831

2932
// Valid according to spec
3033
a ?? (b || c);

0 commit comments

Comments
 (0)