From a3dd28e923d59ed9afe0e9b17d215d8ce121f1a9 Mon Sep 17 00:00:00 2001 From: yearthmain Date: Tue, 4 Aug 2026 11:58:57 +0800 Subject: [PATCH] fix: guard Buffer.from island arguments before bytesNew --- .../src/frontend/lowering/lower-containers.ts | 10 ++++++++-- .../test/ts7/baselines/order-parity.json | 6 ++++++ tests/diagnostics/buffer-from-island/main.ts | 7 +++++++ .../node_modules/bytekit/index.d.ts | 2 ++ .../node_modules/bytekit/index.js | 9 +++++++++ .../node_modules/bytekit/package.json | 6 ++++++ .../buffer-from-island/main.ts.txt | 17 +++++++++++++++++ 7 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tests/diagnostics/buffer-from-island/main.ts create mode 100644 tests/diagnostics/buffer-from-island/node_modules/bytekit/index.d.ts create mode 100644 tests/diagnostics/buffer-from-island/node_modules/bytekit/index.js create mode 100644 tests/diagnostics/buffer-from-island/node_modules/bytekit/package.json create mode 100644 tests/harness/__snapshots__/buffer-from-island/main.ts.txt diff --git a/packages/compiler/src/frontend/lowering/lower-containers.ts b/packages/compiler/src/frontend/lowering/lower-containers.ts index da557647..b53b3a7c 100644 --- a/packages/compiler/src/frontend/lowering/lower-containers.ts +++ b/packages/compiler/src/frontend/lowering/lower-containers.ts @@ -5956,10 +5956,16 @@ const DV_SETTERS: Record/tests/diagnostics/buffer-from-island/main.ts": { + "order": [ + "/tests/diagnostics/buffer-from-island/main.ts" + ], + "diags": [] + }, "/tests/diagnostics/catch-bindings.ts": { "order": [ "/tests/diagnostics/catch-bindings.ts" diff --git a/tests/diagnostics/buffer-from-island/main.ts b/tests/diagnostics/buffer-from-island/main.ts new file mode 100644 index 00000000..4a359c0f --- /dev/null +++ b/tests/diagnostics/buffer-from-island/main.ts @@ -0,0 +1,7 @@ +// @dynamic +// A package call keeps its value in the island even when its declaration +// promises a supported container. Buffer.from must fence that boundary. +import { bytes, numbers } from "bytekit"; +Buffer.from(bytes()); +Buffer.from(numbers()); +void 0; diff --git a/tests/diagnostics/buffer-from-island/node_modules/bytekit/index.d.ts b/tests/diagnostics/buffer-from-island/node_modules/bytekit/index.d.ts new file mode 100644 index 00000000..13fbbabe --- /dev/null +++ b/tests/diagnostics/buffer-from-island/node_modules/bytekit/index.d.ts @@ -0,0 +1,2 @@ +export declare function bytes(): Uint8Array; +export declare function numbers(): number[]; diff --git a/tests/diagnostics/buffer-from-island/node_modules/bytekit/index.js b/tests/diagnostics/buffer-from-island/node_modules/bytekit/index.js new file mode 100644 index 00000000..5ce107f3 --- /dev/null +++ b/tests/diagnostics/buffer-from-island/node_modules/bytekit/index.js @@ -0,0 +1,9 @@ +"use strict"; + +exports.bytes = function bytes() { + return new Uint8Array([1, 2, 3]); +}; + +exports.numbers = function numbers() { + return [1, 2, 3]; +}; diff --git a/tests/diagnostics/buffer-from-island/node_modules/bytekit/package.json b/tests/diagnostics/buffer-from-island/node_modules/bytekit/package.json new file mode 100644 index 00000000..ccdfdf94 --- /dev/null +++ b/tests/diagnostics/buffer-from-island/node_modules/bytekit/package.json @@ -0,0 +1,6 @@ +{ + "name": "bytekit", + "version": "1.0.0", + "main": "index.js", + "types": "index.d.ts" +} diff --git a/tests/harness/__snapshots__/buffer-from-island/main.ts.txt b/tests/harness/__snapshots__/buffer-from-island/main.ts.txt new file mode 100644 index 00000000..eb386224 --- /dev/null +++ b/tests/harness/__snapshots__/buffer-from-island/main.ts.txt @@ -0,0 +1,17 @@ +buffer-from-island/main.ts:5:1 - error SC2020: 'Buffer.from with this argument shape' is part of the standard library types but has no scriptc lowering yet + + 4 | import { bytes, numbers } from "bytekit"; + 5 | Buffer.from(bytes()); + | ^~~~~~~~~~~~~~~~~~~~ + 6 | Buffer.from(numbers()); + + hint: supported: Buffer.from(string, encoding?) with a literal encoding, Buffer.from(u8Array) — a copy — Buffer.from(number[]), or Buffer.from(x.buffer, byteOffset?, length?) — a view sharing x's storage (no free-standing ArrayBuffer value exists; narrow unions first) + +buffer-from-island/main.ts:6:1 - error SC2020: 'Buffer.from with this argument shape' is part of the standard library types but has no scriptc lowering yet + + 5 | Buffer.from(bytes()); + 6 | Buffer.from(numbers()); + | ^~~~~~~~~~~~~~~~~~~~~~ + 7 | void 0; + + hint: supported: Buffer.from(string, encoding?) with a literal encoding, Buffer.from(u8Array) — a copy — Buffer.from(number[]), or Buffer.from(x.buffer, byteOffset?, length?) — a view sharing x's storage (no free-standing ArrayBuffer value exists; narrow unions first) \ No newline at end of file