Skip to content

Commit

Permalink
handle godot setting invalid types
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanNano committed Nov 21, 2023
1 parent 32c0f62 commit ecf3d8e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,24 @@ fn derive_set_fields<'a>(public_fields: impl Iterator<Item = &'a FieldOpts> + 'a
Err(err) => return err.write_errors(),
};

let variant_value = quote!(#godot_types::prelude::FromGodot::from_variant(&value));
let variant_value = quote!(#godot_types::prelude::FromGodot::try_from_variant(&value));

let assignment = match opts.set {
Some(setter) => quote_spanned!(setter.span() => #setter(self, #variant_value)),
None => quote!(self.#field_ident = #variant_value),
Some(setter) => quote_spanned!(setter.span() => #setter(self, local_value)),
None => quote!(self.#field_ident = local_value),
};

quote_spanned! {
field_ident.span() =>
#field_name => #assignment,
#field_name => {
let local_value = match #variant_value {
Ok(v) => v,
Err(_) => return false,
};

#assignment;
true
},
}
})
.collect();
Expand All @@ -288,10 +296,8 @@ fn derive_set_fields<'a>(public_fields: impl Iterator<Item = &'a FieldOpts> + 'a
match name.to_string().as_str() {
#set_field_dispatch

_ => return false,
_ => false,
}

true
}
}
}
Expand Down

0 comments on commit ecf3d8e

Please sign in to comment.