diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index 14a5df3c40..fa566ee09b 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -443,7 +443,11 @@ class RandomizeMarkVisitor final : public VNVisitor { void visit(AstMemberSel* nodep) override { if (!m_constraintExprGenp) return; iterateChildrenConst(nodep); - nodep->user1(nodep->fromp()->user1() && nodep->varp()->rand().isRandomizable()); + // Member select are randomized when both object and member are marked as rand. + // Variable references in with clause are converted to member selects and their from() is + // of type AstLambdaArgRef. They are randomized too. + bool randObject = nodep->fromp()->user1() || VN_IS(nodep->fromp(), LambdaArgRef); + nodep->user1(randObject && nodep->varp()->rand().isRandomizable()); } void visit(AstNodeModule* nodep) override { VL_RESTORER(m_modp);