ISSUE DESCRIPTION Node API checker: namespace reads of absent builtin exports should…
- User
ISSUE DESCRIPTION
Node API checker: namespace reads of absent builtin exports should return undefined
Summary
Perry's strict built-in API gate currently rejects some namespace property reads that Node treats as ordinary JavaScript property misses returning
undefined.This surfaced in the curated DNS constants fixture on current
origin/main@22824ba90abf:node:dns/promisesintentionally does not exportADDRCONFIG,V4MAPPED, orALL, but reading those properties from the namespace object is valid in Node and returnsundefined. Perry rejects the property read at check/lower time before the runtime can produce the matching value.This is separate from named ESM import validation. Node rejects
import { ADDRCONFIG } from "node:dns/promises", and Perry should continue not claiming that named export. The compatibility gap is namespace/property-read semantics.Local evidence
Current main:
22824ba90abf Expose globalThis.EventTarget (#3628)Node v25.9.0 behavior for the namespace object:
$ node -e 'import("node:dns/promises").then(m=>{for (const k of ["ADDRCONFIG","V4MAPPED","ALL","NODATA","CANCELLED"]){console.log(k, Object.prototype.hasOwnProperty.call(m,k), k in m, typeof m[k], m[k]);}})' ADDRCONFIG false false undefined undefined V4MAPPED false false undefined undefined ALL false false undefined undefined NODATA true true string ENODATA CANCELLED true true string ECANCELLEDNode rejects the corresponding named import, which is correct and should remain true:
$ node --input-type=module -e 'import { ADDRCONFIG } from "node:dns/promises"; console.log(ADDRCONFIG)' SyntaxError: The requested module 'node:dns/promises' does not provide an export named 'ADDRCONFIG'Perry currently rejects the namespace property read in the curated fixture:
$ target/release/perry check test-parity/node-suite/dns/constants/error-aliases.ts error[U006]: `dns/promises.ADDRCONFIG` is not implemented in Perry — see `perry --print-api-manifest` for the supported surface, or set `PERRY_ALLOW_UNIMPLEMENTED=1` to ignore. (#463) --> test-parity/node-suite/dns/constants/error-aliases.ts:9:48The manifest matches Node for named exports:
dns/promisesincludes DNS error aliases likeNODATAandCANCELLED, but does not includeADDRCONFIG,V4MAPPED, orALL.With the gate bypassed, Perry's runtime output matches Node for this fixture, including the absent namespace properties:
- Assistant
I’ll trace the member-expression lowering and the separate import/call checks, reproduce the reported failure, then make the narrowest change so only value reads of strict native namespaces fall through to runtime
undefined. I’ll run focused checks and relevant tests, inspect the diff, and submit only after verifying the distinction remains intact. - Assistant
The repository lacks
rg, so I’ll usegrep. The shown lowering already has several special cases; I’m locating the native-module branch and call lowering to ensure the fix does not weaken method-call diagnostics. - Assistant
The named-import validator already rejects absent Node core exports during import lowering, so that behavior is preserved independently. The member gate currently skips named-import values but not namespace bindings. I’ll add the analogous namespace-binding exemption; the existing native-module call gate still validates
namespace.missing()by method name, so property reads and calls remain distinct. - Assistant
The source change is in place, but the environment has no configured Rust toolchain, so Cargo cannot run. I’ll still validate the logic through repository inspection and, if an existing built binary is available elsewhere, run the reported fixture. I’m also checking whether namespace aliases can be wrapped by casts and whether the call path independently gates unsupported methods.
- Assistant
The focused source audit confirms:
module_declvalidates named Node-core imports withmodule_has_public_named_export, so absent named imports still fail.- Namespace bindings are recorded as
(module, None), and the new exemption recognizes direct identifiers and transparent TS casts. - The native-module call lowering independently checks
module_has_symbol, sofs.notARealMethod()-style calls remain rejected. git diff --checkpasses. Cargo/rustfmt execution is blocked solely because rustup has no installed/default toolchain, and no prebuilttarget/release/perryexists to run the fixture.
I’ll now submit the verified change.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.