From 38337fe41cedc96e5d64e2063083c2e19b36d3c5 Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 6 Jun 2022 20:24:04 -0500 Subject: [PATCH 1/5] fix --- src/compiler.ts | 10 ++-- tests/compiler/increment-error.json | 72 +++++++++++++++++++++++++++++ tests/compiler/increment-error.ts | 38 +++++++++++++++ 3 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 tests/compiler/increment-error.json create mode 100644 tests/compiler/increment-error.ts 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/increment-error.json b/tests/compiler/increment-error.json new file mode 100644 index 0000000000..6337e70c65 --- /dev/null +++ b/tests/compiler/increment-error.json @@ -0,0 +1,72 @@ +{ + "asc_flags": [ + ], + "stderr": [ + "AS234: Expression does not compile to a value at runtime.", + "Foo++;", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "Foo++;", + "AS234: Expression does not compile to a value at runtime.", + "++Foo;", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "++Foo;", + "AS234: Expression does not compile to a value at runtime.", + "Foo--;", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "Foo--;", + "AS234: Expression does not compile to a value at runtime.", + "--Foo;", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "--Foo;", + "AS234: Expression does not compile to a value at runtime.", + "Array++;", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "Array++;", + "AS234: Expression does not compile to a value at runtime.", + "++Array;", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "++Array;", + "AS234: Expression does not compile to a value at runtime.", + "Array--;", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "Array--;", + "AS234: Expression does not compile to a value at runtime.", + "--Array;", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "--Array;", + "AS234: Expression does not compile to a value at runtime.", + "const a = (Foo++);", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "const a = (Foo++);", + "AS234: Expression does not compile to a value at runtime.", + "const b = (++Foo);", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "const b = (++Foo);", + "AS234: Expression does not compile to a value at runtime.", + "const d = (Foo--);", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "const d = (Foo--);", + "AS234: Expression does not compile to a value at runtime.", + "const e = (--Foo);", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "const e = (--Foo);", + "AS234: Expression does not compile to a value at runtime.", + "const g = (Array++);", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "const g = (Array++);", + "AS234: Expression does not compile to a value at runtime.", + "const h = (++Array);", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "const h = (++Array);", + "AS234: Expression does not compile to a value at runtime.", + "const j = (Array--);", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "const j = (Array--);", + "AS234: Expression does not compile to a value at runtime.", + "const k = (--Array);", + "TS2322: Type 'i32' is not assignable to type 'void'.", + "const k = (--Array);", + "AS102: User-defined: \"EOF\"", + "ERROR(\"EOF\");" + ] +} diff --git a/tests/compiler/increment-error.ts b/tests/compiler/increment-error.ts new file mode 100644 index 0000000000..a1d3951054 --- /dev/null +++ b/tests/compiler/increment-error.ts @@ -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"); \ No newline at end of file From 9dcac576124f1b04a33055fcb894f279c5094123 Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 6 Jun 2022 20:37:12 -0500 Subject: [PATCH 2/5] forgot to build --- src/compiler.ts | 2 ++ tests/compiler/increment-error.json | 32 ++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 03b61615fa..fa6f78d051 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9246,6 +9246,8 @@ export class Compiler extends DiagnosticEmitter { Constraints.NONE ); + trace("hi"); + // 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/increment-error.json b/tests/compiler/increment-error.json index 6337e70c65..c0f5a5ba54 100644 --- a/tests/compiler/increment-error.json +++ b/tests/compiler/increment-error.json @@ -4,67 +4,67 @@ "stderr": [ "AS234: Expression does not compile to a value at runtime.", "Foo++;", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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;", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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--;", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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;", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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++;", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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;", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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--;", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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;", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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++);", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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);", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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--);", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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);", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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++);", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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);", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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--);", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "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);", - "TS2322: Type 'i32' is not assignable to type 'void'.", + "TS2541: The target of an assignment must be a variable or a property access.", "const k = (--Array);", "AS102: User-defined: \"EOF\"", "ERROR(\"EOF\");" From b8c272ebdfcc74b7ba3858ed3f0ced48d07a1cdc Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 6 Jun 2022 20:39:38 -0500 Subject: [PATCH 3/5] remove debugging --- src/compiler.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index fa6f78d051..03b61615fa 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -9246,8 +9246,6 @@ export class Compiler extends DiagnosticEmitter { Constraints.NONE ); - trace("hi"); - // 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; From 6aa9629f4caf105f1b6f856afc06abde5f6c6a5d Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Mon, 27 Jun 2022 11:37:26 -0500 Subject: [PATCH 4/5] rename test --- tests/compiler/{increment-error.json => unary-errors.json} | 0 tests/compiler/{increment-error.ts => unary-errors.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/compiler/{increment-error.json => unary-errors.json} (100%) rename tests/compiler/{increment-error.ts => unary-errors.ts} (100%) diff --git a/tests/compiler/increment-error.json b/tests/compiler/unary-errors.json similarity index 100% rename from tests/compiler/increment-error.json rename to tests/compiler/unary-errors.json diff --git a/tests/compiler/increment-error.ts b/tests/compiler/unary-errors.ts similarity index 100% rename from tests/compiler/increment-error.ts rename to tests/compiler/unary-errors.ts From a4f36e901dbcb5a8d03cb607491ed5d195054260 Mon Sep 17 00:00:00 2001 From: romdotdog <70765447+romdotdog@users.noreply.github.com> Date: Thu, 30 Jun 2022 11:43:38 -0500 Subject: [PATCH 5/5] update test --- tests/compiler/unary-errors.json | 48 ++++++-------------------------- tests/compiler/unary-errors.ts | 29 +++++-------------- 2 files changed, 15 insertions(+), 62 deletions(-) diff --git a/tests/compiler/unary-errors.json b/tests/compiler/unary-errors.json index c0f5a5ba54..a855e5c66a 100644 --- a/tests/compiler/unary-errors.json +++ b/tests/compiler/unary-errors.json @@ -2,38 +2,6 @@ "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.", @@ -51,21 +19,21 @@ "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++);", + "const g = (Bar++);", "TS2541: The target of an assignment must be a variable or a property access.", - "const g = (Array++);", + "const g = (Bar++);", "AS234: Expression does not compile to a value at runtime.", - "const h = (++Array);", + "const h = (++Bar);", "TS2541: The target of an assignment must be a variable or a property access.", - "const h = (++Array);", + "const h = (++Bar);", "AS234: Expression does not compile to a value at runtime.", - "const j = (Array--);", + "const j = (Bar--);", "TS2541: The target of an assignment must be a variable or a property access.", - "const j = (Array--);", + "const j = (Bar--);", "AS234: Expression does not compile to a value at runtime.", - "const k = (--Array);", + "const k = (--Bar);", "TS2541: The target of an assignment must be a variable or a property access.", - "const k = (--Array);", + "const k = (--Bar);", "AS102: User-defined: \"EOF\"", "ERROR(\"EOF\");" ] diff --git a/tests/compiler/unary-errors.ts b/tests/compiler/unary-errors.ts index a1d3951054..4e42d032a7 100644 --- a/tests/compiler/unary-errors.ts +++ b/tests/compiler/unary-errors.ts @@ -2,22 +2,7 @@ /* eslint-disable no-global-assign */ class Foo {} - -Foo++; -++Foo; -// Foo += 1; - -Foo--; ---Foo; -// Foo -= 1; - -Array++; -++Array; -// Array += 1; - -Array--; ---Array; -// Array -= 1; +namespace Bar {} const a = (Foo++); const b = (++Foo); @@ -27,12 +12,12 @@ const d = (Foo--); const e = (--Foo); // const f = (Foo -= 1); -const g = (Array++); -const h = (++Array); -// const i = (Array += 1); +const g = (Bar++); +const h = (++Bar); +// const i = (Bar += 1); -const j = (Array--); -const k = (--Array); -// const l = (Array -= 1); +const j = (Bar--); +const k = (--Bar); +// const l = (Bar -= 1); ERROR("EOF"); \ No newline at end of file