Skip to content

Commit

Permalink
Tweaks and fixes for Wpacked-array-conv
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Oct 25, 2024
1 parent 528e209 commit c857fd2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion scripts/warning_docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ one of the types must have multiple declared dimensions.
```
module m;
logic [3:1][1:0] a;
logic [5:0] b;
logic [5:0][1:0] b;
initial b = a;
endmodule
```
3 changes: 1 addition & 2 deletions source/ast/expressions/ConversionExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void checkImplicitConversions(const ASTContext& context, const Type& sourceType,

// Warn for conversions between packed arrays of differing
// dimension counts or sizes.
if (isMultiDimArray(lt) || isMultiDimArray(rt) && !hasSameDims(lt, rt)) {
if (isMultiDimArray(lt) && isMultiDimArray(rt) && !hasSameDims(lt, rt)) {
// Avoid warning for assignments or comparisons with 0 or '0, '1.
auto isZeroOrUnsized = [](const Expression& e) {
auto expr = &e.unwrapImplicitConversions();
Expand All @@ -188,7 +188,6 @@ void checkImplicitConversions(const ASTContext& context, const Type& sourceType,
(!parentIsComparison() ||
!isZeroOrUnsized(parentExpr->as<BinaryExpression>().right()))) {
addDiag(diag::PackedArrayConv) << sourceType << targetType;
return;
}
}

Expand Down
10 changes: 3 additions & 7 deletions tests/unittests/ast/ExpressionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,17 +783,13 @@ endmodule
compilation.addSyntaxTree(tree);

auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 10);
REQUIRE(diags.size() == 6);
CHECK(diags[0].code == diag::IndexOOB);
CHECK(diags[1].code == diag::IndexOOB);
CHECK(diags[2].code == diag::PackedArrayConv);
CHECK(diags[2].code == diag::RangeOOB);
CHECK(diags[3].code == diag::RangeOOB);
CHECK(diags[4].code == diag::PackedArrayConv);
CHECK(diags[4].code == diag::RangeOOB);
CHECK(diags[5].code == diag::RangeOOB);
CHECK(diags[6].code == diag::PackedArrayConv);
CHECK(diags[7].code == diag::RangeOOB);
CHECK(diags[8].code == diag::PackedArrayConv);
CHECK(diags[9].code == diag::RangeOOB);
}

TEST_CASE("Empty concat error") {
Expand Down

0 comments on commit c857fd2

Please sign in to comment.