nac3core: clean up, fix broken test
This commit is contained in:
parent
f1013d9a17
commit
917d447605
@ -551,7 +551,7 @@ impl TopLevelComposer {
|
||||
}
|
||||
}
|
||||
|
||||
println!("type_var_to_concrete_def1: {:?}", type_var_to_concrete_def);
|
||||
// println!("type_var_to_concrete_def1: {:?}", type_var_to_concrete_def);
|
||||
|
||||
// handle the inheritanced methods and fields
|
||||
let mut current_ancestor_depth: usize = 2;
|
||||
@ -587,19 +587,19 @@ 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
|
||||
for (ty, def) in type_var_to_concrete_def {
|
||||
println!(
|
||||
"{:?}_{} -> {:?}\n",
|
||||
ty,
|
||||
unifier.stringify(ty,
|
||||
&mut |id| format!("class{}", id),
|
||||
&mut |id| format!("tvar{}", id)
|
||||
),
|
||||
def
|
||||
);
|
||||
// println!(
|
||||
// "{:?}_{} -> {:?}\n",
|
||||
// ty,
|
||||
// unifier.stringify(ty,
|
||||
// &mut |id| format!("class{}", id),
|
||||
// &mut |id| format!("tvar{}", id)
|
||||
// ),
|
||||
// def
|
||||
// );
|
||||
let target_ty =
|
||||
get_type_from_type_annotation_kinds(&temp_def_list, unifier, primitives, &def)?;
|
||||
unifier.unify(ty, target_ty)?;
|
||||
|
@ -213,10 +213,13 @@ pub fn get_type_from_type_annotation_kinds(
|
||||
// NOTE: check for compatible range here
|
||||
let mut result: HashMap<u32, Type> = HashMap::new();
|
||||
for (tvar, p) in type_vars.iter().zip(param_ty) {
|
||||
if let TypeEnum::TVar { id, range, meta: TypeVarMeta::Generic } = unifier.get_ty(*tvar).as_ref() {
|
||||
if let TypeEnum::TVar { id, range, meta: TypeVarMeta::Generic } =
|
||||
unifier.get_ty(*tvar).as_ref()
|
||||
{
|
||||
let ok: bool = {
|
||||
// NOTE: create a temp type var and unify to check compatibility
|
||||
let temp = unifier.get_fresh_var_with_range(range.borrow().as_slice());
|
||||
let temp =
|
||||
unifier.get_fresh_var_with_range(range.borrow().as_slice());
|
||||
unifier.unify(temp.0, p).is_ok()
|
||||
};
|
||||
if ok {
|
||||
@ -230,7 +233,7 @@ pub fn get_type_from_type_annotation_kinds(
|
||||
&mut |id| format!("tvar{}", id)
|
||||
),
|
||||
*id
|
||||
))
|
||||
));
|
||||
}
|
||||
} else {
|
||||
unreachable!("must be generic type var")
|
||||
@ -250,16 +253,16 @@ pub fn get_type_from_type_annotation_kinds(
|
||||
(name.clone(), subst_ty)
|
||||
}));
|
||||
|
||||
println!("tobj_fields: {:?}", tobj_fields);
|
||||
println!(
|
||||
"{:?}: {}\n",
|
||||
tobj_fields.get("__init__").unwrap(),
|
||||
unifier.stringify(
|
||||
*tobj_fields.get("__init__").unwrap(),
|
||||
&mut |id| format!("class{}", id),
|
||||
&mut |id| format!("tvar{}", id)
|
||||
)
|
||||
);
|
||||
// println!("tobj_fields: {:?}", tobj_fields);
|
||||
// println!(
|
||||
// "{:?}: {}\n",
|
||||
// tobj_fields.get("__init__").unwrap(),
|
||||
// unifier.stringify(
|
||||
// *tobj_fields.get("__init__").unwrap(),
|
||||
// &mut |id| format!("class{}", id),
|
||||
// &mut |id| format!("tvar{}", id)
|
||||
// )
|
||||
// );
|
||||
|
||||
Ok(unifier.add_ty(TypeEnum::TObj {
|
||||
obj_id: *id,
|
||||
@ -342,13 +345,15 @@ pub fn get_type_var_contained_in_type_annotation(ann: &TypeAnnotation) -> Vec<Ty
|
||||
result.extend(get_type_var_contained_in_type_annotation(p));
|
||||
}
|
||||
}
|
||||
TypeAnnotation::ListKind(ann) => result.extend(get_type_var_contained_in_type_annotation(ann.as_ref())),
|
||||
TypeAnnotation::ListKind(ann) => {
|
||||
result.extend(get_type_var_contained_in_type_annotation(ann.as_ref()))
|
||||
}
|
||||
TypeAnnotation::TupleKind(anns) => {
|
||||
for a in anns {
|
||||
result.extend(get_type_var_contained_in_type_annotation(a));
|
||||
}
|
||||
}
|
||||
TypeAnnotation::PrimitiveKind( .. ) => {}
|
||||
TypeAnnotation::PrimitiveKind(..) => {}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ impl TestEnvironment {
|
||||
|
||||
"},
|
||||
[("a", "fn[[x=bool], bool]"), ("b", "fn[[x=int32], int32]"), ("c", "bool"),
|
||||
("d", "int32"), ("foo1", "Foo[bool]"), ("foo2", "Foo[int32]")].iter().cloned().collect(),
|
||||
("d", "int32"), ("foo1", "Foo[1->bool]"), ("foo2", "Foo[1->int32]")].iter().cloned().collect(),
|
||||
&[]
|
||||
; "obj test")]
|
||||
#[test_case(indoc! {"
|
||||
|
@ -714,10 +714,9 @@ impl Unifier {
|
||||
let name = obj_to_name(obj_id.0);
|
||||
let params = params.borrow();
|
||||
if !params.is_empty() {
|
||||
let params =
|
||||
params.iter().map(|(id, v)|
|
||||
format!("{}->{}", *id, self.stringify(*v, obj_to_name, var_to_name))
|
||||
);
|
||||
let params = params.iter().map(|(id, v)| {
|
||||
format!("{}->{}", *id, self.stringify(*v, obj_to_name, var_to_name))
|
||||
});
|
||||
// NOTE: sort to preserve order
|
||||
let mut params = params.sorted();
|
||||
format!("{}[{}]", name, params.join(", "))
|
||||
|
Loading…
Reference in New Issue
Block a user