bevyengine/bevy · error · syn::Error
Expected a boolean value
Error message
Expected a boolean value
What it means
The boolean reflect attributes (`#[reflect(from_reflect = ...)]`, `#[reflect(type_path = ...)]`) are parsed by `extract_bool` (crates/bevy_reflect/derive/src/container_attributes.rs:665), which only accepts a literal `true`/`false` (`syn::Lit::Bool`). Any other expression — a string, an integer, a path, or a constant — fails with the compile error "Expected a boolean value" pointing at the value's span.
Source
Thrown at crates/bevy_reflect/derive/src/container_attributes.rs:673
pub fn is_opaque(&self) -> bool {
self.is_opaque
}
}
/// Extract a boolean value from an expression.
///
/// The mapper exists so that the caller can conditionally choose to use the given
/// value or supply their own.
fn extract_bool(
value: &Expr,
mut mapper: impl FnMut(&LitBool) -> LitBool,
) -> Result<LitBool, syn::Error> {
match value {
Expr::Lit(syn::ExprLit {
lit: syn::Lit::Bool(lit),
..
}) => Ok(mapper(lit)),
_ => Err(syn::Error::new(value.span(), "Expected a boolean value")),
}
}
View on GitHub (pinned to 396ca72708)
Solutions
- Use the literal keywords `true` or `false` directly
- If the value comes from a macro, pass the literal through as tokens (e.g. a `bool`-typed macro rule `$v:literal`) instead of computing it
Example fix
// before #[reflect(from_reflect = "false")] // or = 1, or = SOME_CONST // after #[reflect(from_reflect = false)]
Defensive patterns
Strategy: validation
Validate before calling
null
Prevention
- Attribute values must be literal `true`/`false` tokens — never strings, numbers, or constants
- In declarative macros, pass booleans as `$v:literal` tokens rather than interpolating computed values
When it happens
Trigger: Writing `#[reflect(type_path = "false")]`, `#[reflect(from_reflect = 1)]`, `#[reflect(from_reflect = SHOULD_DERIVE)]`, or any non-literal-boolean expression as the attribute value.
Common situations: Porting old attribute syntax that used other literal kinds; macro code substituting a variable into the attribute value (proc macros see tokens, not runtime values); typoed values.
Related errors
- `#[reflect("...")]` must use parentheses `(` and `)`
- `#[type_path = "..."]` must be a string literal
- conflicting type data registration
- `from_reflect` already set to {}
- `type_path` already set to {}
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/a48f1706379720ee.
Report an issue: GitHub.