Skip to content

Commit

Permalink
Revert "Add check for delete expression must be optional (#37921)" (#…
Browse files Browse the repository at this point in the history
…38154)

This reverts commit 39beb1d.
  • Loading branch information
DanielRosenwasser committed Apr 24, 2020
1 parent 84c83da commit 1b8c68d
Show file tree
Hide file tree
Showing 14 changed files with 4 additions and 856 deletions.
15 changes: 2 additions & 13 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27682,23 +27682,12 @@ namespace ts {
}
const links = getNodeLinks(expr);
const symbol = getExportSymbolOfValueSymbolIfExported(links.resolvedSymbol);
if (symbol) {
if (isReadonlySymbol(symbol)) {
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
}

checkDeleteExpressionMustBeOptional(expr, getTypeOfSymbol(symbol));
if (symbol && isReadonlySymbol(symbol)) {
error(expr, Diagnostics.The_operand_of_a_delete_operator_cannot_be_a_read_only_property);
}
return booleanType;
}

function checkDeleteExpressionMustBeOptional(expr: AccessExpression, type: Type) {
const AnyOrUnknownOrNeverFlags = TypeFlags.AnyOrUnknown | TypeFlags.Never;
if (strictNullChecks && !(type.flags & AnyOrUnknownOrNeverFlags) && !(getFalsyFlags(type) & TypeFlags.Undefined)) {
error(expr, Diagnostics.The_operand_of_a_delete_operator_must_be_optional);
}
}

function checkTypeOfExpression(node: TypeOfExpression): Type {
checkExpression(node.expression);
return typeofType;
Expand Down
4 changes: 0 additions & 4 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2963,10 +2963,6 @@
"category": "Error",
"code": 2789
},
"The operand of a 'delete' operator must be optional.": {
"category": "Error",
"code": 2790
},

"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts(10,12): error TS2790: The operand of a 'delete' operator must be optional.
tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts(14,12): error TS2703: The operand of a 'delete' operator must be a property reference.


==== tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts (2 errors) ====
==== tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts (1 errors) ====
function f() {
let x: { a?: number | string, b: number | string } = { b: 1 };
x.a;
Expand All @@ -13,8 +12,6 @@ tests/cases/conformance/controlFlow/controlFlowDeleteOperator.ts(14,12): error T
x.b;
delete x.a;
delete x.b;
~~~
!!! error TS2790: The operand of a 'delete' operator must be optional.
x.a;
x.b;
x;
Expand Down
66 changes: 0 additions & 66 deletions tests/baselines/reference/deleteChain.errors.txt

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1b8c68d

Please sign in to comment.