From 57db1725f459c7904fb24cc1bb1f72bf2d1e6930 Mon Sep 17 00:00:00 2001 From: MikePopoloski Date: Sat, 9 Mar 2024 11:54:47 -0500 Subject: [PATCH] v1800-2023: clarification: unpacked unions are allowed as net types --- scripts/diagnostics.txt | 2 +- source/ast/types/DeclaredType.cpp | 8 ++++++++ tests/unittests/ast/MemberTests.cpp | 13 +++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/scripts/diagnostics.txt b/scripts/diagnostics.txt index 2b13702b8..30c18d4f1 100644 --- a/scripts/diagnostics.txt +++ b/scripts/diagnostics.txt @@ -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 '{}'" diff --git a/source/ast/types/DeclaredType.cpp b/source/ast/types/DeclaredType.cpp index c7ebf3a5f..5327a48af 100644 --- a/source/ast/types/DeclaredType.cpp +++ b/source/ast/types/DeclaredType.cpp @@ -163,6 +163,14 @@ static bool isValidForNet(const Type& type) { return true; } + if (ct.isUnpackedUnion()) { + for (auto field : ct.as().fields) { + if (!isValidForNet(field->getType())) + return false; + } + return true; + } + return false; } diff --git a/tests/unittests/ast/MemberTests.cpp b/tests/unittests/ast/MemberTests.cpp index c2d9e3a3f..2d8cc65b7 100644 --- a/tests/unittests/ast/MemberTests.cpp +++ b/tests/unittests/ast/MemberTests.cpp @@ -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;