Skip to content

Commit

Permalink
fix: err
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy committed Mar 6, 2024
1 parent 657b91c commit 37200b5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ pub(crate) fn generate_api_methods(
}

// TODO move
pub(crate) fn dart_constructor_postfix(name: &NamespacedName, all_funcs: &[IrFunc]) -> String {
pub(crate) fn dart_constructor_postfix(
name: &NamespacedName,
all_funcs: &[IrFunc],
) -> &'static str {
if has_default_dart_constructor(name, all_funcs) {
".raw"
} else {
""
};
}
}

fn has_default_dart_constructor(name: &NamespacedName, all_funcs: &[IrFunc]) -> bool {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::codegen::generator::api_dart::spec_generator::class::method::{
dart_constructor_postfix, generate_api_methods, has_default_dart_constructor,
dart_constructor_postfix, generate_api_methods,
};
use crate::codegen::generator::api_dart::spec_generator::class::ty::ApiDartGeneratorClassTrait;
use crate::codegen::generator::api_dart::spec_generator::class::ApiDartGeneratedClass;
Expand All @@ -21,14 +21,20 @@ impl<'a> ApiDartGeneratorClassTrait for StructRefApiDartGenerator<'a> {
Some(ApiDartGeneratedClass {
namespace: src.name.namespace.clone(),
code: if src.using_freezed() {
self.generate_mode_freezed(src, &comments, &metadata, &methods, constructor_postfix)
self.generate_mode_freezed(
src,
&comments,
&metadata,
&methods,
&constructor_postfix,
)
} else {
self.generate_mode_non_freezed(
src,
&comments,
&metadata,
&methods,
constructor_postfix,
&constructor_postfix,
)
},
needs_freezed: src.using_freezed(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl GeneralizedStructGenerator {
let ctor = match self.mode {
Struct => lang.call_constructor(
&override_struct_name.unwrap_or_else(|| self.st.name.style(lang)),
dart_constructor_postfix(&src.name, TODO),
Some(dart_constructor_postfix(&self.st.name, TODO)),
&(self.st.fields.iter())
.map(|x| x.name.style(lang))
.collect_vec(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'a> WireDartCodecDcoGeneratorDecoderTrait for StructRefWireDartCodecDcoGene
format!(
"{cast}
{safe_check}
return {name}{dotted_ctor_name}({inner});",
return {name}{ctor_postfix}({inner});",
name = s.name.name,
)
}
Expand Down

0 comments on commit 37200b5

Please sign in to comment.