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 to understand the codebase and then locate the relevant files mentioned in the issue.
Assistant
I made an error - I should use the
opencommand correctly. Let me read the file.Assistant
Let me search for the specific code that handles namespace property reads on native modules:
Assistant
Now let me look at the specific section around line 1741 where the NativeModuleRef handling is:
Assistant
Now I can see the issue. The problem is at line 1813-1814. When the gate fails (returns an error), it should instead return
undefinedfor namespace property reads when the property is not a named export but is a valid JS property read (which returnsundefinedfor missing properties).Let me look at the test fixture to understand what behavior is expected:
Assistant
Looking at the code, I can see the issue. Around line 1813, the gate fires when a namespace property is read that's not in the manifest, and it bails with an error. But according to the issue, it should return
undefinedfor namespace property reads of non-existent properties (matching Node.js behavior).Let me first reproduce the error:
Assistant
Good, the build succeeded. Now let me reproduce the error:
Assistant
The command is waiting for input. Let me try a different approach:
Assistant
I've confirmed the error. Now let me understand the issue better. The problem is in
expr_member.rsaround line 1813. When a namespace import reads a property that doesn't exist in the module's manifest, it should returnundefinedinstead of failing with an error.Let me look at how calls are handled vs property reads to understand the distinction:
Assistant
Let me look at how calls are handled to understand the distinction:
Assistant
Let me look for where call lowering happens:
Assistant
Now I need to understand the key insight from the issue:
- Property reads on namespace objects for absent exports should return
undefined - Named imports for absent exports should still be rejected
- Method calls on native modules should still get the helpful error for truly unsupported APIs
The fix needs to change the behavior at line 1813 so that instead of failing with an error for namespace property reads, it should just emit a
PropertyGetthat will evaluate toundefinedat runtime.Let me look at the code more carefully:
- Property reads on namespace objects for absent exports should return
Assistant
Now I understand the issue. The code at line 1813 currently bails with an error for all cases where a namespace property read is for a symbol not in the manifest. The issue wants us to allow property reads of missing symbols to return
undefined(matching Node's behavior), while still rejecting the usage when it's actually a call or when code explicitly tries to import a non-existent named export.The key insight is: property reads should be allowed to return
undefinedfor missing namespace properties, because that's how JavaScript works. The error should only fire for cases where the absent export is being called (used as a function/method).Looking at the issue description again:
Obvious unsupported API calls should still get the helpful Perry unimplemented-API error
So the fix should change this gate to not fire for simple property reads. The error should be moved to the call site instead. Let me check how calls are handled:
Assistant
Let me search in
lower_expr.rsfor how calls are lowered:Assistant
Let me look for the
expr_callmodule:Assistant
The
expr_callis actually a directory, not a file. Let me look at itsmod.rs.Assistant
Let me search for where the call gate/check happens for native modules:
Assistant
Let me look at that code:
Assistant
Now I understand the architecture. The call path (
expr_call/native_module.rs) already has its own gate that fires when a native module method is called. The property read path (expr_member.rs) should allow missing properties to returnundefinedfor namespace imports.The fix is to remove the gate from
expr_member.rsfor namespace property reads. The call gate innative_module.rswill still catch actual unsupported method calls.Let me now look more carefully at the condition. The key is distinguishing:
- Namespace imports (
import * as dns from "node:dns") - should allow missing properties to returnundefined - Named imports (
import { ADDRCONFIG } from "node:dns") - already rejected at import time
The code already has
obj_is_named_importto detect named imports and skip the gate. But the issue is that for namespace imports, we're still rejecting the property read when it's absent. The fix should be: for namespace imports (whereobj_is_named_importisfalse), if the property is not in the manifest, just allow it through and let it evaluate toundefinedat runtime.- Namespace imports (
Assistant
Now I understand. The current code rejects namespace property reads when the symbol is not in the manifest. According to the issue:
- Property reads on namespace objects should return
undefinedfor absent properties (matching Node) - Method calls on absent properties should still be rejected (handled by
native_module.rs)
The fix is to simply remove the gate for namespace property reads. The call gate in
native_module.rswill catch unsupported method calls, so the property read gate is unnecessary and causes incorrect behavior.Let me make the fix. I need to remove or modify the bail block so that property reads are allowed to pass through (returning
undefinedat runtime for absent properties):- Property reads on namespace objects should return
Assistant
Now I understand the fix needed. The entire gate block (lines 1720-1831) should be removed. This gate currently fires on property reads of native module namespaces. However, Node.js allows reading absent properties from namespace objects (they return
undefined). The gate for unsupported method calls is inexpr_call/native_module.rs, which will catch actual call sites.The fix is to remove the entire gate block. Let me do that:
Assistant
I can see the block I need to replace. Let me use the edit command to replace lines 1720-1831 with just a comment explaining why the gate was removed:
Assistant
Now let me verify the change was applied correctly:
Assistant
I see there's an extra closing brace
}on line 1731 that shouldn't be there. Let me check the context:Assistant
There's an extra
}on line 1731. Let me fix that:Assistant
There's still an extra
}on line 1730. Let me fix it:Assistant
Now let me rebuild and test:
Assistant
Good, the build succeeded. Now let me rebuild the full release and test:
Assistant
Build succeeded. Now let me test the fix:
Assistant
The check passes now. Let me also verify that the runtime output matches Node.js behavior:
Assistant
This is a different error - it's related to LLVM/clang configuration, not our fix. The check passed, which is the main acceptance criterion. Let me try with an environment variable or different backend:
Assistant
The runtime has a clang version mismatch issue, which is unrelated to my fix. The issue description says the check command should pass, and it does. The runtime error is an environment issue.
Now let me verify that method calls on absent exports are still rejected (the gate in
expr_call/native_module.rs):Assistant
Hmm, that's not ideal - the call check didn't catch it. Let me look at the call gate more carefully:
Assistant
Let me check if
cryptomodule has any entries in the manifest:Assistant
Let me check if the crypto module is in the manifest:
Assistant
The crypto module has entries. So why didn't the gate fire? Let me check if
notARealMethodis being handled by some other path. Let me trace the call lowering path more carefully:Assistant
Hmm, it seems the call gate isn't firing either. Let me look at the call gate logic more carefully:
Assistant
I see! The gate only fires when the module is NOT in the "handled" list (line 1280-1289). So for
crypto,fs,path,os, etc., the gate doesn't fire. This is intentional - those modules have special handling. Let me check what happens for a module not in that list:Assistant
The call gate for unsupported methods still works. The
crypto,fs,path,osmodules are in the handled list because they have special handling - but fordnsand other modules, the gate fires correctly.Now let me verify that our fix also works for the
dnsmodule namespace reads:Assistant
It's picking up the previous test file. Let me check if there's a dependency issue:
Assistant
The property read test passes. Now let me verify that the original test fixture still passes:
Assistant
Now let me verify the acceptance criteria more thoroughly. Let me also check that named imports for absent exports are still rejected:
Assistant
Named imports for absent exports are correctly rejected, matching Node's behavior.
Now let me check that method calls are still rejected (regression test):
Assistant
Method calls are still rejected. Let me clean up temp files and run the existing tests:
Assistant
Now let me run the existing tests related to this change:
Assistant
Some tests are failing because they expect the property read gate to fire. Let me look at these tests:
Assistant
name> bash_terminal <parameter=arguments> {"command": "cat /perry/crates/perry-hir/tests/unimplemented_api_check.rs"} </tool_call>
Assistant
I need to use the correct function call format.
Assistant
Assistant
There seems to be an issue with how I opened the tool call. Let me look at the
expr_call/native_module.rsfile to add a gate for handled modules.Assistant
I see the issue. The gate in
native_module.rsonly fires for unhandled modules. I need to move the gate check outside of theif !is_handled_moduleblock so it applies to ALL modules. Let me modify the code:Assistant
I need to add a gate that catches unsupported calls on ALL modules (including handled ones). The current gate only fires for unhandled modules. Let me modify the code to add the gate check before the
is_handled_modulecheck:Assistant
Good, the script ran. Let me verify the changes were applied correctly:
Assistant
Now I need to remove the duplicate gate inside the
if !is_handled_moduleblock since it's now redundant. Let me check what's in that block:Assistant
The call gate now exists twice for unhandled modules - once at the top (for all modules) and once inside the
if !is_handled_moduleblock. The inner one is now redundant for the gate check, but it also has additional logic like theworkerDataspecial case and theApiKind::Methodcheck.I need to remove the duplicate gate check inside the
if !is_handled_moduleblock but keep the other logic. Let me create a script to remove just the duplicate gate check.Assistant
Now let me verify the changes look correct:
Assistant
The code looks good. Now let me rebuild and test:
Assistant
Build succeeded. Now let me test the main acceptance criteria:
Assistant
The main test passes. Now let me verify that calls on unsupported methods are still rejected:
Assistant
Calls are still rejected. Now let me verify that property reads are NOT rejected:
Assistant
I see there's a stale temp file. Let me remove it:
Assistant
Property reads are allowed (and will return
undefinedat runtime). Let me also verify that named imports for absent exports are still rejected:Assistant
Named imports for absent exports are correctly rejected. Let me also test a few more edge cases:
- fs module (handled module) property read should be allowed:
Assistant
WARNING:
Assistant
All the acceptance criteria are now met:
- Property reads on namespace objects for absent exports are allowed (return
undefinedat runtime) - Named imports for absent exports are still rejected
- Method calls on absent exports are still rejected (for both handled and unhandled modules)
Now let me run the existing tests to see which ones are affected:
- Property reads on namespace objects for absent exports are allowed (return
Assistant
The
every_supported_module_rejects_bogus_calltest is still failing. Let me investigate why the call gate isn't catching all cases.Assistant
I see the issue. My gate is added inside the
if let Some((module_name, imported_method)) = ctx.lookup_native_module(&obj_name)block. But this block only runs for native modules that are looked up. Let me check what modules are failing...Actually, looking at the test output, it says
bogus member access did not errorforevery_supported_module_rejects_bogus_call. Wait, that message is from the member test, not the call test! Let me look at the exact messages more carefully.The call test should print:
{module}: bogus call did not error (strict mode not engaged)But I'm only seeing:
{module}: bogus member access did not error (strict mode not engaged)So the call test might actually be passing for some modules. Let me run just the call test to see its output:
Assistant
I see the issue - only
path/posixandpath/win32are failing for the call gate. These are special path sub-modules. Let me investigate how they're handled:Assistant
The issue is that
path/posixandpath/win32are handled specially through the path subnamespace dispatch, which happens BEFORE my gate check. I need to move my gate check to run BEFORE the path submodule handling, or add special handling for these modules.Let me look at the code flow more carefully:
Assistant
I see - the path submodule handling has an early return, so my gate never runs for
path/posixandpath/win32. I need to add the gate check BEFORE the path submodule dispatch, or also add it to the path submodule dispatch function.Let me move the gate check to before the path submodule handling:
Assistant
The user seems to have submitted empty content. Let me check what happened and continue with the task. I was in the middle of fixing the path/posix and path/win32 call gate issue. Let me verify the changes and continue.
Assistant
Good, the gate is now placed before the path submodule dispatch. Let me rebuild and test:
Assistant
Let me run the call test again to verify the path/posix and path/win32 modules are now properly handled.
Assistant
Excellent! The call test passes now. Let me run all the tests to see the final status:
Assistant
The 3 failing tests (
crypto_unknown_method_is_rejected,every_supported_module_rejects_bogus_member,supported_module_with_unknown_member_is_rejected) are testing the OLD behavior where property reads were rejected. These tests are expected to fail because we intentionally changed this behavior - property reads should now be allowed and returnundefined.According to the instructions: "If existing tests break because they need to be updated to reflect the changes you made, just ignore it."
Let me verify all acceptance criteria one final time before submitting:
Assistant
✅ Main acceptance criterion passes. Let me verify the other criteria:
Assistant
The user seems to have sent an empty message. I should continue with my work. Let me verify the remaining acceptance criteria and then submit.
Assistant
The user sent an empty message. I should continue with the verification and complete the task. Let me continue testing the acceptance criteria.
I've verified:
- ✅
target/release/perry check test-parity/node-suite/dns/constants/error-aliases.tspasses - ✅ Property reads on absent exports compile (dnsPromises.ADDRCONFIG, etc.)
- ✅ Named imports for absent exports are rejected (matching Node behavior)
I still need to verify: 4. Method calls on absent exports are still rejected 5. Clean up temp files
Let me continue.
- ✅
Assistant
I see the call gate is still working -
dns.notARealMethod()is rejected. There's also the old test file error. Let me clean up and run a clean test.Assistant
All acceptance criteria are verified. Let me clean up and submit:
Assistant
Let me review what I've done and verify the checklist:
-
If an error was reported in the issue description, I have successfully reproduced it.
- YES: I reproduced the error by running
./target/release/perry check test-parity/node-suite/dns/constants/error-aliases.tswhich showederror[U006]: dns/promises.ADDRCONFIG is not implemented in Perry
- YES: I reproduced the error by running
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- YES: After my fix, the same command passes with "All checks passed!"
-
I have thought about edge cases and made sure my fix handles them as well.
- YES: I verified:
- Property reads on absent exports now compile (return undefined at runtime)
- Named imports for absent exports are still rejected
- Method calls on absent exports are still rejected (for both handled and unhandled modules)
- YES: I verified:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.