Skip to content

Commit d25d9a0

Browse files
committed
Allow Package::resolve() to skip the namespace export check for base
1 parent 571ad70 commit d25d9a0

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

crates/oak_db/src/package_resolve.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ impl<'db> Package {
5555
name: Name<'db>,
5656
visibility: PackageVisibility,
5757
) -> Vec<Definition<'db>> {
58+
// When resolving an export, the `name` must be present in the `NAMESPACE`
59+
// exports. If the package is `base`, there is no `NAMESPACE`, but all top-level
60+
// bindings in `base` are visible by construction, so we skip this check entirely.
5861
if visibility == PackageVisibility::Exported &&
62+
self.name(db) != "base" &&
5963
!self
6064
.namespace(db)
6165
.exports

crates/oak_db/src/tests/package_resolve.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,23 @@ fn test_same_name_defined_in_multiple_files_returns_each() {
273273
assert!(target_files.contains(&files[0]));
274274
assert!(target_files.contains(&files[1]));
275275
}
276+
277+
#[test]
278+
fn test_base_exports_every_top_level_binding() {
279+
// `base` doesn't have a `NAMESPACE`, so there are no namespace exports for it.
280+
// Instead, `PackageVisibility::Exported` lookups on `base` skip the export check and
281+
// fall straight through to looking for a top-level binding anywhere in the `base`
282+
// source files.
283+
//
284+
// Note that this won't find primitives! These have no top-level binding.
285+
let mut db = TestDb::new();
286+
let (pkg, files) = setup_package(&mut db, "base", &[], &[(
287+
"workspace/base/R/a.R",
288+
"foo <- function() 1\n",
289+
)]);
290+
291+
let defs = pkg.resolve(&db, name(&db, "foo"), PackageVisibility::Exported);
292+
assert_eq!(defs.len(), 1);
293+
assert_eq!(defs[0].file(&db), files[0]);
294+
assert_eq!(defs[0].name(&db).text(&db).as_str(), "foo");
295+
}

0 commit comments

Comments
 (0)