Skip to content
Open
Show file tree
Hide file tree
Changes from all 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: 8 additions & 2 deletions packages/compiler/src/frontend/lowering/lower-containers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5956,10 +5956,16 @@ const DV_SETTERS: Record<string, { method: IrBytesIntrinsicMethod; le: boolean }
return { kind: "libCall", fn: "buffer.fromStr", args: [s, enc], type: BYTES_U8, loc };
}
if (args.length === 1 && srcIr?.kind === "bytes" && srcIr.elem === "u8") {
return { kind: "bytesNew", source: L.lowerExpr(argNode), type: BYTES_U8, loc };
const source = L.lowerExpr(argNode);
if (source.type.kind === "bytes" && source.type.elem === "u8") {
return { kind: "bytesNew", source, type: BYTES_U8, loc };
}
}
if (args.length === 1 && srcIr?.kind === "array" && srcIr.elem.kind === "f64") {
return { kind: "bytesNew", source: L.lowerExpr(argNode), type: BYTES_U8, loc };
const source = L.lowerExpr(argNode);
if (source.type.kind === "array" && source.type.elem.kind === "f64") {
return { kind: "bytesNew", source, type: BYTES_U8, loc };
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/compiler/test/ts7/baselines/order-parity.json
Original file line number Diff line number Diff line change
Expand Up @@ -6483,6 +6483,12 @@
],
"diags": []
},
"<repo>/tests/diagnostics/buffer-from-island/main.ts": {
"order": [
"<repo>/tests/diagnostics/buffer-from-island/main.ts"
],
"diags": []
},
"<repo>/tests/diagnostics/catch-bindings.ts": {
"order": [
"<repo>/tests/diagnostics/catch-bindings.ts"
Expand Down
7 changes: 7 additions & 0 deletions tests/diagnostics/buffer-from-island/main.ts
Original file line number Diff line number Diff line change
@@ -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;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/harness/__snapshots__/buffer-from-island/main.ts.txt
Original file line number Diff line number Diff line change
@@ -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)