change #[hdl] if
to only accept Expr<T> instead of accepting bool, this prevents using == by accident
This commit is contained in:
parent
79031ccf88
commit
37d03cec33
|
@ -11,7 +11,7 @@ use crate::{
|
|||
ops::VariantAccess, Expr, Flow, Target, TargetBase, TargetPathArrayElement,
|
||||
TargetPathBundleField, TargetPathElement, ToExpr,
|
||||
},
|
||||
int::{DynUInt, DynUIntType, FixedOrDynIntType, UInt},
|
||||
int::{DynUInt, DynUIntType, FixedOrDynIntType, IntValue, UInt},
|
||||
intern::{Intern, Interned},
|
||||
memory::{Mem, MemBuilder, MemBuilderTarget, PortName},
|
||||
reg::Reg,
|
||||
|
@ -2259,8 +2259,10 @@ where
|
|||
) -> RegBuilder<'a, (), (), ()> {
|
||||
self.reg_builder_with_loc(implicit_name.0, SourceLocation::caller())
|
||||
}
|
||||
// intentionally takes Expr instead of impl ToExpr to help prevent
|
||||
// `#[hdl] if a == b {}` instead of using `cmp_eq`
|
||||
#[track_caller]
|
||||
pub fn if_<Ty>(&mut self, cond: impl ToExpr<Type = Ty>) -> IfScope
|
||||
pub fn if_<Ty>(&mut self, cond: Expr<IntValue<Ty>>) -> IfScope
|
||||
where
|
||||
Ty: FixedOrDynIntType<
|
||||
1,
|
||||
|
@ -2273,7 +2275,7 @@ where
|
|||
}
|
||||
pub fn if_with_loc<Ty>(
|
||||
&mut self,
|
||||
cond: impl ToExpr<Type = Ty>,
|
||||
cond: Expr<IntValue<Ty>>,
|
||||
source_location: SourceLocation,
|
||||
) -> IfScope
|
||||
where
|
||||
|
@ -2284,7 +2286,7 @@ where
|
|||
CanonicalValue = DynUInt,
|
||||
>,
|
||||
{
|
||||
let cond = cond.to_expr().as_bool();
|
||||
let cond = cond.as_bool();
|
||||
let outer_block = self.block_stack.top();
|
||||
let then_block = self.new_block();
|
||||
let else_block = self.new_block();
|
||||
|
|
Loading…
Reference in a new issue