Skip to content

Commit

Permalink
Pattern vars should be usable in static initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Dec 21, 2024
1 parent be0428d commit 31e4654
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion source/ast/expressions/MiscExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ Expression& ValueExpressionBase::fromSymbol(const ASTContext& context, const Sym
context.addDiag(diag::LocalVarEventExpr, sourceRange) << symbol.name;
return badExpr(comp, nullptr);
}
else if (!var.flags.has(VariableFlags::RefStatic) && flags.has(DisallowedAutoVarContexts)) {
else if (!var.flags.has(VariableFlags::RefStatic) && flags.has(DisallowedAutoVarContexts) &&
var.kind != SymbolKind::PatternVar) {
if (flags.has(ASTFlags::NonProcedural)) {
context.addDiag(diag::AutoFromNonProcedural, sourceRange) << symbol.name;
return badExpr(comp, nullptr);
Expand Down
15 changes: 15 additions & 0 deletions tests/unittests/ast/ExpressionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3756,3 +3756,18 @@ endclass
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}

TEST_CASE("Pattern var in static initializer") {
auto tree = SyntaxTree::fromText(R"(
module m;
struct {int a; real b;} s;
initial begin
static int b = s matches '{a:.i, b:.j} ? i : 0;
end
endmodule
)");

Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}

0 comments on commit 31e4654

Please sign in to comment.