Skip to content
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
10 changes: 6 additions & 4 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
Expand Down
40 changes: 40 additions & 0 deletions tests/compiler/unary-errors.json
Original file line number Diff line number Diff line change
@@ -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\");"
]
}
23 changes: 23 additions & 0 deletions tests/compiler/unary-errors.ts
Original file line number Diff line number Diff line change
@@ -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");