Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 76 additions & 54 deletions src/ast.rs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ impl SingleExpression {
}
SingleExpressionInner::Variable(identifier) => scope
.get(&BasePattern::Identifier(identifier.clone()))
.ok_or(Error::UndefinedVariable(identifier.clone()))
.ok_or(Error::UndefinedVariable {
identifier: identifier.clone(),
})
.with_span(self)?,
SingleExpressionInner::Expression(expr) => expr.compile(scope)?,
SingleExpressionInner::Tuple(elements) | SingleExpressionInner::Array(elements) => {
Expand Down
9 changes: 7 additions & 2 deletions src/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,13 @@ impl DependencyGraph {
handler: &mut ErrorCollector,
) -> Option<Module> {
let Ok(content) = std::fs::read_to_string(path.as_path()) else {
let err = RichError::new(Error::FileNotFound(PathBuf::from(path.as_path())), span)
.with_source(importer_source.clone());
let err = RichError::new(
Error::FileNotFound {
filename: PathBuf::from(path.as_path()),
},
span,
)
.with_source(importer_source.clone());

handler.push(err);
return None;
Expand Down
46 changes: 34 additions & 12 deletions src/driver/resolve_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ impl Program {
for item in parsed.items() {
if let parse::Item::Use(use_decl) = item {
handler.push(
RichError::new(Error::UnknownLibrary(use_decl.str_path()), *use_decl.span())
.with_content(content.clone()),
RichError::new(
Error::UnknownLibrary {
name: use_decl.str_path(),
},
*use_decl.span(),
)
.with_content(content.clone()),
);
continue;
}
Expand Down Expand Up @@ -259,8 +264,8 @@ impl DependencyGraph {
(Ok(()), _) | (_, Ok(())) => Ok(()),

(Err(err_alias), Err(err_func)) => {
let alias_is_missing = matches!(err_alias.error(), Error::UnresolvedItem(_));
let func_is_missing = matches!(err_func.error(), Error::UnresolvedItem(_));
let alias_is_missing = matches!(err_alias.error(), Error::UnresolvedItem { .. });
let func_is_missing = matches!(err_func.error(), Error::UnresolvedItem { .. });

if !alias_is_missing || func_is_missing {
// If it's missing everywhere, OR if the function is missing
Expand Down Expand Up @@ -315,13 +320,26 @@ impl DependencyGraph {
let orig_id = (target_name.clone(), ind);

// 2. Verify Existence using T
let visibility: &Visibility = namespace.resolutions[ind]
.get(&target_name)
.ok_or_else(|| RichError::new(Error::UnresolvedItem(name.to_string()), span))?;
let visibility: &Visibility =
namespace.resolutions[ind]
.get(&target_name)
.ok_or_else(|| {
RichError::new(
Error::UnresolvedItem {
name: name.to_string(),
},
span,
)
})?;

// 3. Verify Visibility
if matches!(visibility, parse::Visibility::Private) {
return Err(RichError::new(Error::PrivateItem(name.to_string()), span));
return Err(RichError::new(
Error::PrivateItem {
name: name.to_string(),
},
span,
));
}

// 4. Determine the local name and ID up front
Expand All @@ -345,14 +363,18 @@ impl DependencyGraph {
// 5. Check for collisions using `namespace` fields
if namespace.registry.direct_targets.contains_key(&local_id) {
return Err(RichError::new(
Error::DuplicateAlias(local_symbol.to_string()),
Error::DuplicateAlias {
name: local_symbol.to_string(),
},
span,
));
}

if namespace.memo.contains(&local_id) {
return Err(RichError::new(
Error::RedefinedItem(local_symbol.to_string()),
Error::RedefinedItem {
name: local_symbol.to_string(),
},
span,
));
}
Expand Down Expand Up @@ -400,7 +422,7 @@ fn register_type_alias(

if tracker.memo.contains(&local_id) {
return Err(RichError::new(
Error::RedefinedAlias(name.clone()),
Error::RedefinedAlias { name: name.clone() },
*item.span(),
));
}
Expand All @@ -426,7 +448,7 @@ fn register_function(

if tracker.memo.contains(&local_id) {
return Err(RichError::new(
Error::FunctionRedefined(name.clone()),
Error::FunctionRedefined { name: name.clone() },
*item.span(),
));
}
Expand Down
Loading
Loading