fix: remove incorrect dynamic attr check

This commit is contained in:
2026-01-31 18:06:53 +08:00
parent 8f01ce2eb4
commit c5aee21514

View File

@@ -529,16 +529,21 @@ where
binding_keys.push(alias_sym);
}
let (required, optional) = params
.iter()
.partition_map(|Param { sym, sym_span, default, .. }| {
let (required, optional) = params.iter().partition_map(
|Param {
sym,
sym_span,
default,
..
}| {
use itertools::Either::*;
if default.is_none() {
Left((*sym, *sym_span))
} else {
Right((*sym, *sym_span))
}
});
},
);
let slots: Vec<_> = ctx.reserve_slots(binding_keys.len()).collect();
let let_bindings: HashMap<_, _> = binding_keys
@@ -790,9 +795,6 @@ fn finalize_pending_value<Ctx: DowngradeContext, const ALLOW_DYN: bool>(
) -> Result<ExprId> {
match value {
PendingValue::Expr(expr) => {
if !ALLOW_DYN {
check_no_dynamic_attrs(&expr, ctx)?;
}
let id = Downgrade::downgrade(expr, ctx)?;
Ok(ctx.maybe_thunk(id))
}
@@ -830,24 +832,3 @@ fn finalize_pending_value<Ctx: DowngradeContext, const ALLOW_DYN: bool>(
}
}
}
/// Check that an expression doesn't contain dynamic attributes (for let bindings).
fn check_no_dynamic_attrs(expr: &ast::Expr, ctx: &impl DowngradeContext) -> Result<()> {
let ast::Expr::AttrSet(attrset) = expr else {
return Ok(());
};
for v in attrset.attrpath_values() {
v.attrpath().unwrap().attrs().try_for_each(|attr| {
if let ast::Attr::Dynamic(dyn_attr) = attr {
Err(Error::downgrade_error(
"dynamic attributes not allowed in let bindings".to_string(),
ctx.get_current_source(),
dyn_attr.syntax().text_range(),
))
} else {
Ok(())
}
})?;
}
Ok(())
}