Skip to content

Commit f9b558d

Browse files
committed
feat: miette report for multiple declaration of the same id
1 parent 953a748 commit f9b558d

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/parser.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,14 @@ pub fn generate_bit_stream(
217217
id_collect.insert(id.clone(), (adr, span.clone()));
218218
} else {
219219
let other_span = (*id_ref.unwrap()).1.clone();
220-
panic!(
221-
"identifier already used there {}..{}",
222-
other_span.start, other_span.end
220+
let report = miette!(
221+
labels = vec![
222+
LabeledSpan::at(other_span, "previously declared here"),
223+
LabeledSpan::at(span.clone(), "declared there"),
224+
],
225+
"Error: Identifier already declared"
223226
);
227+
errors.push(report);
224228
}
225229

226230
String::new()
@@ -236,10 +240,14 @@ pub fn generate_bit_stream(
236240
id_collect.insert(id.clone(), (*val, span.clone()));
237241
} else {
238242
let other_span = (*id_ref.unwrap()).1.clone();
239-
panic!(
240-
"identifier already used there {}..{}",
241-
other_span.start, other_span.end
243+
let report = miette!(
244+
labels = vec![
245+
LabeledSpan::at(other_span, "previously declared here"),
246+
LabeledSpan::at(span.clone(), "declared there"),
247+
],
248+
"Error: Identifier already declared"
242249
);
250+
errors.push(report);
243251
}
244252

245253
String::new()

0 commit comments

Comments
 (0)