Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix compiler crash when certain operators used on types #3 #2309

Merged
merged 5 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
72 changes: 72 additions & 0 deletions tests/compiler/increment-error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"asc_flags": [
],
"stderr": [
"AS234: Expression does not compile to a value at runtime.",
"Foo++;",
"TS2541: The target of an assignment must be a variable or a property access.",
"Foo++;",
"AS234: Expression does not compile to a value at runtime.",
"++Foo;",
"TS2541: The target of an assignment must be a variable or a property access.",
"++Foo;",
"AS234: Expression does not compile to a value at runtime.",
"Foo--;",
"TS2541: The target of an assignment must be a variable or a property access.",
"Foo--;",
"AS234: Expression does not compile to a value at runtime.",
"--Foo;",
"TS2541: The target of an assignment must be a variable or a property access.",
"--Foo;",
"AS234: Expression does not compile to a value at runtime.",
"Array++;",
"TS2541: The target of an assignment must be a variable or a property access.",
"Array++;",
"AS234: Expression does not compile to a value at runtime.",
"++Array;",
"TS2541: The target of an assignment must be a variable or a property access.",
"++Array;",
"AS234: Expression does not compile to a value at runtime.",
"Array--;",
"TS2541: The target of an assignment must be a variable or a property access.",
"Array--;",
"AS234: Expression does not compile to a value at runtime.",
"--Array;",
"TS2541: The target of an assignment must be a variable or a property access.",
"--Array;",
"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 = (Array++);",
"TS2541: The target of an assignment must be a variable or a property access.",
"const g = (Array++);",
"AS234: Expression does not compile to a value at runtime.",
"const h = (++Array);",
"TS2541: The target of an assignment must be a variable or a property access.",
"const h = (++Array);",
"AS234: Expression does not compile to a value at runtime.",
"const j = (Array--);",
"TS2541: The target of an assignment must be a variable or a property access.",
"const j = (Array--);",
"AS234: Expression does not compile to a value at runtime.",
"const k = (--Array);",
"TS2541: The target of an assignment must be a variable or a property access.",
"const k = (--Array);",
"AS102: User-defined: \"EOF\"",
"ERROR(\"EOF\");"
]
}
38 changes: 38 additions & 0 deletions tests/compiler/increment-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable no-class-assign */
/* eslint-disable no-global-assign */

class Foo {}

Foo++;
++Foo;
// Foo += 1;

Foo--;
--Foo;
// Foo -= 1;

Array++;
++Array;
// Array += 1;

Array--;
--Array;
// Array -= 1;

const a = (Foo++);
const b = (++Foo);
// const c = (Foo += 1);

const d = (Foo--);
const e = (--Foo);
// const f = (Foo -= 1);

const g = (Array++);
const h = (++Array);
// const i = (Array += 1);

const j = (Array--);
const k = (--Array);
// const l = (Array -= 1);

ERROR("EOF");
MaxGraey marked this conversation as resolved.
Show resolved Hide resolved