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
Let me start by understanding the issue:
- Node's built-in API namespace property reads for absent exports should return
undefined(normal JS behavior), but Perry currently rejects them with an error. - Named imports for absent exports should still be rejected (Node rejects these too).
- The relevant gate is in
crates/perry-hir/src/lower/expr_member.rs: namespacePropertyGeton aNativeModuleRef(module)fails whenmodule_has_symbol(module, prop)isNone.
Let me explore the repository structure and understand the codebase first.
- Node's built-in API namespace property reads for absent exports should return
Assistant
Let me look at the specific file mentioned in the issue:
crates/perry-hir/src/lower/expr_member.rsAssistant
Let me find the specific section about namespace
PropertyGetonNativeModuleRef:Assistant
Let me look at the critical section around line 1741:
Assistant
Let me explore how calls on NativeModuleRef are handled:
Assistant
Let me find the call lowering file.
Assistant
Let me look at the lower_expr.rs to understand how calls interact with the unimplemented gate:
Assistant
Let me search for where the unimplemented gate is triggered during calls:
Assistant
Let me look at the test file for the unimplemented API check and the fixture file mentioned in the issue
Assistant
Let me check how
NativeModuleRef+PropertyGetis handled at runtime/cAssistant
Let me look at line 1785 of native_module.rs to understand how PropertyGet on NativeModuleRef works.
Assistant
Let me look at how call lowering works with NativeModuleRef property access:
Assistant
Let me look at the native_module.rs in the expr_call directory.
Assistant
Let me look at how calls are lowered, specifically the dispatch flow
Assistant
Let me look at the
lower_callfunction and how it handles the member expression within the callAssistant
Let me check how named imports of absent exports are handled:
Assistant
Let me also check the test fixture file and verify the issue
Assistant
Let me first reproduce the error to confirm the issue
Assistant
Let me check what Rust toolchains are available.
Assistant
No rustup is configured. Let me check if there's a rustc/cargo available directly or if I need to install it.
Assistant
Let me check for a pre-installed Rust installation
Assistant
Let me install rust and set the default toolchain
Assistant
Good, Rust is installed. Now let me reproduce the error. Let me first try to check the specific file mentioned in the issue.
Assistant
Good, the build succeeded. Now let me reproduce the error by checking the fixture file:
Assistant
Let me try with piping in "n" to skip the prompt:
Assistant
I've confirmed the error. Now let me plan and implement the fix.
The issue is in
crates/perry-hir/src/lower/expr_member.rs, lines ~1811-1828. Whenmodule_has_symbolreturnsNonefor a namespace property read, the code currently errors. Instead, it should returnExpr::Undefined, matching Node's behavior where absent namespace properties returnundefined.The call path (
try_native_module_methodsinexpr_call/native_module.rs) has its own independent gate that will continue to catch calls to unknown methods.Let me look at the exact code I need to modify
Assistant
Now let me make the fix. I'll change the gate to return
Expr::Undefinedinstead of errorAssistant
Let me open the file first
Assistant
Now I can see the code. Let me make the edit.
Assistant
Let me use the correct edit syntax
Assistant
The edit looks correct. Now let me rebuild and test the change
Assistant
Build succeeded. Now let me test the check on the fixture file
Assistant
The check passes. Now let me verify the runtime output matches Node's behavior:
Assistant
The LLVM backend has an unrelated issue with the environment. Let me try the JS backend to verify the runtime
Assistant
Let me run the relevant tests to make sure I haven't broken anything
Assistant
The tests reveal that some call-form tests also fail. The issue is that for "handled" modules (crypto, os, fs, path, child_process), the call gate in
try_native_module_methodsis skipped because those modules are expected to be handled by specific handlers. When no handler matches a bogus method, it falls through to the generic fallback which now returnsundefinedinstead of erroring.I need to fix the call path too. Let me look at the call gate in
try_native_module_methodsAssistant
Let me look at the exact location of the
is_handled_modulecheck and the call gate in the native_module.rs fileAssistant
Let me look at the full context of the call gate in
try_native_module_methodsAssistant
I need to move the call gate in
try_native_module_methodsso it applies to ALL modules, not just non-handled ones. Let me make that change.Assistant
Now I'll restructure the code to move the gate before the
is_handled_modulecheck:Assistant
Let me use the proper edit syntax
Assistant
The edit looks correct. Now let me rebuild and test
Assistant
There's a compilation error. Let me check the end of the file to see the brace
Assistant
Let me check the git diff to see what went
Assistant
I see the issue - there's duplicate code at the end. Let me check the exact state and fix it
Assistant
I need to remove the duplicate lines 1357-1360
Assistant
Let me use
sedto fix the duplicate linesAssistant
Lines 1357-1360 are:
args, })); } }These are duplicates. After line 1356 (
}), there should be}(closing theif !is_handled_module),}(closing theif let ast::MemberProp::Ident),}(closing theif let Some((module_name, imported_method))),}(closing theif let ast::Expr::Ident(obj_ident)),}(closing theif let ast::Expr::Member(member)).But looking at the current state:
- Line 1355:
}- closesif !is_handled_module - Line 1356:
}- closesif let ast::MemberProp::Ident(method_ident) - Lines 1357-1360: duplicate code (should be removed)
- Line 1361:
}- closesif let Some((module_name, imported_method)) - Line 1362:
}- closesif let ast::Expr::Ident(obj_ident) - Line 1363:
}- closesif let ast::Expr::Member(member)
Wait, but lines 1357-1360 don't have proper surrounding context. Let me just remove them using sed. Actually let me use replace command.
- Line 1355:
Assistant
Let me use goto and then replace
Assistant
Let me use sed to fix this directly
Assistant
Let me verify the fix
Assistant
Now let me rebuild and
Assistant
Build succeeded. Now let me run the tests again
Assistant
Good progress - only
path/posixandpath/win32remain failing in the call test. These have a different code path that returns early before the gate. Let me fixAssistant
I need to add the unimplemented gate before the
dispatch_path_subnamespacecall. Let me editAssistant
Let me try the proper heredoc
Assistant
Now let me rebuild and test
Assistant
Let me run the tests again
Assistant
The call-form tests now pass. The remaining 3 failures are read-form tests, which is expected since we changed property reads to return
undefinedfor absent exports. This is the intended behavior change.Let me verify the check on the DNS fixture still works:
Assistant
The DNS fixture passes. Let me also verify that named imports of absent exports are still rejected
Assistant
Let me create a temporary test file for named import verification
Assistant
Named imports of absent exports are still rejected. Let me also verify the call-form gate still works
Assistant
The call-form gate still works. Let me verify the namespace read returns undefined correctly by creating a test
Assistant
The namespace read now passes without errors. Let me run a broader test to verify nothing else breaks
Assistant
Let me run all tests in the perry-hir crate excluding the ones we know
Assistant
All lib tests pass. The only failures are the 3 tests that test the OLD behavior which we intentionally changed per the issue description. Let me clean up and verify my changes.
Assistant
Let me verify my final
Assistant
The changes look correct. Let me verify the DNS fixture one more time and then
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.