opencode/packages/codemode-rust/conformance/cases/lang-data-guards.js
kommander bcb2ddf1b9 fix(codemode): guard opaque operands and word iteration errors like the reference
Operators reject promises and tool references as the reference does
(Binary/Unary operators require data values, '++' requires a data
value), reading or adding a property a promise lacks reports it as
un-awaited, and for...in over a promise throws. A value that is not
iterable reports where it was iterated: for...of and for await...of as
an invalid data value naming it, destructuring, spread and yield* with
their own messages.

An opened iterator keeps the next method it had, as iterator records do,
and spread, rest and Object.assign copy the confined symbol keys.

call() returns packed words, so short callbacks no longer stall on the
reload of a two-word Value.
2026-11-18 18:56:10 +01:00

68 lines
1.1 KiB
JavaScript

const t = (f) => {
try {
return f()
} catch (e) {
return [e.name, e.message]
}
}
let p = Promise.resolve(1)
const g = (function* () {})()
const fn = () => 1
return [
t(() => p == 1),
t(() => p == p),
t(() => p != null),
t(() => p === p),
t(() => p < 1),
t(() => p + 1),
t(() => p * 2),
t(() => -p),
t(() => +p),
t(() => ~p),
t(() => {
let q = p
q++
return q
}),
t(() => {
let q = p
q -= 1
return q
}),
t(() => `${p}`),
t(() => String(p)),
t(() => typeof p.then),
t(() => p.foo),
t(() => p[0]),
t(() => {
p.x = 1
}),
t(() => {
const q = Promise.resolve(2)
q.then = 5
return typeof q.then
}),
t(() => "x" in p),
t(() => g + 1),
t(() => fn + ""),
t(() => tools.echo + 1),
t(() => {
for (const k in p) return k
}),
t(() => {
for (const x of { a: 1 }) return x
}),
t(() => {
for (const x of 5) return x
}),
t(() => {
for (const x of fn) return x
}),
t(() => {
const [a] = {}
return a
}),
t(() => [...{}]),
t(() => Math.max(...{})),
t(() => [...(function* () { yield* {} })()]),
]