Fixed type/generics parsing

This commit is contained in:
2026-06-04 18:50:33 +02:00
parent 6cacfd7135
commit 202f41c0e6
6 changed files with 28 additions and 40 deletions
+7 -12
View File
@@ -208,19 +208,14 @@ pub fn get_static_type_path(path: &Path) -> String {
impl GetRust for TypeExprKind {
fn get_rust(&self) -> String {
match self {
TypeExprKind::Path(path) => get_static_type_path(path),
TypeExprKind::Lifetime(name) => format!("'{}", name.get_rust()),
TypeExprKind::PathParams(path, params) => {
format!(
"{}<{}>",
get_static_type_path(path),
params
.into_iter()
.map(|t| t.get_rust())
.collect::<Vec<_>>()
.join(", ")
)
TypeExprKind::Path(path, generics) => {
if let Some(generics) = generics {
format!("{}{}", get_static_type_path(path), generics.get_rust())
} else {
get_static_type_path(path)
}
}
TypeExprKind::Lifetime(name) => format!("'{}", name.get_rust()),
TypeExprKind::Tuple(types) => format!(
"({})",
types
+5 -3
View File
@@ -235,7 +235,7 @@ impl GenRust for (&Vec<Spanned<FieldDeclStmt>>, &Spanned<ClassConstructor>) {
let mut constructor_params = vec![VarDecl {
name: Pattern::Path(false, Path(vec![Identifier(String::from("self"))])),
type_: Some(TypeExpr(
TypeExprKind::Path(Path(vec![Identifier(String::from("Self"))])),
TypeExprKind::Path(Path(vec![Identifier(String::from("Self"))]), None),
vec![TypePostfix::RefMut],
)),
}];
@@ -423,8 +423,10 @@ impl GenRust for TopLevelKind {
let mut impl_ = impl_.clone();
impl_.item.trait_ = Some(impl_.item.target);
impl_.item.target =
TypeExpr(TypeExprKind::Path(Path(vec![name.clone()])), Vec::new());
impl_.item.target = TypeExpr(
TypeExprKind::Path(Path(vec![name.clone()]), None),
Vec::new(),
);
impl_.gen_rust(ctx, cg);
}