From fd2dbb02df6724cfa02fb009cb94e1195cf230e0 Mon Sep 17 00:00:00 2001 From: Andrew Morris Date: Thu, 22 Jun 2023 17:57:46 +1000 Subject: [PATCH] Update test --- .../copyCounting/subscriptAssignment.ts | 16 ------------ .../copyCounting/subscriptAssignment.ts | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 16 deletions(-) delete mode 100644 inputs/failing/copyCounting/subscriptAssignment.ts create mode 100644 inputs/passing/copyCounting/subscriptAssignment.ts diff --git a/inputs/failing/copyCounting/subscriptAssignment.ts b/inputs/failing/copyCounting/subscriptAssignment.ts deleted file mode 100644 index 51d731d..0000000 --- a/inputs/failing/copyCounting/subscriptAssignment.ts +++ /dev/null @@ -1,16 +0,0 @@ -//! test_output(3) -// Should be: 2 - -/// - -export default function main() { - const x = Debug.makeCopyCounter("x"); - - let obj: Record = { x }; // First copy - obj.y = "y"; // No extra copy - - let arr: unknown[] = [x]; // Second copy - arr[1] = "y"; // No extra copy - - return x.count; -} diff --git a/inputs/passing/copyCounting/subscriptAssignment.ts b/inputs/passing/copyCounting/subscriptAssignment.ts new file mode 100644 index 0000000..50f3b3e --- /dev/null +++ b/inputs/passing/copyCounting/subscriptAssignment.ts @@ -0,0 +1,25 @@ +//! test_output(0) + +/// + +export default function main() { + return measure(true) - measure(false); +} + +function measure(assign: boolean) { + const x = Debug.makeCopyCounter("x"); + + let obj: Record = { x }; + + if (assign) { + obj.y = "y"; + } + + let arr: unknown[] = [x]; + + if (assign) { + arr[1] = "y"; + } + + return x.count; +}