Node API checker: namespace reads of absent builtin exports should return undefined…
- User
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:
console - Assistant
I'll trace how namespace property reads are gated in the HIR lowerer and compare that to the DNS constants fixture so we can allow absent reads to compile to
undefinedwithout weakening named-import or call checks. - Assistant
The gate likely belongs on calls, not property reads — I'll trace
expr_calland see how absent namespace members are handled at runtime. - Assistant
Removing the property-read gate in
expr_member.rsand updating tests so absent namespace reads compile while call-site checks stay strict. - Assistant
The call gate isn't firing for some modules — I'll trace how
crypto.foobar()is lowered inexpr_call. - Assistant
Handled modules skip the call gate — I'll add manifest checks for those modules in
expr_callso bogus calls still error while property reads stay allowed. - Assistant
I'll add a shared gate helper and apply it on the path submodule path when dispatch doesn't match.
- Assistant
Namespace property reads on built-in modules now follow Node’s property-miss semantics, while unsupported method calls still hit the strict API gate.
Changes
1.
crates/perry-hir/src/lower/expr_member.rsRemoved the #463 gate on namespace property reads. Reads like
dnsPromises.ADDRCONFIGcompile and evaluate to at runtime when the export isn’t on the namespace object — matching Node.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.