Fix has on non-inherent fields (#2745)

This commit is contained in:
frozolotl 2023-11-24 05:41:38 -05:00 committed by GitHub
parent 07ae4fb923
commit e5470401f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -731,12 +731,18 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
quote! {
<#elem as #model::ElementFields>::Fields::#name => None,
}
} else {
} else if field.inherent() {
quote! {
<#elem as #model::ElementFields>::Fields::#name => Some(
::typst::eval::IntoValue::into_value(self.#field_ident.clone())
),
}
} else {
quote! {
<#elem as #model::ElementFields>::Fields::#name => {
self.#field_ident.clone().map(::typst::eval::IntoValue::into_value)
}
}
}
});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -1,3 +1,17 @@
// Tests for field introspection.
---
// Verify that non-inherent fields are hidden if not set.
#show figure: it => [
`repr(it)`: #repr(it) \
`it.has("gap"): `#repr(it.has("gap")) \
]
#figure[]
#figure([], gap: 1pt)
---
// Integrated test for content fields.
#let compute(equation, ..vars) = {