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 its call/import validation paths, reproduce the reported check failure, then make the smallest change that permits only value reads while preserving unsupported-call diagnostics and named-import validation. I’ll run focused tests plus the fixture and inspect the diff before submitting.
- Assistant
The first inspection confirms this is a Rust lowering path with special handling for process namespaces.
rgis unavailable, so I’ll usegrepand inspect the rest oflower_member_inner, then locate the exact gate and native-module metadata APIs. - Assistant
The architecture already has call-time gates for both
module.method()and chainedmodule.Namespace.method(), while named-import validation occurs during import lowering. Therefore the incorrect behavior is specifically the standalone member-read gate. I’ll remove only that read-time refusal, leaving thePropertyGetruntime path intact (it already yieldsundefinedfor missing native properties) and preserving all call-time checks. - Assistant
The focused test exposed an important edge: several builtins (
fs,path,crypto,os, etc.) use specialized call dispatch that bypasses the existing generic call gate. I’ll add the same strict check at the start of native namespace call dispatch, restricted to namespace bindings (lookup_native_module(...).1 == None), so unknown reads remain valid but unknown calls still fail uniformly. - Assistant
The updated focused suite now shows all call-form rejection checks passing; only the old read-form tests fail, as expected because they assert the behavior this issue changes.
cargo check -p perry-hirsucceeds. I’ll now build/run the CLI against the DNS fixture and a temporary named-import probe, then review the final diff. - Assistant
The fixture check passes, the absent named import is still rejected with the expected diagnostic, and focused regression tests for unsupported calls and named imports pass. Runtime execution reached an environment-only clang 14/opaque-pointer incompatibility after lowering, so it could not execute; the check path verified the relevant lowering behavior. I’ll do one final diff review and submit.
- Assistant
Implemented the namespace property-read compatibility fix.
Changes:
- Removed the strict unimplemented-API rejection from native namespace value reads in
expr_member.rs.- Missing properties now lower to the existing runtime
PropertyGetbehavior, producingundefined. - Named ESM imports remain validated and rejected when absent.
- Missing properties now lower to the existing runtime
- Added strict call-time validation in native module dispatch for specialized modules such as
fs,path,crypto, andos.- Unsupported method calls continue to produce the Perry unimplemented-API error.
PERRY_ALLOW_UNIMPLEMENTED=1remains respected.
Verification:
- DNS fixture check passes without
PERRY_ALLOW_UNIMPLEMENTED.
- Removed the strict unimplemented-API rejection from native namespace value reads in
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.