Fix defaults on #[synthesized] fields (#2825)

Fixes #2821
This commit is contained in:
Sébastien d'Herbais de Thun 2023-12-04 11:44:34 +01:00 committed by GitHub
parent 9926a594e7
commit 7f10d3282e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 5 deletions

View File

@ -723,7 +723,7 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
quote! {
<#elem as #foundations::ElementFields>::Fields::#name => None,
}
} else if field.inherent() {
} else if field.inherent() || (field.synthesized && field.default.is_some()) {
quote! {
<#elem as #foundations::ElementFields>::Fields::#name => Some(
#foundations::IntoValue::into_value(self.#field_ident.clone())
@ -748,7 +748,7 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
quote! {
<#elem as #foundations::ElementFields>::Fields::#name => false,
}
} else if field.inherent() {
} else if field.inherent() || (field.synthesized && field.default.is_some()) {
quote! {
<#elem as #foundations::ElementFields>::Fields::#name => true,
}
@ -867,6 +867,14 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
quote! { ::ecow::EcoString::inline(#name).into() }
};
if field.synthesized && field.default.is_some() {
quote! {
fields.insert(
#field_call,
#foundations::IntoValue::into_value(self.#field_ident.clone())
);
}
} else {
quote! {
if let Some(value) = &self.#field_ident {
fields.insert(
@ -875,6 +883,7 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
);
}
}
}
});
let location = element

View File

@ -0,0 +1,9 @@
// Issue #2821: Setting a figure's supplement to none removes the field
// Ref: false
---
#show figure.caption: it => {
assert(it.has("supplement"))
assert(it.supplement == none)
}
#figure([], caption: [], supplement: none)