From 74f881392c9b305b53f4a9f4d35137eb74d33ae5 Mon Sep 17 00:00:00 2001 From: IsaacShelton Date: Tue, 17 Dec 2024 21:26:31 -0600 Subject: [PATCH] Fixed issue with some types incorrectly being determined to satisfy user-defined traits --- src/resolved/function.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/resolved/function.rs b/src/resolved/function.rs index 1369a8e..4b58b27 100644 --- a/src/resolved/function.rs +++ b/src/resolved/function.rs @@ -9,7 +9,7 @@ pub struct CurrentConstraints { impl CurrentConstraints { pub fn satisfies(&self, ty: &Type, constraint: &Constraint) -> bool { match constraint { - Constraint::PrimitiveAdd | Constraint::Trait(..) => match &ty.kind { + Constraint::PrimitiveAdd => match &ty.kind { TypeKind::Integer(..) | TypeKind::CInteger(..) | TypeKind::Floating(..) => true, TypeKind::Polymorph(name, constraints) => { constraints.contains(constraint) @@ -20,6 +20,18 @@ impl CurrentConstraints { } _ => false, }, + Constraint::Trait(name, _trait_ref) => match &ty.kind { + TypeKind::Polymorph(name, constraints) => { + constraints.contains(constraint) + || self + .constraints + .get(name) + .map_or(false, |in_scope| in_scope.contains(constraint)) + } + _ => { + todo!("test if user-defined trait '{}' is satisfied", name) + } + }, } } }