nac3core: fix broken top level test due to hashmap order

This commit is contained in:
ychenfo 2021-09-09 00:44:56 +08:00
parent 5a1a8ecee3
commit 2ce507964c
3 changed files with 10 additions and 6 deletions

View File

@ -43,7 +43,12 @@ impl TopLevelDef {
"Function {{\nname: {:?},\nsig: {:?},\nvar_id: {:?}\n}}", "Function {{\nname: {:?},\nsig: {:?},\nvar_id: {:?}\n}}",
name, name,
unifier.stringify(*signature, obj_to_name, var_to_name), unifier.stringify(*signature, obj_to_name, var_to_name),
var_id {
// NOTE: preserve the order for debug output and test
let mut r = var_id.clone();
r.sort_unstable();
r
}
), ),
TopLevelDef::Initializer { class_id } => format!("Initializer {{ {:?} }}", class_id), TopLevelDef::Initializer { class_id } => format!("Initializer {{ {:?} }}", class_id),
} }

View File

@ -588,7 +588,7 @@ impl TopLevelComposer {
} }
println!("type_var_to_concrete_def3: {:?}\n", type_var_to_concrete_def); println!("type_var_to_concrete_def3: {:?}\n", type_var_to_concrete_def);
// unification of previously assigned typevar // unification of previously assigned typevar
for (ty, def) in type_var_to_concrete_def { for (ty, def) in type_var_to_concrete_def {
println!( println!(
@ -864,8 +864,7 @@ impl TopLevelComposer {
)? )?
}; };
// find type vars within this method parameter type annotation // find type vars within this method parameter type annotation
let type_vars_within = let type_vars_within = get_type_var_contained_in_type_annotation(&type_ann);
get_type_var_contained_in_type_annotation(&type_ann);
// handle the class type var and the method type var // handle the class type var and the method type var
for type_var_within in type_vars_within { for type_var_within in type_vars_within {
if let TypeAnnotation::TypeVarKind(ty) = type_var_within { if let TypeAnnotation::TypeVarKind(ty) = type_var_within {
@ -987,7 +986,7 @@ impl TopLevelComposer {
unreachable!("must be type var annotation"); unreachable!("must be type var annotation");
} }
} }
// TODO: allow class have field which type refers to Self type? // TODO: allow class have field which type refers to Self type?
type_var_to_concrete_def type_var_to_concrete_def
.insert(dummy_field_type, annotation); .insert(dummy_field_type, annotation);

View File

@ -342,7 +342,7 @@ fn test_simple_class_analyze(source: Vec<&str>, res: Vec<&str>) {
let tvar_v = composer let tvar_v = composer
.unifier .unifier
.get_fresh_var_with_range(&[composer.primitives_ty.bool, composer.primitives_ty.int32]); .get_fresh_var_with_range(&[composer.primitives_ty.bool, composer.primitives_ty.int32]);
println!("t: {}, {:?}", tvar_t.1, tvar_t.0); println!("t: {}, {:?}", tvar_t.1, tvar_t.0);
println!("v: {}, {:?}\n", tvar_v.1, tvar_v.0); println!("v: {}, {:?}\n", tvar_v.1, tvar_v.0);