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 start by exploring the repository structure and understanding the codebase, then locate the relevant files mentioned in the issue.
Assistant
Let me look at the specific part of this file that handles the namespace property access for native modules:
Assistant
I need to see the specific code around line 1813 where the
module_has_symbolcheck happens. Let me view that section more carefully.Assistant
Now I can see the issue. The code around line 1813 is checking if a property exists in the module's API manifest, and if it doesn't, it bails with an error. However, according to the issue, when reading a property from a namespace object that doesn't exist, Node just returns
undefined- it should only error for things like method calls or named imports.Let me look at the test file and understand the expected behavior:
Assistant
Let me first reproduce the error:
Assistant
Good, the build succeeded. Now let me reproduce the error:
Assistant
I've successfully reproduced the error. Now I understand the issue:
- The code in
expr_member.rsat line ~1813 checks if a property exists in the module's API manifest - When accessing
dnsPromises.ADDRCONFIG, this property doesn't exist in the manifest, so it errors - But in Node.js, reading a non-existent property from a namespace object returns
undefined
The fix should be: instead of bailing with an error for property reads of absent exports from native module namespaces, we should just emit the
PropertyGetexpression and let the runtime returnundefinedfor missing properties.Let me look more closely at the code structure to understand what the fix should be:
- The code in
Assistant
Now I understand the issue. The current gate rejects all property reads on native module namespaces when the symbol isn't in the manifest. However, according to the issue, property reads should be allowed (returning
undefined), and only method calls should be rejected.Let me check how calls are handled:
Assistant
My earlier search found the
expr_calldirectory with anative_module.rsfile. Let me look at that to understand how calls are handled vs property reads. )<tool_call> <function=bash_terminal> <parameter=command> cat /perry/crates/perry-hir/src/lower/expr_call/native_module.rs </tool_call>
Assistant
I need to run the bash command to view the file. Let me do that.
Assistant
Let me look at the exact structure of the file around the gate:
Assistant
Now I understand the issue. The problem is in the unimplemented-API gate in
expr_member.rsaround lines 1810-1830. Currently, it rejects all property reads on native module namespaces when the property is not in the manifest. However, according to the issue:- Property reads on namespace objects for absent exports should return
undefined(normal JavaScript behavior) - Method calls should still get the unimplemented-API error (handled separately in
native_module.rs)
The fix is to remove the error for namespace property reads - let them fall through to emit
PropertyGet, which will returnundefinedat runtime. The call gate innative_module.rswill still catch actual unsupported method calls.Let me implement this fix:
- Property reads on namespace objects for absent exports should return
Assistant
Let me look at the code structure more carefully and create a proper fix.
Assistant
Looking at the code, I can see the issue. The unimplemented-API gate in
expr_member.rsis rejecting namespace property reads for symbols not in the manifest. According to the issue, this should be allowed and returnundefinedat runtime. The gate should only fire for method calls (handled innative_module.rs).Let me check the exact line numbers:
Assistant
Now I understand the fix. The entire gate block (lines 1721-1831) should be removed, because namespace property reads should just return
undefinedwhen the symbol doesn't exist in the manifest. The call gate innative_module.rswill still catch actual unsupported method calls.Let me verify this is the right approach by looking at what happens after the gate:
Assistant
Good. After the gate, the code emits
Expr::PropertyGet { object, property }which is exactly what we want - this will be evaluated at runtime and returnundefinedfor missing properties.Now let me remove the gate block. The block starts at line 1721 and ends at line 1831.
Assistant
I need to delete lines 1721-1831 (the entire gate block). Let me count the exact lines:
Assistant
Now I understand the issue. The gate in
expr_member.rsblocks property reads on native module namespaces when the symbol isn't in the manifest. According to the issue, these should be allowed and returnundefinedat runtime (normal JavaScript behavior). Method calls should still get the error, but that's handled separately innative_module.rs.Let me remove the gate block (lines 1721-1832) from
expr_member.rs:Assistant
I need to delete lines 1721-1832 (the entire gate block). Let me use the edit command to replace this section:
Assistant
The block to remove is lines 1721-1832. After line 1832, line 1834 starts with
match &member.prop. Let me replace the entire gate block with an updated comment explaining the new behavior:Assistant
I need to continue by rebuilding the project and testing if the fix works. Let me build and test.
Now let me rebuild the project and test if the fix works:
Assistant
Good, the build succeeded. Now let me test if the fix works by running the check command on the test file:
Assistant
The check passes now. Let me also run the file to verify the runtime output matches Node's behavior:
Assistant
There's a LLVM/clang issue with the environment, but that's unrelated to my fix. The important thing is the
checkcommand passes now. Let me verify with thePERRY_ALLOW_UNIMPLEMENTED=1environment variable that was mentioned in the issue:Assistant
Now let me also verify that the named import rejection still works. The issue says named imports for absent exports should remain rejected. Let me create a test file:
Assistant
The named import rejection still works. Now let me also verify that unsupported method calls still get the unimplemented-API error. Let me create a test for that:
Assistant
...
Assistant
...
Assistant
The user is telling me that my previous response didn't contain a valid tool call. I need to continue testing to make sure the method call gate still works. Let me create a new test file and run the check command.
Assistant
Hmm, the method call test passed, which means it's not catching the unsupported method call. According to the issue, method calls should still be caught. Let me check the
native_module.rsgate and see what's happening:Assistant
The manifest might use a different format. Let me check what it outputs.
Assistant
The method call test passed, meaning it's not being caught by the gate. Let me check if
fsmodule has entries in the manifest.Wait, looking back at the issue - it says the method call gate is in
native_module.rs. Let me check if that gate is still working. The issue says: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.Let me check if the gate in native_module.rs is still there and working.
Assistant
Let me check the gate in
native_module.rsmore carefully to see if it's still catching unsupported method calls:Assistant
The method call gate is still in
native_module.rs. Let me check why it's not catchingfs.notARealMethod(). Looking at the code around line 1297:Assistant
You're right, there was an issue with my response format. Let me continue with the proper testing. Looking at the code in
native_module.rs, I can see thatfsis explicitly in theis_handled_modulelist (line 1282), which means calls tofsmethods bypass the unimplemented-API gate. The gate only applies to other modules. This is expected behavior -fs,crypto,os, etc. have their own specific handling in the LLVM backend.Let me verify that the main acceptance criteria is met and run the existing tests:
Assistant
You're right, I need to use proper tool calls. Let me continue testing by running the existing tests in the repository to make sure my fix doesn't break anything.
Assistant
I see the issue - my fix was too broad. The failing tests show that bogus member access should still be rejected. Let me look at what these tests are checking:
Assistant
The failing tests are checking that bogus member access on supported modules should be rejected. But my fix removed that check entirely. I need to re-read the issue more carefully.
Looking at the issue again:
- The problem is specifically about namespace property reads (like
dnsPromises.ADDRCONFIG) that should returnundefinedin Node - The issue says: "Obvious unsupported API calls should still get the helpful Perry unimplemented-API error"
- The issue distinguishes between property reads (should return undefined) and method calls (should error)
So the fix should:
- Allow namespace property reads to pass through (return undefined at runtime)
- Keep rejecting method calls on unsupported APIs
But the current code rejects both property reads AND method calls at the same gate. The method call rejection is handled separately in
native_module.rs.Wait, let me re-read the test output. The tests are about "bogus member access" and "bogus call". Let me look at the test file to understand what they're testing.
- The problem is specifically about namespace property reads (like
Assistant
Looking at the test failures, I see the issue. My fix removed the property read gate entirely, but the tests expect it to still reject bogus property reads. Let me re-read the issue more carefully.
The issue says:
- Namespace property reads should return
undefinedfor absent exports - Named imports should still be rejected
- Method calls should still get the unimplemented-API error
So the issue is specifically about distinguishing between property reads and method calls. The property read gate in
expr_member.rswas rejecting both. I need to only remove it for property reads, while keeping the call gate innative_module.rs.However, looking at the call gate in
native_module.rs, it only fires for modules NOT in theis_handled_modulelist. This means calls tocrypto,fs,os, etc. bypass the gate.Let me add the gate for handled modules as well:
- Namespace property reads should return
Assistant
I see the issue now. The handled modules (crypto, fs, os, etc.) bypass the unimplemented-API gate in
native_module.rs. I need to add the gate for these modules too. Let me look at how crypto calls are handled:Assistant
Looking at the test output more carefully, I see that my fix was too aggressive. The original code rejected ALL property reads on native modules that aren't in the manifest. But according to the issue, the problem is specifically about namespace property reads of absent exports - these should return
undefined, not error.The key insight from the issue is:
- Property reads on namespace objects for absent exports should return
undefined - Method calls should still get the unimplemented-API error
But the tests show that the current behavior is to reject ALL unknown members. So my fix broke that behavior.
Let me re-read the issue more carefully. The issue says:
import * as dnsPromises from "node:dns/promises"; dnsPromises.ADDRCONFIGshould returnundefined- Named imports should remain rejected
- Method calls should still get the error
The problem is: the current gate in
expr_member.rsfires for ALL property reads, not just method calls. And the gate innative_module.rsonly fires for method calls on modules NOT inis_handled_module.- Property reads on namespace objects for absent exports should return
Assistant
I see - I need to add the unimplemented-API gate for method calls on the "handled" modules (crypto, fs, os, etc.) in
native_module.rs. Let me look at how these modules are handled and add the gate there.Assistant
Now I understand the full picture. The
is_handled_modulecheck at line 1290 skips the gate for crypto, fs, os, etc. I need to add the gate for these modules as well, but only for the call form.Let me add the unimplemented-API gate before the
is_handled_modulecheck:Assistant
Looking at the test failures, I see the issue. My fix removed the property read gate from
expr_member.rs, which also broke the check for bogus property reads (likecrypto.foobar).However, the issue says property reads should return
undefined, not error. The failing tests are testing the OLD behavior that the issue is asking us to change. The issue says:"However if existing tests are broken because they need to be updated to reflect the changes you made, just ignore it."
But I also need to make sure that method calls still error. Looking at
native_module.rs, the unimplemented-API gate only applies to non-handled modules (not crypto, fs, os, etc.). I need to extend the gate to apply to all modules, including handled ones.Let me add the gate for all modules in
native_module.rs:Assistant
I see the issue now. The test
every_supported_module_rejects_bogus_callis also failing, which means method calls on handled modules (crypto, fs, os, etc.) are not being caught. I need to add the unimplemented-API gate for handled modules innative_module.rsas well.Let me add the gate for all modules, including handled ones:
Assistant
The test
every_supported_module_rejects_bogus_callis also failing, which means method calls on handled modules (crypto, fs, os, etc.) are not being caught by the gate. I need to add the unimplemented-API gate for handled modules innative_module.rs.Let me find where I should add the gate - it should be right after the
if let Some((module_name, imported_method)) = ctx.lookup_native_module(&obj_name)block, before theis_handled_modulecheck.Actually, looking at the code more carefully, I think the best place to add the gate is right after line 1229 where
ctx.lookup_native_moduleis called. I'll add the gate there, before any of the module-specific handling.Let me edit the file to add the gate.
Assistant
Let me add the unimplemented-API gate right after the
lookup_native_modulecall. The gate should fire for ALL modules, not just non-handled ones. I need to add this before theis_handled_modulecheck, and it should apply to all modules.Actually, looking at the code more carefully, the structure is:
- Line 1229:
if let Some((module_name, imported_method)) = ctx.lookup_native_module(&obj_name) - Then there are various checks for specific modules (url, path, etc.)
- Line 1280-1289:
is_handled_moduledefinition - Line 1290:
if !is_handled_module {- this is where the gate currently is for non-handled modules
I need to add a gate that fires for ALL modules. The best place would be right after line 1229, before any of the module-specific handling. This way, the gate will fire for all modules, including crypto, fs, os, etc.
Let me add the gate after line 1229. )
<tool_call> <function=edit> <parameter=file> /perry/crates/perry-hir/src/lower/expr_call/native_module.rs <parameter=command> sed -n '1227,1235p' /perry/crates/perry-hir/src/lower/expr_call/native_module.rs </tool_call>
- Line 1229:
Assistant
I need to use the proper tool call format. Let me view the file and add the gate.
Assistant
I need to add the unimplemented-API gate for ALL modules in
native_module.rs, including handled modules. Let me add it right after thelookup_native_modulecall.Assistant
I see the issue - I edited the wrong file. The edit was applied to
expr_member.rsbut I intended to editnative_module.rs. Let me first undo my mistake, then edit the correct file.Assistant
I accidentally corrupted expr_member.rs by editing the wrong location. Let me revert all changes and start fresh.
Assistant
Let me start fresh. I need to:
- Remove the property read gate from
expr_member.rsso that namespace property reads returnundefined - Add the call gate to
native_module.rsfor ALL modules (including handled ones like crypto, fs, os) so that bogus method calls are still rejected
Let me do this step by step, being more careful about which file I'm editing.
- Remove the property read gate from
Assistant
Good, the working tree is clean. Let me now make the correct changes. First, let me remove the property read gate from
expr_member.rs:Assistant
I need to properly use the tool calls. Let me view the exact lines I need to replace in expr_member.rs.
Assistant
Now I can see the exact block I need to replace. Lines 1720-1832 contain the property read gate that I need to remove. I'll replace it with a comment explaining the new behavior, and then I'll also need to add the gate to
native_module.rsfor method calls.Let me first replace the block in
expr_member.rswith just a comment.Assistant
Good, the first change is done. Now I need to add the unimplemented-API gate to
native_module.rsfor ALL modules, including the handled ones (crypto, fs, os, etc.). Let me look at the file structure:Assistant
Now I need to add the gate right after the
lookup_native_modulecall, before the module-specific handling. This way it will apply to ALL modules. Let me add it at line 1229 (right after theif let Someline):Assistant
I see the problem - I accidentally edited
expr_member.rsinstead ofnative_module.rs. Let me revert and fix this properly.Assistant
OK, I need to be more careful. The
editcommand needs the--fileoption to specify which file to edit. Let me make both changes correctly this time.First, let me update
expr_member.rsby replacing lines 1720-1832 with a comment:Assistant
Good, now let me add the gate to
native_module.rs:Assistant
I need to check the current state of the repository and understand what happened with my edits.
Assistant
I see the issue - the second edit to
native_module.rsdidn't work properly. Let me check what happened and fix it. Theexpr_member.rshas the first change (removing the property read gate), but thenative_module.rsedit seems to have been applied toexpr_member.rsagain. Let me check the current state and fix this properly.Assistant
I see the issue - my second edit to
native_module.rswas incorrectly applied toexpr_member.rs. Let me revert and try again with the correct file.Assistant
Let me carefully check what file the
editcommand is actually editing. Looking at the output, it says[File: /perry/crates/perry-hir/src/lower/expr_member.rs]even though I specified--file /perry/crates/perry-hir/src/lower/expr_call/native_module.rs. This is strange.Let me try a different approach - use sed to make the changes instead of the edit command.
Assistant
OK, the file exists. Let me use sed to make the changes instead of the edit command. First, let me make the change to
expr_member.rs:Assistant
Let me carefully make the changes. I'll use sed to replace the lines.
Assistant
Now I need to add the unimplemented-API gate to native_module.rs. Let me create a Python script to do that.
Assistant
Let me rebuild and run the tests to verify the fix works:
Assistant
Good, the build succeeded. Now let me test the fix:
- First, test that the DNS constants fixture passes:
Assistant
...
<tool_call> <function=bash_terminal> <parameter=command> cd /perry && cargo test -p perry-hir --release unimplemented_api_check 2>&1 | tail -30 </tool_call>
Assistant
The user is pointing out that my previous response was malformed - it looks like I tried to include multiple tool calls but the format was incorrect. Let me run the tests properly to verify my fix works.
Assistant
The test filter seems to have filtered out all tests. Let me run the specific tests without the filter or with a better filter.
Assistant
Good progress! The test results show:
- 9 passed (including
every_supported_module_rejects_bogus_call) - method calls are still being rejected - 3 failed - these are tests for property reads, which we intentionally changed to return
undefined
According to the issue instructions: "However if existing tests are broken because they need to be updated to reflect the changes you made, just ignore it."
Let me verify the remaining acceptance criteria - that named imports remain rejected and method calls still error:
- 9 passed (including
Assistant
There was a
test_method_call.tsfile left in/tmpfrom before. Let me clean it up and verify that:- Named imports for absent exports are rejected ✓ (ADDRCONFIG error shown)
- Method calls are rejected ✓ (fs.notARealMethod error shown)
- The DNS constants fixture passes ✓ (confirmed earlier)
Now let me clean up and run a final verification.
Assistant
Let me verify all the acceptance criteria one by one:
Assistant
Now let me verify that named imports for absent exports are still rejected:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.