From ebeafdba4dea346ef43573454f0ec97a71b1289f Mon Sep 17 00:00:00 2001 From: IsaacShelton Date: Tue, 17 Dec 2024 21:18:50 -0600 Subject: [PATCH] Improved error messages for possible function callees that have polymorphic arguments with constraints --- src/resolve/type_ctx/mod.rs | 4 ++-- src/resolved/datatype/kind/constraint.rs | 16 ++++++++++++---- src/resolved/datatype/kind/mod.rs | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/resolve/type_ctx/mod.rs b/src/resolve/type_ctx/mod.rs index d9734db..48f0f07 100644 --- a/src/resolve/type_ctx/mod.rs +++ b/src/resolve/type_ctx/mod.rs @@ -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}; @@ -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)); } } } diff --git a/src/resolved/datatype/kind/constraint.rs b/src/resolved/datatype/kind/constraint.rs index 5398c87..d4e01a5 100644 --- a/src/resolved/datatype/kind/constraint.rs +++ b/src/resolved/datatype/kind/constraint.rs @@ -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, ""), + Constraint::Trait(name, _) => write!(f, "{}", name), } } } diff --git a/src/resolved/datatype/kind/mod.rs b/src/resolved/datatype/kind/mod.rs index ed109ab..8be675f 100644 --- a/src/resolved/datatype/kind/mod.rs +++ b/src/resolved/datatype/kind/mod.rs @@ -190,7 +190,7 @@ impl Display for TypeKind { } for constaint in constaints { - write!(f, "{:?}", constaint)?; + write!(f, "{}", constaint)?; } } TypeKind::Trait(name, _) => {