Skip to content

Commit

Permalink
Tweaks and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 committed Feb 3, 2025
1 parent a33e854 commit ab0e97a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/ast/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions src/type_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());

Expand Down
11 changes: 7 additions & 4 deletions src/type_checker/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use smol_str::SmolStr;
#[derive(Debug, Clone)]
pub struct Scheme {
/// Generalized variables with kinds.
pub(super) quantified_vars: Map<Id, Kind>,
///
/// 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<Pred>,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()),
Expand All @@ -995,7 +998,7 @@ impl fmt::Display for Ty {
RecordOrVariant::Variant => ('[', ']'),
};

if *is_row {
if is_row {
write!(f, "row")?;
}

Expand Down

0 comments on commit ab0e97a

Please sign in to comment.