Skip to content

Commit

Permalink
Improved error messages for possible function callees that have polym…
Browse files Browse the repository at this point in the history
…orphic arguments with constraints
  • Loading branch information
IsaacShelton committed Dec 18, 2024
1 parent 6d89442 commit ebeafdb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/resolve/type_ctx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{
use crate::{
ast,
name::ResolvedName,
resolved::{self, Constraint, CurrentConstraints},
resolved::{self, Constraint, CurrentConstraints, HumanName},
workspace::fs::FsNodeId,
};
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -91,7 +91,7 @@ pub fn resolve_constraint(
.at(resolved_type.source));
};

return Ok(Constraint::Trait(*trait_ref));
return Ok(Constraint::Trait(HumanName(name.to_string()), *trait_ref));
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/resolved/datatype/kind/constraint.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
use crate::resolved::TraitRef;
use crate::resolved::{HumanName, TraitRef};
use derivative::Derivative;
use derive_more::IsVariant;
use std::fmt::Display;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, IsVariant, Derivative)]
#[derivative(PartialEq, Eq, Hash)]
pub enum Constraint {
PrimitiveAdd,
Trait(TraitRef),
Trait(
#[derivative(PartialEq = "ignore")]
#[derivative(Hash = "ignore")]
HumanName,
TraitRef,
),
}

impl Display for Constraint {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Constraint::PrimitiveAdd => write!(f, "PrimitiveAdd"),
Constraint::Trait(_) => write!(f, "<user-defined trait>"),
Constraint::Trait(name, _) => write!(f, "{}", name),
}
}
}
2 changes: 1 addition & 1 deletion src/resolved/datatype/kind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl Display for TypeKind {
}

for constaint in constaints {
write!(f, "{:?}", constaint)?;
write!(f, "{}", constaint)?;
}
}
TypeKind::Trait(name, _) => {
Expand Down

0 comments on commit ebeafdb

Please sign in to comment.