Skip to content

Commit 7e1ff30

Browse files
authored
fix: Fix compiler crash when certain operators used on types #3 (#2309)
1 parent 96599c6 commit 7e1ff30

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

src/compiler.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6134,8 +6134,13 @@ export class Compiler extends DiagnosticEmitter {
61346134
], valueExpression);
61356135
}
61366136
}
6137+
default: {
6138+
this.error(
6139+
DiagnosticCode.The_target_of_an_assignment_must_be_a_variable_or_a_property_access,
6140+
valueExpression.range
6141+
);
6142+
}
61376143
}
6138-
assert(false);
61396144
return module.unreachable();
61406145
}
61416146

@@ -9322,9 +9327,6 @@ export class Compiler extends DiagnosticEmitter {
93229327
Constraints.NONE
93239328
);
93249329

9325-
// shortcut if compiling the getter already failed
9326-
if (getExpressionId(getValue) == ExpressionId.Unreachable) return getValue;
9327-
93289330
// if the value isn't dropped, a temp. local is required to remember the original value,
93299331
// except if a static overload is found, which reverses the use of a temp. (see below)
93309332
var tempLocal: Local | null = null;

tests/compiler/unary-errors.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"asc_flags": [
3+
],
4+
"stderr": [
5+
"AS234: Expression does not compile to a value at runtime.",
6+
"const a = (Foo++);",
7+
"TS2541: The target of an assignment must be a variable or a property access.",
8+
"const a = (Foo++);",
9+
"AS234: Expression does not compile to a value at runtime.",
10+
"const b = (++Foo);",
11+
"TS2541: The target of an assignment must be a variable or a property access.",
12+
"const b = (++Foo);",
13+
"AS234: Expression does not compile to a value at runtime.",
14+
"const d = (Foo--);",
15+
"TS2541: The target of an assignment must be a variable or a property access.",
16+
"const d = (Foo--);",
17+
"AS234: Expression does not compile to a value at runtime.",
18+
"const e = (--Foo);",
19+
"TS2541: The target of an assignment must be a variable or a property access.",
20+
"const e = (--Foo);",
21+
"AS234: Expression does not compile to a value at runtime.",
22+
"const g = (Bar++);",
23+
"TS2541: The target of an assignment must be a variable or a property access.",
24+
"const g = (Bar++);",
25+
"AS234: Expression does not compile to a value at runtime.",
26+
"const h = (++Bar);",
27+
"TS2541: The target of an assignment must be a variable or a property access.",
28+
"const h = (++Bar);",
29+
"AS234: Expression does not compile to a value at runtime.",
30+
"const j = (Bar--);",
31+
"TS2541: The target of an assignment must be a variable or a property access.",
32+
"const j = (Bar--);",
33+
"AS234: Expression does not compile to a value at runtime.",
34+
"const k = (--Bar);",
35+
"TS2541: The target of an assignment must be a variable or a property access.",
36+
"const k = (--Bar);",
37+
"AS102: User-defined: \"EOF\"",
38+
"ERROR(\"EOF\");"
39+
]
40+
}

tests/compiler/unary-errors.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint-disable no-class-assign */
2+
/* eslint-disable no-global-assign */
3+
4+
class Foo {}
5+
namespace Bar {}
6+
7+
const a = (Foo++);
8+
const b = (++Foo);
9+
// const c = (Foo += 1);
10+
11+
const d = (Foo--);
12+
const e = (--Foo);
13+
// const f = (Foo -= 1);
14+
15+
const g = (Bar++);
16+
const h = (++Bar);
17+
// const i = (Bar += 1);
18+
19+
const j = (Bar--);
20+
const k = (--Bar);
21+
// const l = (Bar -= 1);
22+
23+
ERROR("EOF");

0 commit comments

Comments
 (0)