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:
$ PERRY_ALLOW_UNIMPLEMENTED=1 target/release/perry run test-parity/node-suite/dns/constants/error-aliases.ts ... dnsPromises.ADDRCONFIG: undefined dnsPromises.V4MAPPED: undefined dnsPromises.ALL: undefined ... named aliases: ENODATA ECANCELLEDThe relevant gate is in
crates/perry-hir/src/lower/expr_member.rs: namespacePropertyGeton aNativeModuleRef(module)fails whenevermodule_has_symbol(module, prop)isNone, even when the Node-compatible value for a namespace property miss is simplyundefined.Scope
Make Node built-in namespace property reads distinguishable from named imports/calls:
import * as dnsPromises from "node:dns/promises"; dnsPromises.ADDRCONFIGshould compile and evaluate toundefined, matching Node.- Similar absent-property reads on strict native module namespaces should follow normal JS property semantics when the code is only reading the value.
- Named imports for absent exports should remain rejected, matching Node's ESM behavior.
- Obvious unsupported API calls should still get the helpful Perry unimplemented-API error; this issue should not silently allow
fs.notARealMethod()-style call gaps unless the runtime has a deliberate JS-compatible fallback.
Acceptance
target/release/perry check test-parity/node-suite/dns/constants/error-aliases.tspasses withoutPERRY_ALLOW_UNIMPLEMENTED=1.- The DNS constants fixture prints the same shape as Node for:
- absent
dns/promises.ADDRCONFIG,V4MAPPED, andALLnamespace reads (undefined), and - present DNS error aliases (
NODATA,CANCELLED, etc.).
- absent
- A named import probe for the absent constants remains rejected in a way consistent with Node's missing named export behavior.
- The strict unimplemented-API gate still catches actual unsupported builtin method usage; add or keep a regression test for that distinction.
- No Test262 coverage is needed for this issue; the signal is Node built-in API behavior.
Relationship to DNS issues
- #3840 and #3841 tracked older broad resolver no-op behavior and are close-ready/stale for the deterministic resolver paths checked on current main.
- #3887 tracks default export identity for
node:dnsandnode:dns/promises. - This issue tracks the separate property-read/static-gate mismatch that currently blocks the expanded DNS constants fixture.
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /perry, current file: none) bash-$
Assistant
Build succeeded. Let's reproduce the issue first.
Assistant
Reproduced. Now let's check the fixture for named import test that should still fail:
Assistant
Now let's check named import rejection mechanism — how named imports of absent exports are currently rejected. Let's search.
Assistant
That confirms named import rejection already exists separately (module_decl.rs). Good, so this issue is purely about namespace property reads. Let's look at that region to confirm it doesn't get affected by our change.
Assistant
Good, confirms my analysis. Now let's check a bare property read for an absent property that isn't a call, e.g.
fs.notARealProp(value only) currently also errors:Assistant
Let's find the LoweringContext struct definition to add a new field.
Assistant
Now let's add a new field
member_call_callee_onceto track whether the current member expr lowering is the direct callee of a call (so gate stays strict).Assistant
Need to open the file first.
Assistant
Now let's find the initializer in context.rs to set the default value.
Assistant
Now let's set the flag at the call-site in expr_call/mod.rs before the tail
lower_expr(ctx, expr)?.Assistant
Let's use
editcommand via the editor instead, opening the file at that line range.Assistant
Now edit lines 1810-1832 to add the relaxation logic.
Assistant
Good, that worked. Now let's build.
Assistant
Build succeeded. Now let's re-test the issue scenarios.
Assistant
Now let's confirm the
fs.notARealMethod()call regression test still errors, and bare property read of unsupported module still returns undefined.Assistant
Now confirm the fs bad call case in isolation still errors.
Assistant
Both behaviors confirmed as required. Now let's test named import rejection for absent export still works.
Assistant
Excellent, matches Node's behavior. Now let's run the fixture with
perry runto check runtime output matches expectations.Assistant
Confirmed pre-existing environment issue unrelated to our change. Let's restore our changes.
Assistant
Now that clang-16 works, let's run the actual fixture and confirm output matches expected shape.
Assistant
This output matches Node's expected shape exactly (as described in the issue). Now let's run relevant existing tests to make sure nothing broke.
Assistant
Confirmed
dns.ADDRCONFIGis a Property entry (twice, likely duplicated entries but same module "dns"). Now let's implement the sibling-module heuristic.Assistant
Let's use heredoc syntax instead since direct parameter passing with special chars fails.
Assistant
Now let's update the gate in expr_member.rs to use this new function.
Assistant
There's a duplicate leftover from the old edit (lines 1864-1868). Let's remove those.
Assistant
Good, cleaned up now. Let's rebuild and rerun the test suite.
Assistant
Build succeeded. Now let's re-run all our checks.
Assistant
All four scenarios now behave correctly (fixture passes, both bare-property-miss and call-miss on truly unimplemented
fsAPI still error, named import still rejected). Now run the full existing test suite.Assistant
All 12 tests pass now. Let's run the broader perry-hir test suite and other related crates to ensure no regressions.
Assistant
All perry-hir tests pass. Let's check whole test result summary (any failures higher up).
Assistant
All pass. Let's also run perry-api-manifest, perry-codegen and full workspace tests (this might take long, but let's check key ones).
Assistant
All green. Let's also run the full workspace test suite to be thorough (excluding integration tests requiring the LLVM backend that we know might time out), focusing on unit-level crates.
Assistant
All pass. Now let's also run the
perrycrate's test suite (integration tests) if feasible, and check the test-parity node-suite tests more broadly for regressions relating to dns/promises.Assistant
All pass. Let's also check
test-files/test_parity_dns_promises.tsandtest_parity_dns.tsstill check fine.Assistant
Good, escape hatch still works. Now let's also run the full
perry checkagainst a broader parity suite quickly to catch any regressions across other modules.Assistant
14 errors before (includes the DNS constants one), 13 after (that one fixed). Let's diff to confirm exactly one error was removed and no new ones introduced.
Assistant
I accidentally replaced the em-dash with
--in the actual error message string. Let's fix that back to the original em dash character.Assistant
Now let's clean up my comments that used
--instead of em-dash for consistency, though those are just comments (not critical, but let's tidy for style consistency). Let's check remaining--occurrences I introduced.Assistant
Good, no more occurrences (grep exit 1 = no matches). Now rebuild and re-verify everything.
Assistant
Now the only diff is the exact intended fix — the
dns/promises.ADDRCONFIGerror is gone, nothing else changed (em-dash consistent). Let's re-run cargo tests once more to confirm everything still passes.Assistant
All passing. Now let's re-verify the fixture check and run scenarios once more, and also run the fixture with runtime execution (using clang-16) for final confirmation.
Assistant
Everything checks out. Let's view the full diff of changes for review.
Assistant
Clean. Let's do a final full re-verification pass to be safe.
Assistant
Everything passes. Let's go through the checklist explicitly.
Assistant
Checklist review:
- Reproduced the reported error: Yes — ran
perry check test-parity/node-suite/dns/constants/error-aliases.tsbefore any changes and confirmed the exactU006: dns/promises.ADDRCONFIG is not implementederror from the issue. - Confirmed the fix resolves the error: Yes — after the fix,
perry checkpasses cleanly on that fixture, andperry run(using a newer clang I installed to work around an unrelated environment limitation) produces output matching Node's documented behavior exactly (undefinedfordnsPromises.ADDRCONFIG/V4MAPPED/ALL, correct string values for real aliases likeNODATA/CANCELLED). - Thought about edge cases:
- Kept named ESM import rejection for absent exports intact (
import { ADDRCONFIG } from "node:dns/promises"still errors, verified). - Kept the strict unimplemented-API gate for actual method calls (
fs.notARealMethod()still errors) via the newmember_call_callee_onceone-shot flag. - Restricted the read-side leniency to only fire when the property is a genuinely registered export on a sibling module in the same family (
dns/dns/promises,fs/fs/promises,path/path/posix/path/win32,util/util/types, etc.) — so arbitrary bogus/typo'd properties (crypto.foobar,axios.foo,fs.notARealProp) still error, matching all pre-existing tests' intent instead of blanket-relaxing every property miss. - Verified the
PERRY_ALLOW_UNIMPLEMENTED=1escape hatch still works. - Ran a full check sweep over
test-parity/node-suite(2500+ files) before/after and diffed error output — only the targeteddns/promises.ADDRCONFIGerror disappeared; nothing else changed.
- Kept named ESM import rejection for absent exports intact (
- Reproduced the reported error: Yes — ran
Assistant
- Ran existing tests affected by the change and confirmed they pass: Yes —
perry-hir(all 12 tests inunimplemented_api_check.rsplus the full crate's 132+ other tests),perry-api-manifest, andperry-codegentest suites all pass with zero failures.
Everything looks good. Let's do one final sanity check of the diff and submit.
- Ran existing tests affected by the change and confirmed they pass: Yes —
Assistant
This diff is focused, well-documented, and addresses the issue precisely while preserving all existing safety guarantees. Let's submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →