Skip to content

Commit

Permalink
v1800-2023: clarification: unpacked unions are allowed as net types
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Mar 9, 2024
1 parent f327887 commit 57db172
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/diagnostics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ error InheritFromAbstract "'{}' cannot inherit from virtual class '{}' without p
error InheritFromAbstractConstraint "'{}' cannot inherit from virtual class '{}' without providing an implementation for pure constraint '{}'"
error InvalidPortType "{} is not a valid type for a port"
error InvalidPortSubType "{} is not a valid type for a port because it contains type {}"
error InvalidNetType "{} is not a valid type for a net; only 4-state integral types and unpacked structs and arrays of such types are allowed"
error InvalidNetType "{} is not a valid type for a net; only 4-state integral types and unpacked structs/unions and arrays of such types are allowed"
error InvalidUserDefinedNetType "{} is not a valid type for a user-defined nettype; only integral types, floating types, and unpacked structs, unions, and arrays of such types are allowed"
error ExtendIfaceFromClass "a normal (or virtual) class cannot extend interface class '{}'"
error ExtendClassFromIface "an interface class cannot extend non-interface class '{}'"
Expand Down
8 changes: 8 additions & 0 deletions source/ast/types/DeclaredType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ static bool isValidForNet(const Type& type) {
return true;
}

if (ct.isUnpackedUnion()) {
for (auto field : ct.as<UnpackedUnionType>().fields) {
if (!isValidForNet(field->getType()))
return false;
}
return true;
}

return false;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/unittests/ast/MemberTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ endmodule
CHECK(diags[5].code == diag::DelayNotNumeric);
}

TEST_CASE("Net types can be unpacked unions") {
auto tree = SyntaxTree::fromText(R"(
module m;
typedef union { logic l; } u;
wire u w;
endmodule
)");

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

TEST_CASE("Bad signed specifier") {
auto tree = SyntaxTree::fromText(R"(
module Top;
Expand Down

0 comments on commit 57db172

Please sign in to comment.