fix: get_variant_name was not properly traversing type args on map and data types
This commit is contained in:
parent
2f6c794cdf
commit
7215bf33e9
|
@ -850,18 +850,16 @@ pub fn get_generics_and_type(tipo: &Type, param: &Type) -> Vec<(u64, Arc<Type>)>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_variant_name(new_name: &mut String, t: &Arc<Type>) {
|
pub fn get_variant_name(new_name: &mut String, t: &Arc<Type>) {
|
||||||
new_name.push_str(&format!(
|
new_name.push_str(&if t.is_string() {
|
||||||
"_{}",
|
"_string".to_string()
|
||||||
if t.is_string() {
|
|
||||||
"string".to_string()
|
|
||||||
} else if t.is_int() {
|
} else if t.is_int() {
|
||||||
"int".to_string()
|
"_int".to_string()
|
||||||
} else if t.is_bool() {
|
} else if t.is_bool() {
|
||||||
"bool".to_string()
|
"_bool".to_string()
|
||||||
} else if t.is_bytearray() {
|
} else if t.is_bytearray() {
|
||||||
"bytearray".to_string()
|
"_bytearray".to_string()
|
||||||
} else if t.is_map() {
|
} else if t.is_map() {
|
||||||
let mut full_type = "map".to_string();
|
let mut full_type = "_map".to_string();
|
||||||
let pair_type = &t.get_inner_types()[0];
|
let pair_type = &t.get_inner_types()[0];
|
||||||
let fst_type = &pair_type.get_inner_types()[0];
|
let fst_type = &pair_type.get_inner_types()[0];
|
||||||
let snd_type = &pair_type.get_inner_types()[1];
|
let snd_type = &pair_type.get_inner_types()[1];
|
||||||
|
@ -870,39 +868,31 @@ pub fn get_variant_name(new_name: &mut String, t: &Arc<Type>) {
|
||||||
get_variant_name(&mut full_type, snd_type);
|
get_variant_name(&mut full_type, snd_type);
|
||||||
full_type
|
full_type
|
||||||
} else if t.is_list() {
|
} else if t.is_list() {
|
||||||
let mut full_type = "list".to_string();
|
let mut full_type = "_list".to_string();
|
||||||
let list_type = &t.get_inner_types()[0];
|
let list_type = &t.get_inner_types()[0];
|
||||||
get_variant_name(&mut full_type, list_type);
|
get_variant_name(&mut full_type, list_type);
|
||||||
full_type
|
full_type
|
||||||
} else if t.is_tuple() {
|
} else if t.is_tuple() {
|
||||||
let mut full_type = "tuple".to_string();
|
let mut full_type = "_tuple".to_string();
|
||||||
match &**t {
|
|
||||||
Type::App { .. } => {}
|
|
||||||
Type::Fn { .. } => {}
|
|
||||||
Type::Var { .. } => {}
|
|
||||||
Type::Tuple { elems } => {
|
|
||||||
for elem in elems {
|
|
||||||
get_variant_name(&mut full_type, elem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
full_type
|
|
||||||
} else {
|
|
||||||
let mut full_type = "data".to_string();
|
|
||||||
match &**t {
|
|
||||||
Type::App { args, .. } => {
|
|
||||||
for arg in args {
|
|
||||||
get_variant_name(&mut full_type, arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Type::Fn { .. } => {}
|
|
||||||
Type::Var { .. } => {}
|
|
||||||
Type::Tuple { .. } => {}
|
|
||||||
};
|
|
||||||
|
|
||||||
full_type
|
let inner_types = t.get_inner_types();
|
||||||
|
|
||||||
|
for arg_type in inner_types {
|
||||||
|
get_variant_name(&mut full_type, &arg_type);
|
||||||
}
|
}
|
||||||
));
|
full_type
|
||||||
|
} else if t.is_unbound() {
|
||||||
|
"_unbound".to_string()
|
||||||
|
} else {
|
||||||
|
let mut full_type = "_data".to_string();
|
||||||
|
|
||||||
|
let inner_types = t.get_inner_types();
|
||||||
|
|
||||||
|
for arg_type in inner_types {
|
||||||
|
get_variant_name(&mut full_type, &arg_type);
|
||||||
|
}
|
||||||
|
full_type
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert_constants_to_data(constants: Vec<UplcConstant>) -> Vec<UplcConstant> {
|
pub fn convert_constants_to_data(constants: Vec<UplcConstant>) -> Vec<UplcConstant> {
|
||||||
|
|
|
@ -486,14 +486,12 @@ impl TypeVar {
|
||||||
pub fn get_inner_type(&self) -> Vec<Arc<Type>> {
|
pub fn get_inner_type(&self) -> Vec<Arc<Type>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Link { tipo } => tipo.get_inner_types(),
|
Self::Link { tipo } => tipo.get_inner_types(),
|
||||||
var @ Self::Generic { .. } => {
|
var => {
|
||||||
let tipos = vec![Type::Var {
|
vec![Type::Var {
|
||||||
tipo: RefCell::new(var.clone()).into(),
|
tipo: RefCell::new(var.clone()).into(),
|
||||||
}
|
}
|
||||||
.into()];
|
.into()]
|
||||||
tipos
|
|
||||||
}
|
}
|
||||||
_ => vec![],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue