Skip to content

Commit

Permalink
[DSLX:fmt] Do not put a break1 after a match arrow, use a space isntead.
Browse files Browse the repository at this point in the history
break1 causes the expr to be at the same indent level on the next line if it
overflows the line.

PiperOrigin-RevId: 576297032
  • Loading branch information
cdleary authored and copybara-github committed Oct 24, 2023
1 parent bae65e5 commit 01839ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion xls/dslx/fmt/ast_fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ static DocRef Fmt(const MatchArm& n, const Comments& comments,
FmtNameDefTreePtr, comments, arena));
pieces.push_back(arena.space());
pieces.push_back(arena.fat_arrow());
pieces.push_back(arena.break1());
pieces.push_back(arena.space());
pieces.push_back(Fmt(*n.expr(), comments, arena));
return ConcatNGroup(arena, pieces);
}
Expand Down
19 changes: 19 additions & 0 deletions xls/dslx/fmt/ast_fmt_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1349,5 +1349,24 @@ proc p_test {
EXPECT_EQ(got, kProgram);
}

TEST(ModuleFmtTest, MatchLongWildcardArmExpression) {
const std::string_view kProgram =
R"(import float32
fn f(input_float: float32::F32) -> float32::F32 {
match f.bexp {
_ => float32::F32 {
sign: input_float.sign, bexp: input_float.bexp - u8:1, fraction: input_float.fraction
},
}
}
)";
std::vector<CommentData> comments;
XLS_ASSERT_OK_AND_ASSIGN(std::unique_ptr<Module> m,
ParseModule(kProgram, "fake.x", "fake", &comments));
std::string got = AutoFmt(*m, Comments::Create(comments));
EXPECT_EQ(got, kProgram);
}

} // namespace
} // namespace xls::dslx

0 comments on commit 01839ab

Please sign in to comment.