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:
text22824ba90abf Expose globalThis.EventTarget (#3628)Node v25.9.0 behavior for the namespace object:
console$ 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:
console$ 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:
Assistant
Good, so named import rejection already exists separately in
module_decl.rs. Now let's look at that gate more closely and understand how to distinguish "property read" vs "call" inexpr_member.rsandexpr_call.rs.Assistant
Good, this confirms named import validation is separate and already correct. Now let's reproduce the issue with the test fixture.
Assistant
Let's build first and reproduce the error.
Assistant
Build succeeded. Now let's reproduce.
Assistant
Reproduced. Now let's look at the gate logic and figure out how to distinguish a mere property-read from a call.
Assistant
Now let's add the new function. Let's view end of file for a good place.
Assistant
I'll add the new function right after
module_has_symbolsince it's a close cousin.Assistant
Now update
pub uselist inlib.rs? Let's check exports.Assistant
Good, it's a top-level pub fn, no need for explicit re-export since it's not in a submodule. Now let's update
expr_member.rsgate.Assistant
Now let's check the call-site gate too (native_module.rs) — although calls to these constants wouldn't happen since they're not functions, but let's check if there is a similar 3-deep gate for
mod.X.Yshape that might also need updating for consistency (not required by issue but let's check nested_namespace.rs too, not necessary here). Let's rebuild and test.Assistant
Now let's run it and compare with node output.
Assistant
All existing tests pass. Now let's run full perry-hir test suite and perry-api-manifest.
Assistant
All perry-hir tests pass. Now run perry-api-manifest tests.
Assistant
All tests pass. Now let's also double check the codegen consistency test (manifest_consistency.rs mentioned in comments) and run the full test suite for perry-codegen quickly for safety.
Assistant
All good. Now let's write a temporary regression test-style script to check the specific issue scenario more thoroughly, then remove it (per instructions, not to add to test suite but to validate manually).
Assistant
Let me fix the borrow errors quickly.
Assistant
All 6 cases behave exactly as expected. Let's remove the temporary example file now.
Assistant
Good, clean diff with only two files modified. Let's view the final diff.
Assistant
Already confirmed working via reproduction test (error message showed
dns/promises.__totally_bogus_prop__meaning module="dns/promises" without node: prefix). Good, consistent with strip_prefix pattern anyway. Now let's also confirm the fixture end-to-end again and diff against previous PERRY_ALLOW_UNIMPLEMENTED output to ensure identical HIR-level behavior (values same).Assistant
Let's also verify no other tests reference
dns/promisesfixture elsewhere (e.g. parity harness) that might need updates.Assistant
That's gitignored cache, not part of tracked changes. Good. Now let's run the broader test suite for perry-codegen and perry crate to be safe (may take a while, but let's do targeted ones related to member/property gating).
Assistant
All perry-hir tests pass. Let's also run perry-api-manifest tests once more (already done) and perry-codegen full test suite quickly.
Assistant
All tests pass. Let's clean up the temp files and finalize.
Assistant
Final diff review before submission.
Assistant
This is a minimal, targeted fix. Now going through the checklist:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.