mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Use type aliases when pretty printing types
This commit is contained in:
parent
20725b862d
commit
695d1eb467
1 changed files with 53 additions and 16 deletions
|
@ -28,22 +28,7 @@ fn write_flat_type(flat_type: FlatType, subs: &mut Subs, buf: &mut String, use_p
|
|||
|
||||
match flat_type {
|
||||
Apply(module_name, type_name, args) => {
|
||||
let write_parens = use_parens && !args.is_empty();
|
||||
|
||||
if write_parens {
|
||||
buf.push_str("(");
|
||||
}
|
||||
|
||||
buf.push_str(&format!("{}.{}", module_name, type_name));
|
||||
|
||||
for arg in args {
|
||||
buf.push_str(" ");
|
||||
write_content(subs.get(arg).content, subs, buf, true);
|
||||
}
|
||||
|
||||
if write_parens {
|
||||
buf.push_str(")");
|
||||
}
|
||||
write_apply(module_name, type_name, args, subs, buf, use_parens)
|
||||
},
|
||||
EmptyRecord => buf.push_str(EMPTY_RECORD),
|
||||
Func(args, ret) => {
|
||||
|
@ -58,6 +43,58 @@ fn write_flat_type(flat_type: FlatType, subs: &mut Subs, buf: &mut String, use_p
|
|||
}
|
||||
}
|
||||
|
||||
fn write_apply(module_name: String, type_name: String, args: Vec<Variable>, subs: &mut Subs, buf: &mut String, use_parens: bool) {
|
||||
let write_parens = use_parens && !args.is_empty();
|
||||
|
||||
// Hardcoded type aliases
|
||||
if module_name == "Num" && type_name == "Num" {
|
||||
let arg = args.into_iter().next().unwrap_or_else(|| {
|
||||
panic!("Num did not have any type parameters somehow.")
|
||||
});
|
||||
let arg_content = subs.get(arg).content;
|
||||
let mut arg_param = String::new();
|
||||
|
||||
write_content(arg_content, subs, &mut arg_param, true);
|
||||
|
||||
if arg_param == "Int.Integer" {
|
||||
buf.push_str("Int");
|
||||
} else if arg_param == "Float.FloatingPoint" {
|
||||
buf.push_str("Float");
|
||||
} else {
|
||||
if write_parens { buf.push_str("("); }
|
||||
|
||||
buf.push_str("Num ");
|
||||
buf.push_str(&arg_param);
|
||||
|
||||
if write_parens { buf.push_str(")"); }
|
||||
}
|
||||
} else if module_name == "List" && type_name == "List" {
|
||||
if write_parens { buf.push_str("("); }
|
||||
|
||||
buf.push_str("List ");
|
||||
|
||||
let arg = args.into_iter().next().unwrap_or_else(|| {
|
||||
panic!("List did not have any type parameters somehow.")
|
||||
});
|
||||
let arg_content = subs.get(arg).content;
|
||||
|
||||
write_content(arg_content, subs, buf, true);
|
||||
|
||||
if write_parens { buf.push_str(")"); }
|
||||
} else {
|
||||
if write_parens { buf.push_str("("); }
|
||||
|
||||
buf.push_str(&format!("{}.{}", module_name, type_name));
|
||||
|
||||
for arg in args {
|
||||
buf.push_str(" ");
|
||||
write_content(subs.get(arg).content, subs, buf, true);
|
||||
}
|
||||
|
||||
if write_parens { buf.push_str(")"); }
|
||||
}
|
||||
}
|
||||
|
||||
fn write_fn(args: Vec<Variable>, ret: Variable, subs: &mut Subs, buf: &mut String, use_parens: bool) {
|
||||
let mut needs_comma = false;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue