Skip to content

Commit 583a933

Browse files
committed
[v2] fix object destructure with number literal props — coerce i64 prop type to f64 since dynobj_get returns f64
1 parent 6abe863 commit 583a933

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/hir/lower-destructure.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ export function lowerObjectDestructuring(d: any, mutable: boolean): HIRStmt[] {
138138

139139
for (const { fieldName, localName, span } of resolveObjectDestructProps(d.id.properties)) {
140140
const propInfo = props.find((p) => p.name === fieldName);
141-
const propType = propInfo ? propInfo.type : DYNOBJ;
141+
let propType = propInfo ? propInfo.type : DYNOBJ;
142+
if (propType.kind === "i64") propType = F64;
142143
const elemId = freshId();
143144
const key: HIRExpr = { kind: "literal_string", value: fieldName, type: I8PTR };
144145
const fieldGet = dynObjGetForType(

src/hir/lower.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ export function lowerModule(
440440

441441
for (const { fieldName, localName } of resolveObjectDestructProps(d.id.properties)) {
442442
const propInfo = props.find((p) => p.name === fieldName);
443-
const propType = propInfo ? propInfo.type : DYNOBJ;
443+
let propType = propInfo ? propInfo.type : DYNOBJ;
444+
if (propType.kind === "i64") propType = F64;
444445
const key: HIRExpr = { kind: "literal_string", value: fieldName, type: I8PTR };
445446
const fieldGet = dynObjGetForType(
446447
{ kind: "global_get", name: tmpName, type: initExpr.type },
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const o = { x: 1, y: 2, z: 100 };
2+
const { x, y, z } = o;
3+
console.log(x);
4+
console.log(y);
5+
console.log(z);
6+
console.log(x + y + z);

0 commit comments

Comments
 (0)