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:
text22824ba90abf Expose globalThis.EventTarget (#3628)Node v25.9.0 behavior for the namespace object:
console$ 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:
console$ 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:
Assistant
Let me start by understanding the issue:
-
When reading properties from a Node.js built-in module namespace (like
node:dns/promises), Perry currently rejects property reads for symbols that don't exist in the built-in module's exports. However, Node.js returnsundefinedfor such property reads - they're just ordinary JS property misses. -
The fix should be in
crates/perry-hir/src/lower/expr_member.rs- the namespacePropertyGeton aNativeModuleRef(module)fails whenmodule_has_symbol(module, prop)isNone, even when the Node-compatible value should beundefined. -
Named imports for absent exports should remain rejected (Node behavior for ESM imports).
-
Unsupported API calls (like
fs.notARealMethod()) should still get the helpful error.
Let me start by exploring the repository structure and understanding the codebase.
-
Assistant
Let me look at the key file mentioned in the issue description
Assistant
The open command expects a different format. Let me try with the proper format.
Assistant
Let me search for the key patterns mentioned in the issue
Assistant
Let me look at the critical section around line 1741
Assistant
Let me see the rest of this section
Assistant
Now let me look at how call expressions handle the NativeModuleRef
Assistant
Let me find the call lowering file
Assistant
Let me look at the native module call handling
Assistant
The open command seems to be finicky. Let me try a different format.
Assistant
Let me view the native_module.rs file with cat:
Assistant
Let me search for the unimplemented gate in native_module.rs
Assistant
Let me see the context around line 1306
Assistant
Let me understand how named imports are validated. Let me check the module declaration lowering.
Assistant
Let me search for where named import validation from native modules happens
Assistant
Let me look at the named export validation in module_decl.rs
Assistant
Let me understand where NativeModuleRef is created to understand all the cases
Assistant
Let me look at how namespace imports create NativeModuleRef in module_decl.rs
Assistant
Let me understand how calls flow through the lowering to see if the member expression gate also blocks calls
Assistant
Let me find where calls with a NativeModuleRef receiver are handled
Assistant
Let me look at the process handling in expr_member.rs more carefully
Assistant
Let me look at how identifiers for namespace imports are lowered
Assistant
Let me look at the identifier lowering in lower_expr.rs
Assistant
Let me look at the call lowering flow in expr_call/mod.rs
Assistant
Let me look at the try_native_module_methods function to understand how it handles callees
Assistant
Let me see more of the try_native_module_methods function, especially the part where it handles the NativeModuleRef case and the gate
Assistant
Let me verify how lower_expr dispatches Call vs Member
Assistant
Let me look at the Call and Member arms in lower_expr.rs
Assistant
Let me search for where the Member expression is handled for reading (not assignment)
Assistant
Let me look at the Call arm in lower_expr.rs to see if it calls lower_member for the callee
Assistant
Let me look at the process handling path in expr_member.rs more carefully
Assistant
Let me look at the DNS constants test fixture mentioned in the issue
Assistant
Let me reproduce the error first
Assistant
Let me build perry first
Assistant
Let me check what Rust toolchains are available.
Assistant
Now let me build perry - this will take a while. But first let me understand the fix I need to make.
Looking at the code in
expr_member.rs, the gate at lines 1810-1831 blocks all property reads onNativeModuleRefwhen the symbol is not in the manifest. The fix is to simply remove this gate (let the code fall through toPropertyGetwhich returnsundefinedat runtime).But wait, I need to be more careful. Let me re-read the issue once more:
"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.
Assistant
Let me look at the full block I need to modify
Assistant
Let me check how the
processglobal is registeredAssistant
Let me search for how process is identified as a native
Assistant
Let me look at the process path in lower_member more carefully
Assistant
Let me look at where the process member access starts being matched
Assistant
Let me look at the process handling starting at line 175
Assistant
Let me look at the overall structure of lower_member_inner to understand when object is set
Assistant
Let me find where
objectvariable is defined that flows to the gate at line 174Assistant
Now I understand the code well. Let me make the fix. The gate at lines 1810-1831 needs to be removed, along with the now-unused variables
allow_unimplementedandobj_is_named_importAssistant
Let me try the edit command with
Assistant
Now let me update the comment block above to match the new behavior
Assistant
Let me check if
module_has_any_entriesis used elsewhere in this file now that we removed the gateAssistant
Good,
module_has_symbolis still used elsewhere. Let me also check ifmodule_has_any_entriesis imported but no longer usedAssistant
Let me check if
unimpl_hintsis still needed in this fileAssistant
Let me try building to verify the changes compile
Assistant
It compiled. Now let me build the full perry binary
Assistant
Now let me test with the DNS constants fixture
Assistant
Let me try with the telemetry prompt disabled
Assistant
The check passes! Now let me also run the fixture to verify correct output
Assistant
The
checkpassed. The runtime LLVM issue is pre-existing and not related. Let me verify that named imports of absent exports are still rejectedAssistant
Named imports are still rejected. Let me also verify that unsupported method calls are still
Assistant
Let me test with a module that's not in the handled list for the call gate
Assistant
Unsupported method calls are still caught. Now let me verify present symbols still work correctly and absent symbols return undefined
Assistant
Let me clean up and test properly
Assistant
Now let me run the existing tests to ensure no regressions
Assistant
Let me look at the failing tests to understand what they check
Assistant
Let me view the test file with cat
Assistant
Let me look at the end of lower_call_inner to see what happens when no call handler matches
Assistant
Let me see the fallback path at the end of lower_call_inner
Assistant
Let me look at the try_native_module_methods flow for handled modules more
Assistant
Let me look at try_module_static_methods to see how it handles unknown methods on handled modules
Assistant
Let me look at the module_static function to understand its flow
Assistant
Let me look at the LoweringContext structure
Assistant
Let me take a different approach. Instead of removing the gate entirely, I'll keep it but only skip it for standalone property reads (not callees of calls). Let me look at the fallback path in lower_call_inner
Assistant
Let me check the LoweringContext fields for similar patterns
Assistant
Let me look for existing boolean flags in the LoweringContext
Assistant
I need a more nuanced approach. Let me revert my changes to lower_member and instead add a context flag. First, let me revert:
Assistant
Let me revert my changes first, then apply the correct fix
Assistant
Now let me implement the proper fix. First, let me add the flag to LoweringContext
Assistant
Let me find the new() method
Assistant
Let me look at the LoweringContext initialization pattern
Assistant
Let me find where LoweringContext is
Assistant
Let me look at how LoweringContext is constructed
Assistant
Let me see the rest of the
Assistant
Let me think about a simpler approach. Instead of a flag, let me add the call-side gate for handled modules. Let me check what happens for each handled module in the call
Assistant
OK, I think the cleanest approach is:
- Keep the gate removed from
lower_member(my original change) - Add the gate in the call fallback path to catch unknown methods on ALL modules (including handled ones)
Let me revert to my change and then add the call-side gate. First, let me re-apply my change to lower_member:
- Keep the gate removed from
Assistant
Now let me update the comment above the gate
Assistant
Now let me add the call-side gate in the fallback path of lower_call_inner. Let me look at the exact location
Assistant
Now let me add the call-side gate. I'll add it right before the fallback at line 452
Assistant
I accidentally edited the wrong file! Let me revert expr_member.rs and apply the change to the
Assistant
Let me re-apply the correct changes to both files. First, let me edit expr_member.rs using the --file option
Assistant
Good. Now let me add the call-side gate in expr_call/mod.rs
Assistant
Now let me add the call-side gate in expr_call/mod.rs
Assistant
Now I need to check if
unimpl_hintsis accessible fromexpr_call/mod.rs. Let me check the importsAssistant
Let me verify the unimpl_hints module has the function I'm calling
Assistant
Let me try building to see if it compiles
Assistant
Let me fix the compilation errors. First, let me check the pre-existing error in expr_member.rs to see if it's from my changes
Assistant
I see the problem - my edit removed the
let object = Box::new(object_expr);line! Let me check the full state of theAssistant
I need to fix the missing
let objectline. Let me add it backAssistant
I need to use --file to target the correct file. Let me first fix the damage to expr_call/mod.rs
Assistant
Let me first fix expr_member.rs to add back the missing
let objectlineAssistant
Let me add the missing line back to expr_m
Assistant
Good, expr_member.rs is fixed. Now let me add the call-side gate to expr_call/mod.rs
Assistant
Now let me insert the call-side gate
Assistant
Now let me build to verify it compiles
Assistant
It compiles. Now let me build the full binary and run the tests
Assistant
Now let me run the tests to verify
Assistant
The call-side gate works (
every_supported_module_rejects_bogus_callpasses). Now I need to update the property-read tests to reflect the new behavior. These tests should now expect success (property reads return undefined) instead of failureAssistant
I see there's a stray
}at line 184. Let me fix that and update the other testsAssistant
Good. Now let me update
supported_module_with_unknown_member_is_rejectedandevery_supported_module_rejects_bogus_memberAssistant
Now update
every_supported_module_rejects_bogus_memberto expect successAssistant
I see leftover duplicate lines. Let me clean them up
Assistant
Let me remove the dangling lines at 311-315
Assistant
Now let me run the tests again
Assistant
Let me check around line 142 for the unclosed delimiter
Assistant
The closing brace for
node_builtin_real_named_exports_still_compilewas removed. Let me add it backAssistant
Now let me run the tests again
Assistant
All 12 tests pass! Let me also run a broader set of tests and verify the original acceptance criteria
Assistant
All tests pass. Now let me verify the acceptance criteria
Assistant
Acceptance criterion 1 passes. Let me verify the other criteria
Assistant
The key results are visible despite the files being checked together. Let me clean up and run individual checks
Assistant
The namespace property read test passed (only 2 errors from t1 and t2, no error from t3). Let me run a clean test to confirm
Assistant
All acceptance criteria are met! Let me run a broader test to make sure nothing else is broken
Assistant
All tests pass! Zero failures. Let me review my final changes
Assistant
Let me look at the final diff
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.