mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
Consolidate variable pretty printing
This commit is contained in:
parent
3de35f7aa2
commit
a9507cf917
7 changed files with 28 additions and 43 deletions
|
@ -29,7 +29,7 @@ mod test_load {
|
|||
use roc_reporting::report::RenderTarget;
|
||||
use roc_reporting::report::RocDocAllocator;
|
||||
use roc_target::TargetInfo;
|
||||
use roc_types::pretty_print::{content_to_string, name_all_type_vars};
|
||||
use roc_types::pretty_print::name_and_print_var;
|
||||
use roc_types::subs::Subs;
|
||||
use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
@ -237,10 +237,7 @@ mod test_load {
|
|||
expected_types: &mut HashMap<&str, &str>,
|
||||
) {
|
||||
for (symbol, expr_var) in &def.pattern_vars {
|
||||
let named_result = name_all_type_vars(*expr_var, subs);
|
||||
|
||||
let content = subs.get_content_without_compacting(*expr_var);
|
||||
let actual_str = content_to_string(content, subs, home, interns, named_result);
|
||||
let actual_str = name_and_print_var(*expr_var, subs, home, interns);
|
||||
let fully_qualified = symbol.fully_qualified(interns, home).to_string();
|
||||
let expected_type = expected_types
|
||||
.remove(fully_qualified.as_str())
|
||||
|
|
|
@ -19,7 +19,7 @@ mod solve_expr {
|
|||
use roc_region::all::{LineColumn, LineColumnRegion, LineInfo, Region};
|
||||
use roc_reporting::report::{can_problem, type_problem, RocDocAllocator};
|
||||
use roc_solve::solve::TypeError;
|
||||
use roc_types::pretty_print::{content_to_string, name_all_type_vars};
|
||||
use roc_types::pretty_print::name_and_print_var;
|
||||
use std::path::PathBuf;
|
||||
|
||||
// HELPERS
|
||||
|
@ -174,10 +174,7 @@ mod solve_expr {
|
|||
|
||||
debug_assert!(exposed_to_host.len() == 1);
|
||||
let (_symbol, variable) = exposed_to_host.into_iter().next().unwrap();
|
||||
let named_result = name_all_type_vars(variable, subs);
|
||||
let content = subs.get_content_without_compacting(variable);
|
||||
|
||||
let actual_str = content_to_string(content, subs, home, &interns, named_result);
|
||||
let actual_str = name_and_print_var(variable, subs, home, &interns);
|
||||
|
||||
Ok((type_problems, can_problems, actual_str))
|
||||
}
|
||||
|
@ -276,9 +273,7 @@ mod solve_expr {
|
|||
let var = find_type_at(region, &decls)
|
||||
.expect(&format!("No type for {} ({:?})!", &text, region));
|
||||
|
||||
let named_result = name_all_type_vars(var, subs);
|
||||
let content = subs.get_content_without_compacting(var);
|
||||
let actual_str = content_to_string(content, subs, home, &interns, named_result);
|
||||
let actual_str = name_and_print_var(var, subs, home, &interns);
|
||||
|
||||
solved_queries.push(format!("{} : {}", text, actual_str));
|
||||
}
|
||||
|
|
|
@ -336,7 +336,7 @@ struct Context<'a> {
|
|||
recursion_structs_to_expand: Vec<Variable>,
|
||||
}
|
||||
|
||||
pub fn content_to_string(
|
||||
fn content_to_string(
|
||||
content: &Content,
|
||||
subs: &Subs,
|
||||
home: ModuleId,
|
||||
|
@ -364,6 +364,17 @@ pub fn content_to_string(
|
|||
buf
|
||||
}
|
||||
|
||||
pub fn name_and_print_var(
|
||||
var: Variable,
|
||||
subs: &mut Subs,
|
||||
home: ModuleId,
|
||||
interns: &Interns,
|
||||
) -> String {
|
||||
let named_result = name_all_type_vars(var, subs);
|
||||
let content = subs.get_content_without_compacting(var);
|
||||
content_to_string(content, subs, home, interns, named_result)
|
||||
}
|
||||
|
||||
pub fn get_single_arg<'a>(subs: &'a Subs, args: &'a AliasVariables) -> &'a Content {
|
||||
debug_assert_eq!(args.len(), 1);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue