Skip to content

Commit

Permalink
🐛 Fix duplicate typing error messages
Browse files Browse the repository at this point in the history
semver: patch
  • Loading branch information
Somfic committed Nov 2, 2024
1 parent 8a13341 commit f50bb5a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub mod parser;
pub mod passer;

const INPUT: &str = "
let a = 1 + 1.1 - true * 'c' / \"hello\"
let a = 1 if true else 2
";

fn main() {
Expand Down
20 changes: 14 additions & 6 deletions src/passer/typing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ impl Passer for TypingPasser {
.map(|ty| LabeledSpan::at(ty.span, format!("{}", ty)))
.collect::<Vec<_>>();

critical.push(miette::miette! {
labels = labels,
help = "expression has multiple possible types",
"{:?} has multiple possible types", expression.value
});
// critical.push(miette::miette! {
// labels = labels,
// help = "expression has multiple possible types",
// "{:?} has multiple possible types", expression.value
// });

Ok(PasserResult {
critical,
Expand All @@ -50,7 +50,15 @@ impl Passer for TypingPasser {
fn check_statement(statement: &Statement<'_>) -> Result<PasserResult> {
let mut critical = vec![];

let types = statement.possible_types();
let types = statement
.possible_types()
.into_iter()
.fold(vec![], |mut acc, ty| {
if !acc.iter().any(|t: &Type<'_>| t.value == ty.value) {
acc.push(ty);
}
acc
});

if types.is_empty() || types.len() == 1 {
return Ok(PasserResult::default());
Expand Down

0 comments on commit f50bb5a

Please sign in to comment.