iter 22-tidy.6.1 fixup: cover abstract-method + instance-override branches; doc + fallback comments

This commit is contained in:
2026-05-10 04:54:22 +02:00
parent d1c992d49a
commit 788c9808dd
3 changed files with 35 additions and 0 deletions
+13
View File
@@ -321,6 +321,8 @@ fn write_const_def(out: &mut String, cd: &ConstDef, level: usize) {
write_term(out, &cd.value, level);
}
/// Render a class declaration in Rust-flavoured Form-B:
/// `class Name a [extends Super] { <methods> }`.
fn write_class_def(out: &mut String, c: &ClassDef, level: usize) {
write_doc(out, &c.doc, level);
indent(out, level);
@@ -340,6 +342,9 @@ fn write_class_def(out: &mut String, c: &ClassDef, level: usize) {
out.push('}');
}
/// Render one method line of a class: signature plus optional
/// `default { <body> }`. Class methods carry no parameter names
/// in the AST, so slots are named `x`, `x1`, ….
fn write_class_method(out: &mut String, m: &ClassMethod, level: usize) {
indent(out, level);
out.push_str("fn ");
@@ -374,6 +379,9 @@ fn write_class_method(out: &mut String, m: &ClassMethod, level: usize) {
}
}
} else {
// Defensive fallback: a non-Fn class-method type. Render the
// bare type so nothing crashes; this path is unreachable for
// typechecked input.
out.push_str(") -> ");
write_type(out, &m.ty);
}
@@ -389,6 +397,8 @@ fn write_class_method(out: &mut String, m: &ClassMethod, level: usize) {
}
}
/// Render an instance declaration in Form-B:
/// `instance Class Type { <method bodies> }`.
fn write_instance_def(out: &mut String, i: &InstanceDef, level: usize) {
write_doc(out, &i.doc, level);
indent(out, level);
@@ -404,6 +414,9 @@ fn write_instance_def(out: &mut String, i: &InstanceDef, level: usize) {
out.push('}');
}
/// Render one method body of an instance: `fn name { <body> }`.
/// The signature is recoverable from the class declaration via
/// `InstanceDef.class` lookup, so it is intentionally elided.
fn write_instance_method(out: &mut String, m: &InstanceMethod, level: usize) {
indent(out, level);
out.push_str("fn ");
+5
View File
@@ -76,3 +76,8 @@ fn snapshot_bench_list_sum() {
fn snapshot_test_22b3_default_e2e() {
check_snapshot("test_22b3_default_e2e");
}
#[test]
fn snapshot_test_22b2_instance_present() {
check_snapshot("test_22b2_instance_present");
}
@@ -0,0 +1,17 @@
// module test_22b2_instance_present
class Show a {
fn show(x: a) -> Str
}
instance Show Int {
fn show {
|x: a| -> Str {
"n"
}
}
}
fn main() -> Str {
show(42)
}