iter 22-tidy.6.1 fixup: cover abstract-method + instance-override branches; doc + fallback comments
This commit is contained in:
@@ -321,6 +321,8 @@ fn write_const_def(out: &mut String, cd: &ConstDef, level: usize) {
|
|||||||
write_term(out, &cd.value, level);
|
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) {
|
fn write_class_def(out: &mut String, c: &ClassDef, level: usize) {
|
||||||
write_doc(out, &c.doc, level);
|
write_doc(out, &c.doc, level);
|
||||||
indent(out, level);
|
indent(out, level);
|
||||||
@@ -340,6 +342,9 @@ fn write_class_def(out: &mut String, c: &ClassDef, level: usize) {
|
|||||||
out.push('}');
|
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) {
|
fn write_class_method(out: &mut String, m: &ClassMethod, level: usize) {
|
||||||
indent(out, level);
|
indent(out, level);
|
||||||
out.push_str("fn ");
|
out.push_str("fn ");
|
||||||
@@ -374,6 +379,9 @@ fn write_class_method(out: &mut String, m: &ClassMethod, level: usize) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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(") -> ");
|
out.push_str(") -> ");
|
||||||
write_type(out, &m.ty);
|
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) {
|
fn write_instance_def(out: &mut String, i: &InstanceDef, level: usize) {
|
||||||
write_doc(out, &i.doc, level);
|
write_doc(out, &i.doc, level);
|
||||||
indent(out, level);
|
indent(out, level);
|
||||||
@@ -404,6 +414,9 @@ fn write_instance_def(out: &mut String, i: &InstanceDef, level: usize) {
|
|||||||
out.push('}');
|
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) {
|
fn write_instance_method(out: &mut String, m: &InstanceMethod, level: usize) {
|
||||||
indent(out, level);
|
indent(out, level);
|
||||||
out.push_str("fn ");
|
out.push_str("fn ");
|
||||||
|
|||||||
@@ -76,3 +76,8 @@ fn snapshot_bench_list_sum() {
|
|||||||
fn snapshot_test_22b3_default_e2e() {
|
fn snapshot_test_22b3_default_e2e() {
|
||||||
check_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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user