diff --git a/src/compiler.ts b/src/compiler.ts index d9dd2df4cc..03b61615fa 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -6053,8 +6053,13 @@ export class Compiler extends DiagnosticEmitter { ], valueExpression); } } + default: { + this.error( + DiagnosticCode.The_target_of_an_assignment_must_be_a_variable_or_a_property_access, + valueExpression.range + ); + } } - assert(false); return module.unreachable(); } @@ -9241,9 +9246,6 @@ export class Compiler extends DiagnosticEmitter { Constraints.NONE ); - // shortcut if compiling the getter already failed - if (getExpressionId(getValue) == ExpressionId.Unreachable) return getValue; - // if the value isn't dropped, a temp. local is required to remember the original value, // except if a static overload is found, which reverses the use of a temp. (see below) var tempLocal: Local | null = null; diff --git a/tests/compiler/unary-errors.json b/tests/compiler/unary-errors.json new file mode 100644 index 0000000000..a855e5c66a --- /dev/null +++ b/tests/compiler/unary-errors.json @@ -0,0 +1,40 @@ +{ + "asc_flags": [ + ], + "stderr": [ + "AS234: Expression does not compile to a value at runtime.", + "const a = (Foo++);", + "TS2541: The target of an assignment must be a variable or a property access.", + "const a = (Foo++);", + "AS234: Expression does not compile to a value at runtime.", + "const b = (++Foo);", + "TS2541: The target of an assignment must be a variable or a property access.", + "const b = (++Foo);", + "AS234: Expression does not compile to a value at runtime.", + "const d = (Foo--);", + "TS2541: The target of an assignment must be a variable or a property access.", + "const d = (Foo--);", + "AS234: Expression does not compile to a value at runtime.", + "const e = (--Foo);", + "TS2541: The target of an assignment must be a variable or a property access.", + "const e = (--Foo);", + "AS234: Expression does not compile to a value at runtime.", + "const g = (Bar++);", + "TS2541: The target of an assignment must be a variable or a property access.", + "const g = (Bar++);", + "AS234: Expression does not compile to a value at runtime.", + "const h = (++Bar);", + "TS2541: The target of an assignment must be a variable or a property access.", + "const h = (++Bar);", + "AS234: Expression does not compile to a value at runtime.", + "const j = (Bar--);", + "TS2541: The target of an assignment must be a variable or a property access.", + "const j = (Bar--);", + "AS234: Expression does not compile to a value at runtime.", + "const k = (--Bar);", + "TS2541: The target of an assignment must be a variable or a property access.", + "const k = (--Bar);", + "AS102: User-defined: \"EOF\"", + "ERROR(\"EOF\");" + ] +} diff --git a/tests/compiler/unary-errors.ts b/tests/compiler/unary-errors.ts new file mode 100644 index 0000000000..4e42d032a7 --- /dev/null +++ b/tests/compiler/unary-errors.ts @@ -0,0 +1,23 @@ +/* eslint-disable no-class-assign */ +/* eslint-disable no-global-assign */ + +class Foo {} +namespace Bar {} + +const a = (Foo++); +const b = (++Foo); +// const c = (Foo += 1); + +const d = (Foo--); +const e = (--Foo); +// const f = (Foo -= 1); + +const g = (Bar++); +const h = (++Bar); +// const i = (Bar += 1); + +const j = (Bar--); +const k = (--Bar); +// const l = (Bar -= 1); + +ERROR("EOF"); \ No newline at end of file