From c959443a8054b80d47909825f87a4da52a363965 Mon Sep 17 00:00:00 2001 From: Malte Ubl Date: Tue, 27 Oct 2026 19:34:46 -0700 Subject: [PATCH] Exercise the unary island-call fix from the corpus program The corpus case passed `new Swapper(tricky)` straight to `+`, which the argument check already treated as effectful, so it never distinguished the two lowerings. Bind the swapper to a local: an identifier is what the old check called inert, and the program now prints "replaced replaced" without the fix and matches Node with it. The class also used a parameter property, which Node's strip-only mode rejects. Co-Authored-By: Claude 5.5 --- tests/corpus/6816-node-island-objects/main.ts | 17 ++++++++++++++--- .../node_modules/islandkit/index.d.ts | 2 +- .../node_modules/islandkit/index.js | 5 ++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/tests/corpus/6816-node-island-objects/main.ts b/tests/corpus/6816-node-island-objects/main.ts index 7a2724f8c..002613b33 100644 --- a/tests/corpus/6816-node-island-objects/main.ts +++ b/tests/corpus/6816-node-island-objects/main.ts @@ -3,7 +3,7 @@ // require() specifier) runs in a Node island: its objects cross as // handles, so the same object returned twice is ===, and writes through // one reference are visible through every other, on both sides. -import { Store, createStore, describe, VERSION, makePoint, addPoints, ping, makeTricky } from "islandkit"; +import { Store, createStore, describe, VERSION, makePoint, addPoints, ping, makeTricky, type Tricky } from "islandkit"; import * as kit from "islandkit"; console.log(VERSION); @@ -35,10 +35,21 @@ console.log(p.x, p.y); p.x = 100; console.log(p.x + p.y); -// JavaScript reads `tricky.method` before it evaluates `+tricky`, whose +// JavaScript reads `tricky.method` before it evaluates `+swapper`, whose // valueOf replaces the method: the call must reach the original. +class Swapper { + target: Tricky; + constructor(target: Tricky) { + this.target = target; + } + valueOf(): number { + this.target.method = this.target.other; + return 1; + } +} const tricky = makeTricky(); -console.log("unary", tricky.method(+tricky), tricky.method(1)); +const swapper = new Swapper(tricky); +console.log("unary", tricky.method(+swapper), tricky.method(1)); console.log(ping(), ping(), kit.ping()); diff --git a/tests/corpus/6816-node-island-objects/node_modules/islandkit/index.d.ts b/tests/corpus/6816-node-island-objects/node_modules/islandkit/index.d.ts index 360f0f783..7f1e9cf1c 100644 --- a/tests/corpus/6816-node-island-objects/node_modules/islandkit/index.d.ts +++ b/tests/corpus/6816-node-island-objects/node_modules/islandkit/index.d.ts @@ -26,6 +26,6 @@ export declare let loads: number; export declare function ping(): number; export interface Tricky { method(value: number): string; - valueOf(): number; + other(): string; } export declare function makeTricky(): Tricky; diff --git a/tests/corpus/6816-node-island-objects/node_modules/islandkit/index.js b/tests/corpus/6816-node-island-objects/node_modules/islandkit/index.js index 09334ef4d..613181936 100644 --- a/tests/corpus/6816-node-island-objects/node_modules/islandkit/index.js +++ b/tests/corpus/6816-node-island-objects/node_modules/islandkit/index.js @@ -20,8 +20,7 @@ exports.makeTricky = () => ({ method() { return "original"; }, - valueOf() { - this.method = () => "replaced"; - return 1; + other() { + return "replaced"; }, });