From ab0e97a9a4822980d3979753312e47c667c30fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Mon, 3 Feb 2025 15:53:53 +0100 Subject: [PATCH] Tweaks and fixes --- src/ast/printer.rs | 3 --- src/type_checker.rs | 5 +++++ src/type_checker/ty.rs | 11 +++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/ast/printer.rs b/src/ast/printer.rs index 874c970..a1b9b26 100644 --- a/src/ast/printer.rs +++ b/src/ast/printer.rs @@ -120,9 +120,6 @@ impl TypeDeclRhs { impl FunDecl { pub fn print(&self, buffer: &mut String, indent: u32) { - if self.body.is_none() { - buffer.push_str("prim "); - } self.sig.print(&self.parent_ty, &self.name.node, buffer); if let Some(body) = &self.body { buffer.push('\n'); diff --git a/src/type_checker.rs b/src/type_checker.rs index 04b3dca..db0e480 100644 --- a/src/type_checker.rs +++ b/src/type_checker.rs @@ -569,6 +569,9 @@ fn collect_schemes( trait_decl.node.type_param_kinds.len() ); + // Note: this needs to be a `Vec` instead of a `Map` as we need to add trait context + // before the function context in the method type schemes, and type parameters in + // the trait context need to be in the same order as the trait declaration. let trait_quantified_vars: Vec<(Id, Kind)> = trait_decl .node .type_params @@ -593,6 +596,8 @@ fn collect_schemes( for fun in &trait_decl.node.items { // Add trait type parameters and predicate to the function context before // converting. + // Note: This needs to be a `Vec` instead of `Map`. See the comments around + // `trait_quantified_vars`. let mut fun_type_params = trait_quantified_vars.clone(); fun_type_params.extend(fun.node.sig.context.type_params.clone()); diff --git a/src/type_checker/ty.rs b/src/type_checker/ty.rs index 020a43a..5fd3ec6 100644 --- a/src/type_checker/ty.rs +++ b/src/type_checker/ty.rs @@ -13,7 +13,10 @@ use smol_str::SmolStr; #[derive(Debug, Clone)] pub struct Scheme { /// Generalized variables with kinds. - pub(super) quantified_vars: Map, + /// + /// When the scheme is for a trait method, the first type parameters will be the type parameters + /// for the trait, in the right order. + pub(super) quantified_vars: Vec<(Id, Kind)>, /// Predicates. pub(super) preds: Set, @@ -318,7 +321,7 @@ impl Scheme { quantified_vars: self .quantified_vars .iter() - .filter(|(qvar, _)| *qvar != var) + .filter(|(qvar, _)| qvar != var) .map(|(qvar, kind)| (qvar.clone(), kind.clone())) .collect(), preds: self @@ -968,7 +971,7 @@ use std::fmt; impl fmt::Display for Ty { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { + match self.normalize(&Default::default()) { Ty::Con(id) => write!(f, "{}", id), Ty::Var(var_ref) => write!(f, "_{}", var_ref.id()), @@ -995,7 +998,7 @@ impl fmt::Display for Ty { RecordOrVariant::Variant => ('[', ']'), }; - if *is_row { + if is_row { write!(f, "row")?; }