ditto-lang/ditto

Support `private` modules

Opened this issue · 2 comments

A module marked as private can only be imported by other modules in the same package.

private module Implementation.Details exports (..);

The implementation should be fairly straightforward - we just need to check during build planning whether a module imported from a different package is private: true (and raise an error if it is):

Relevant bit of the build planning logic is here:

// Add the edges
for (node_index, node) in build_graph_nodes.iter() {
for import_line in node.imports.iter() {
let import_package_name = import_line
.package
.as_ref()
.map(|parens| parens.value.0.value.as_str());
let import_module_name = ast::ModuleName::from(import_line.module_name.clone());
for (
idx,
BuildGraphNode {
package_name,
module_name,
..
},
) in build_graph_nodes.iter()
{
let same_package_name = match (package_name, import_package_name) {
(None, None) => true,
(Some(a), Some(b)) => a.as_str() == b,
_ => false,
};
let same_module_name = *module_name == import_module_name;
if same_package_name && same_module_name {
build_graph.add_edge(*node_index, *idx, "");
break;
}
}
// If we can't find the import then we just ignore it,
// let the checker throw an error.
}
}

The ditto_ast::Module type will also need a private: bool field adding:

pub struct Module {

Hi,
Can I take up this issue if possible?

Hi, Can I take up this issue if possible?

Sure thing 🙏