Skip to content

Commit

Permalink
handle no primary
Browse files Browse the repository at this point in the history
  • Loading branch information
Medowhill committed Aug 5, 2024
1 parent 92f46ab commit adf3a7c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ impl MultiSpan {
.collect()
}

fn primary_line(&self, source_map: &SourceMap) -> usize {
fn primary_line(&self, source_map: &SourceMap) -> Option<usize> {
let labels = self.internal_labels(source_map);
let label = labels.iter().find(|l| l.primary).unwrap();
pos_of_span(label.span.span(), source_map).0
let label = labels.iter().find(|l| l.primary)?;
Some(pos_of_span(label.span.span(), source_map).0)
}
}

Expand Down Expand Up @@ -1501,7 +1501,7 @@ impl TypeCheckingResult {
#[derive(Debug, Clone)]
pub struct TypeError {
pub message: String,
pub line: usize,
pub line: Option<usize>,
pub fix: Option<PossibleFix>,
}

Expand Down
21 changes: 13 additions & 8 deletions src/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ impl<'a> FixContext<'a> {
if let Some(res) = &self.result {
let prefix_lines = self.prefix_lines();
for error in &res.errors {
assert!(
error.line == 1 || error.line > prefix_lines,
"{}\n\n{}\n\n{}",
self.prefix,
self.code,
error.message
);
if let Some(line) = error.line {
assert!(
line == 1 || line > prefix_lines,
"{}\n\n{}\n\n{}",
self.prefix,
self.code,
error.message
);
}
}
}
}
Expand Down Expand Up @@ -480,7 +482,10 @@ impl<'ast> Translator<'ast> {
wo_errors += 1;
wo_error_names.push(*name);
let callees = &transitive[name];
if callees.iter().all(|c| translated[c].no_error()) {
if callees.iter().all(|c| {
let t = some_or!(translated.get(c), return true);
t.no_error()
}) {
no_trans_errors += 1;
no_trans_error_names.push(*name);
}
Expand Down

0 comments on commit adf3a7c

Please sign in to comment.