diff --git a/xls/dslx/frontend/parser.cc b/xls/dslx/frontend/parser.cc index c99596586e..9ed48a97e6 100644 --- a/xls/dslx/frontend/parser.cc +++ b/xls/dslx/frontend/parser.cc @@ -1268,11 +1268,18 @@ absl::StatusOr Parser::ParseCast(Bindings& bindings, return term; } + // This handles the case where we're trying to make a tuple constant that has + // an explicitly annotated type; e.g. + // + // ```dslx + // const MY_TUPLE = (u32, u64):(u32:32, u64:64); + // ``` if (auto* tuple = dynamic_cast(term); tuple != nullptr && std::all_of(tuple->members().begin(), tuple->members().end(), IsConstant)) { return term; } + return ParseErrorStatus( type->span(), "Old-style cast only permitted for constant arrays/tuples " diff --git a/xls/dslx/type_system/typecheck_module_test.cc b/xls/dslx/type_system/typecheck_module_test.cc index 9efd367cf3..8cb41da5c6 100644 --- a/xls/dslx/type_system/typecheck_module_test.cc +++ b/xls/dslx/type_system/typecheck_module_test.cc @@ -282,6 +282,13 @@ fn f() -> u32 { p() } XLS_EXPECT_OK(Typecheck(kProgram)); } +TEST(TypecheckTest, TupleWithExplicitlyAnnotatedType) { + constexpr std::string_view kProgram = R"( +const MY_TUPLE = (u32, u64):(u32:32, u64:64); +)"; + XLS_EXPECT_OK(Typecheck(kProgram)); +} + TEST(TypecheckTest, ProcWithImplEmpty) { constexpr std::string_view kProgram = R"( proc Foo {}