Skip to content

Commit

Permalink
✨ Add label not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
Philogy committed Oct 20, 2024
1 parent dd78490 commit 4908d47
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 8 deletions.
58 changes: 53 additions & 5 deletions crates/analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,19 @@ impl AnalysisError<'_, '_> {
Label::new((filename.clone(), not_found.1.into_range()))
.with_color(Color::Red),
)
.with_label(
.with_label(if scope.args.0.is_empty() {
Label::new((filename.clone(), scope.args.1.into_range()))
.with_color(Color::Red)
.with_message("no arguments")
} else {
let args_list_span = scope.args.1.start + 1..scope.args.1.end - 1;
Label::new((filename.clone(), args_list_span))
.with_color(Color::Red)
.with_message(format!(
"no '{}' in argument list",
not_found.0.fg(Color::Red)
)),
)
"No '{}' in arguments list",
not_found.ident().fg(Color::Red)
))
})
.with_help(
"Ensure the argument exists and is correct (names are case-sensitive)",
)
Expand All @@ -184,6 +189,49 @@ impl AnalysisError<'_, '_> {
Label::new((filename.clone(), not_found.1.into_range())).with_color(Color::Red),
)
.finish(),
AnalysisError::LabelNotFound {
scope,
invocation_chain,
not_found,
} => {
Report::build(ReportKind::Error, filename.clone(), not_found.1.start)
.with_config(Config::default().with_index_type(IndexType::Byte))
.with_message(format!(
"Label '{}' not found in macro {} or its parent contexts",
not_found.ident().fg(Color::Red),
scope.ident().fg(Color::Blue)
))
.with_labels(invocation_chain.iter().rev().flat_map(
|(parent_scope, invoke)| {
[
Label::new((filename.clone(), parent_scope.span().into_range()))
.with_color(Color::Yellow)
.with_message(format!(
"No label '{}' found in parent {}",
not_found.ident().fg(Color::Red),
parent_scope.ident().fg(Color::Yellow)
)),
Label::new((filename.clone(), invoke.1.into_range())).with_color(
if invoke.ident() == scope.ident() {
Color::Blue
} else {
Color::Yellow
},
),
]
},
))
.with_label(
Label::new((filename.clone(), scope.span().into_range()))
.with_color(Color::Blue)
.with_message(format!(
"No label '{}' found in {}",
not_found.ident().fg(Color::Red),
scope.ident().fg(Color::Blue)
)),
)
.finish()
}
_ => Report::build(ReportKind::Error, filename.clone(), 0)
.with_message(format!("Error with unimplemented formatting: {:?}", self))
.finish(),
Expand Down
22 changes: 22 additions & 0 deletions examples/errors/LabelNotFound.huff
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#define macro MAIN() = takes(0) returns(0) {
LABEL_AWAY()
FIRST()
}

#define macro LABEL_AWAY() = takes(0) returns(0) {
nice:
SECOND()
}

#define macro FIRST() = takes(0) returns(0) {
stop
stop
stop
stop
SECOND()
}


#define macro SECOND() = takes(0) returns(0) {
nice 0x1
}
3 changes: 0 additions & 3 deletions examples/errors/ReferenceNotFound.huff
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
0x879234af8c
<wow>
HAS_LABEL(0x1)
NO_FIND_LABEL()
}

#define macro HAS_LABEL(five, seven, eight) = takes(0) returns(0) {
label:
<six>
}


0 comments on commit 4908d47

Please sign in to comment.