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
Now let's add the new field. Let's find a good spot near these flags.
Assistant
Now let's add the new flag field after
unresolved_ident_as_global.Assistant
Now update the constructor in context.rs.
Assistant
Good, only one constructor site. Now let's set this flag in expr_call/mod.rs around the fallback callee lowering.
Assistant
Now let's do the edit using line ranges instead of replace-search (since the file is open, direct edit should work fine).
Assistant
Now let's build the crate.
Assistant
It installed. Now let's build.
Assistant
Compiles fine (just pre-existing warnings). Now let's build the full perry binary and test with the fixture.
Assistant
Build succeeded. Now let's find the fixture mentioned in the issue.
Assistant
Now let's run the check command as in the issue.
Assistant
The check now passes. Now let's run to compare output with Node.
Assistant
Network access works. Let's try installing clang-16 via LLVM apt repo or check available.
Assistant
clang-16 is available. Let's install it and point PERRY_LLVM_CLANG at it.
Assistant
It works now. Let's run the DNS fixture with this env var.
Assistant
This matches Node's expected output exactly (undefined for the 3 absent constants, and NODATA/CANCELLED etc. present). Now let's verify that named import of an absent export still gets rejected.
Assistant
Named import remains rejected. Now let's confirm the "obvious unsupported API call" case still triggers the strict error.
Assistant
Good, the call-form still correctly rejects. Now let's test plain property read on
fs(non-call) with an absent property to confirm it becomesundefinedtoo, and test a value read used as a call target indirectly (edge case).Assistant
Matches Node semantics (bare property read of unknown module member → undefined). Now let's test the "read stored then called" edge case — assign to variable, then call — should probably still throw at runtime like Node (calling undefined throws TypeError), not a compile-time error, since it's an indirect call.
Assistant
This is a plain read (not a call), so it now compiles as
undefined, matching Node's dynamic-call-not-required semantics (the resultingf()would only throw if actually invoked, exactly like real JS). Good, this is consistent behavior. Let's clean up temp files.Assistant
Now update the gate check to use
is_call_callee_hereinstead ofctx.lowering_call_callee.Assistant
Now let's re-run all the tests to make sure everything still works correctly.
Assistant
All the expected behaviors hold. Let's run to check the actual runtime output for t3 (chained call on undefined without optional chaining, to confirm it throws like Node).
Assistant
Now let's add the new helper function right after
module_has_any_entries.Assistant
Now let's update the gate in expr_member.rs to use this instead of the general fallback.
Assistant
Now let's rewrite this block to use the narrow allowlist instead of the blanket bypass.
Assistant
Now let's rebuild and rerun the test suite.
Assistant
All 12 tests pass now. Let's rebuild the binary and re-verify the fixture + edge cases.
Assistant
Matches Node exactly. Now let's re-verify the named-import rejection and call-form rejection edge cases again with the new build.
Assistant
Both remain correctly rejected. Let's also test that calling
dnsPromises.ADDRCONFIG()(calling one of the newly-allowed constants) still triggers the strict error since it's a call.Assistant
Correctly rejected. Now let's run the full perry-hir test suite to look for any broader regressions.
Assistant
All perry-hir tests pass. Let's also run perry-codegen and perry-api-manifest test suites, since I touched perry-api-manifest too.
Assistant
All pass. Let's run the
perrycrate's own tests too (which may include integration tests referencing check/run behaviors).Assistant
All 426 tests pass. Let's clean up temporary test files and directories.
Assistant
Let's remove the stray build artifacts left in the repo root.
Assistant
Now let's review the full diff for correctness/style.
Assistant
This is a pre-existing platform-specific limitation unrelated to our change (macOS-only
objc2crate can't build on Linux). Our targeted crates (perry,perry-hir,perry-codegen,perry-api-manifest) all build and test cleanly. Let's do a final review of the whole diff and re-run the exact acceptance command once more.Assistant
Now let's also check other DNS-related test-parity fixtures still pass to make sure nothing else broke there.
Assistant
All good. Let's do a broader sanity sweep across
test-parity/node-suiteto be extra safe against regressions.Assistant
This confirms the baseline (before our fix) already had 14 pre-existing errors, including the
dns/promises.ADDRCONFIGone from our issue. Let's restore our change and compare.Assistant
The only difference across the entire
test-parity/node-suitefixture set is that thedns/promises.ADDRCONFIGerror is gone — exactly the fix intended, with zero collateral changes to any other fixture.Assistant
Let's run the full targeted crate test suites one final time to be certain everything is green after the last rebuild.
Assistant
All green. Let's do a final
git diffreview and clean any stray files.Assistant
Clean. Now let's go through the checklist explicitly.
Assistant
Checklist review:
- I have successfully reproduced the reported error: Yes — built
perryfrom the unmodified repo and confirmedperry check test-parity/node-suite/dns/constants/error-aliases.tsfailed witherror[U006]: dns/promises.ADDRCONFIG is not implemented in Perryexactly as described in the issue.
- I have successfully reproduced the reported error: Yes — built
Assistant
Everything checks out. Let me summarize the checklist before submitting:
- Reproduced the reported error: Confirmed — before the fix,
perry check test-parity/node-suite/dns/constants/error-aliases.tsfailed witherror[U006]: dns/promises.ADDRCONFIG is not implemented in Perry, matching the issue exactly. - Confirmed my fix resolves the error:
perry checknow passes withoutPERRY_ALLOW_UNIMPLEMENTED=1, and on the fixture (using a working clang-16 toolchain to work around an unrelated environment gap) prints output identical in shape to Node's: for //, and correct string values for the DNS error aliases.
- Reproduced the reported error: Confirmed — before the fix,
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.