Skip to content

Commit

Permalink
Make a comment and add a test for one place where IsConstant is still…
Browse files Browse the repository at this point in the history
… used.
  • Loading branch information
cdleary committed Nov 29, 2024
1 parent 713c194 commit ce57dad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions xls/dslx/frontend/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1268,11 +1268,18 @@ absl::StatusOr<Expr*> 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<XlsTuple*>(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 "
Expand Down
7 changes: 7 additions & 0 deletions xls/dslx/type_system/typecheck_module_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ fn f() -> u32 { p<u32:28>() }
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 {}
Expand Down

0 comments on commit ce57dad

Please sign in to comment.