Skip to content

Commit

Permalink
reintroduce proper error message
Browse files Browse the repository at this point in the history
  • Loading branch information
plafer committed Jul 25, 2024
1 parent 42a991a commit 8669dfc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
8 changes: 5 additions & 3 deletions assembly/src/ast/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,11 @@ impl Module {
span: export.span(),
});
}
if let Some(_prev) = self.resolve(export.name()) {
Err(SemanticAnalysisError::ProcedureNameConflict {
name: export.name().clone(),
if let Some(prev) = self.resolve(export.name()) {
let prev_span = prev.span();
Err(SemanticAnalysisError::SymbolConflict {
span: export.span(),
prev_span,
})
} else {
self.procedures.push(export);
Expand Down
5 changes: 0 additions & 5 deletions assembly/src/sema/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use crate::{
use alloc::{sync::Arc, vec::Vec};
use core::fmt;

use super::ProcedureName;

/// The high-level error type for all semantic analysis errors.
///
/// This rolls up multiple errors into a single one, and as such, can emit many
Expand Down Expand Up @@ -78,9 +76,6 @@ pub enum SemanticAnalysisError {
#[label("previously defined here")]
prev_span: SourceSpan,
},
#[error("procedure name conflict: found duplicate definitions of '{name}'")]
#[diagnostic()]
ProcedureNameConflict { name: ProcedureName },
#[error("symbol undefined: no such name found in scope")]
#[diagnostic(help("are you missing an import?"))]
SymbolUndefined {
Expand Down
8 changes: 7 additions & 1 deletion assembly/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2198,7 +2198,13 @@ fn invalid_proc_duplicate_procedure_name() {
source,
"syntax error",
"help: see emitted diagnostics for details",
"procedure name conflict: found duplicate definitions of 'foo'"
"symbol conflict: found duplicate definitions of the same name",
regex!(r#",-\[test[\d]+:1:6\]"#),
"1 | proc.foo add mul end proc.foo push.3 end begin push.1 end",
" : ^|^ ^^^^^^^^^|^^^^^^^^^",
" : | `-- conflict occurs here",
" : `-- previously defined here",
" `----"
);
}

Expand Down

0 comments on commit 8669dfc

Please sign in to comment.