Skip to content

Commit

Permalink
Allow implicitly typed parameters with range declarations to be assig…
Browse files Browse the repository at this point in the history
…nment-like contexts
  • Loading branch information
MikePopoloski committed Sep 24, 2023
1 parent af08cba commit e0d4122
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 10 additions & 8 deletions source/ast/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,18 +358,19 @@ std::tuple<const Expression*, const Type*> Expression::bindImplicitParam(
const DataTypeSyntax& typeSyntax, const ExpressionSyntax& rhs, SourceLocation location,
const ASTContext& exprContext, const ASTContext& typeContext, bitmask<ASTFlags> extraFlags) {

Compilation& comp = exprContext.getCompilation();
Expression& expr = create(comp, rhs, exprContext, extraFlags);
const Type* lhsType = expr.type;

// Rules are described in [6.20.2].
Compilation& comp = exprContext.getCompilation();
auto& it = typeSyntax.as<ImplicitTypeSyntax>();
if (!it.dimensions.empty()) {
// If we have a range provided, the result is always an integral value
// of the provided width -- getType() will do what we want here.
lhsType = &comp.getType(typeSyntax, typeContext);
auto lhsType = &comp.getType(typeSyntax, typeContext);
return {&bindRValue(*lhsType, rhs, location, exprContext, extraFlags), lhsType};
}
else if (it.signing) {

Expression& expr = create(comp, rhs, exprContext, extraFlags);
const Type* lhsType = expr.type;
if (it.signing) {
// If signing is provided, the result is always integral but we infer the width.
// If the type is non-integral or unsized, infer a width of 32.
bitwidth_t bits = lhsType->getBitWidth();
Expand Down Expand Up @@ -859,8 +860,9 @@ Expression& Expression::create(Compilation& compilation, const ExpressionSyntax&
context);
break;
case SyntaxKind::TimingControlExpression:
// Valid cases of this expression type are handled in AssignmentExpression. If we reach
// this block here, the expression is invalid so always report an error.
// Valid cases of this expression type are handled in AssignmentExpression.
// If we reach this block here, the expression is invalid so always report
// an error.
context.addDiag(diag::TimingControlNotAllowed, syntax.sourceRange());
result = &badExpr(compilation, nullptr);
break;
Expand Down
10 changes: 10 additions & 0 deletions tests/unittests/ast/TypeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2130,3 +2130,13 @@ endmodule
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}

TEST_CASE("Inferred parameter type with range specification -- assignment-like context") {
auto tree = SyntaxTree::fromText(R"(
localparam [1:0][7:0] VALUES_0 = '{1, 2};
)");

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

0 comments on commit e0d4122

Please sign in to comment.