Skip to content

Commit 5d85c3d

Browse files
authored
fix(#515): codegen and default problem (#525)
1 parent 29f80e5 commit 5d85c3d

File tree

7 files changed

+32
-52
lines changed

7 files changed

+32
-52
lines changed

Cargo.lock

+13-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/code-generation/thrift/test.thrift

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ struct TestResponse {
1313
}
1414

1515
service TestService {
16-
TestResponse Test (1: TestRequest req),
16+
TestResponse Test (1: TestRequest req, 2: list<TestRequest> reqs),
1717
TestResponse test (1: TestRequest Req),
1818
TestResponse Test2 (1: TestRequest type),
1919
TestResponse Test3 (1: TestRequest self),
2020
}
2121

2222
service testService {
23-
TestResponse Test (1: TestRequest req),
23+
TestResponse Test (1: TestRequest req, 2: list<TestRequest> reqs),
2424
TestResponse test (1: TestRequest Req),
2525
}

volo-build/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "volo-build"
3-
version = "0.10.16"
3+
version = "0.10.17"
44
edition.workspace = true
55
homepage.workspace = true
66
repository.workspace = true

volo-build/src/grpc_backend.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl VoloGrpcBackend {
3434
) -> FastStr {
3535
let ty = self.cx().codegen_item_ty(ty.kind);
3636
let ty_str = if global_path {
37-
format!("volo_gen{}", ty.global_path())
37+
format!("{}", ty.global_path("volo_gen"))
3838
} else {
3939
format!("{}", ty)
4040
};
@@ -54,7 +54,7 @@ impl VoloGrpcBackend {
5454
) -> FastStr {
5555
let ret_ty = self.cx().codegen_item_ty(ty.kind);
5656
let ret_ty_str = if global_path {
57-
format!("volo_gen{}", ret_ty.global_path())
57+
format!("{}", ret_ty.global_path("volo_gen"))
5858
} else {
5959
format!("{}", ret_ty)
6060
};
@@ -402,7 +402,7 @@ impl CodegenBackend for VoloGrpcBackend {
402402
"",
403403
|enum_variant_names| -> "Self::{enum_variant_names}(s) => {{
404404
::volo_grpc::codec::encode::encode(s, compression_encoding)
405-
}},"
405+
}},"
406406
);
407407

408408
let req_recv_from_body = crate::join_multi_strs!(

volo-build/src/thrift_backend.rs

+6-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use pilota_build::{
44
db::RirDatabase,
55
rir::{self, Method},
66
tags::RustWrapperArc,
7-
ty::TyKind,
87
CodegenBackend, Context, DefId, IdentName, Symbol, ThriftBackend,
98
};
109
use quote::format_ident;
@@ -648,11 +647,8 @@ impl pilota_build::CodegenBackend for VoloThriftBackend {
648647
let mut ret_ty = self
649648
.inner
650649
.codegen_item_ty(method.ret.kind.clone())
651-
.global_path()
650+
.global_path("volo_gen")
652651
.to_string();
653-
if need_prepend_volo_gen_path(&method.ret.kind) {
654-
ret_ty = format!("volo_gen{ret_ty}");
655-
}
656652
if let Some(RustWrapperArc(true)) = self
657653
.cx()
658654
.tags(method.ret.tags_id)
@@ -665,13 +661,12 @@ impl pilota_build::CodegenBackend for VoloThriftBackend {
665661
.args
666662
.iter()
667663
.map(|a| {
668-
let ty = self.inner.codegen_item_ty(a.ty.kind.clone()).global_path();
664+
let ty = self
665+
.inner
666+
.codegen_item_ty(a.ty.kind.clone())
667+
.global_path("volo_gen");
669668
let ident = self.cx().rust_name(a.def_id).0.field_ident(); // use the _{rust-style fieldname} without keyword escaping
670-
if need_prepend_volo_gen_path(&a.ty.kind) {
671-
format!("_{ident}: volo_gen{ty}")
672-
} else {
673-
format!("_{ident}: {ty}")
674-
}
669+
format!("_{ident}: {ty}")
675670
})
676671
.join(",");
677672

@@ -701,14 +696,6 @@ impl pilota_build::CodegenBackend for VoloThriftBackend {
701696
}
702697
}
703698

704-
fn need_prepend_volo_gen_path(ty: &TyKind) -> bool {
705-
match ty {
706-
TyKind::Arc(t) => need_prepend_volo_gen_path(&t.kind),
707-
TyKind::Path(_) => true,
708-
_ => false,
709-
}
710-
}
711-
712699
fn rust_name(cx: &Context, def_id: DefId) -> FastStr {
713700
let name = cx.rust_name(def_id);
714701
if cx.names.contains(&def_id) {

volo-thrift/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "volo-thrift"
3-
version = "0.10.4"
3+
version = "0.10.5"
44
edition.workspace = true
55
homepage.workspace = true
66
repository.workspace = true

volo-thrift/src/error.rs

+6
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,9 @@ pub enum MaybeException<T, E> {
229229
Ok(T),
230230
Exception(E),
231231
}
232+
233+
impl<T: Default, E> Default for MaybeException<T, E> {
234+
fn default() -> Self {
235+
MaybeException::Ok(Default::default())
236+
}
237+
}

0 commit comments

Comments
 (0)