diff --git a/crates/ailang-prose/src/lib.rs b/crates/ailang-prose/src/lib.rs index 0c71812..5fafc5f 100644 --- a/crates/ailang-prose/src/lib.rs +++ b/crates/ailang-prose/src/lib.rs @@ -238,9 +238,11 @@ fn write_fn_def(out: &mut String, fd: &FnDef, level: usize) { // `Type::Fn` or a `Type::Forall` wrapping one — in the latter case // we render the forall on the line above and then the inner fn // signature. - let (forall_vars, fn_ty) = match &fd.ty { - Type::Forall { vars, constraints: _, body } => (Some(vars.clone()), body.as_ref()), - other => (None, other), + let (forall_vars, forall_constraints, fn_ty) = match &fd.ty { + Type::Forall { vars, constraints, body } => { + (Some(vars.clone()), constraints.clone(), body.as_ref()) + } + other => (None, Vec::new(), other), }; if let Some(vars) = &forall_vars { @@ -252,7 +254,19 @@ fn write_fn_def(out: &mut String, fd: &FnDef, level: usize) { } out.push_str(v); } - out.push_str(">\n"); + out.push('>'); + if !forall_constraints.is_empty() { + out.push_str(" where "); + for (i, c) in forall_constraints.iter().enumerate() { + if i > 0 { + out.push_str(", "); + } + out.push_str(&c.class); + out.push(' '); + write_type(out, &c.type_); + } + } + out.push('\n'); } indent(out, level); diff --git a/crates/ailang-prose/tests/snapshot.rs b/crates/ailang-prose/tests/snapshot.rs index 075e818..b64380d 100644 --- a/crates/ailang-prose/tests/snapshot.rs +++ b/crates/ailang-prose/tests/snapshot.rs @@ -81,3 +81,8 @@ fn snapshot_test_22b3_default_e2e() { fn snapshot_test_22b2_instance_present() { check_snapshot("test_22b2_instance_present"); } + +#[test] +fn snapshot_test_22b2_constraint_declared_via_superclass() { + check_snapshot("test_22b2_constraint_declared_via_superclass"); +} diff --git a/examples/test_22b2_constraint_declared_via_superclass.prose.txt b/examples/test_22b2_constraint_declared_via_superclass.prose.txt new file mode 100644 index 0000000..15c5233 --- /dev/null +++ b/examples/test_22b2_constraint_declared_via_superclass.prose.txt @@ -0,0 +1,14 @@ +// module test_22b2_constraint_declared_via_superclass + +class Eq a { + fn eq(x: a, x1: a) -> Bool +} + +class Ord a extends Eq { + fn lt(x: a, x1: a) -> Bool +} + +forall where Ord a +fn uses_eq_via_ord(x: a, y: a) -> Bool { + eq(x, y) +}