Skip to content

Commit

Permalink
julefmt: simplify primitive type castings
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Mar 28, 2024
1 parent 2ce26d8 commit 0c680e8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/format.jule
Original file line number Diff line number Diff line change
Expand Up @@ -1325,9 +1325,13 @@ impl ExprFormatter {
}

fn cast(&self, mut c: &ast::CastExpr) {
self.write("(")
self.fmt.format_type(c.kind)
self.write(")")
if is_prim_type(c.kind) {
self.fmt.format_type(c.kind)
} else {
self.write("(")
self.fmt.format_type(c.kind)
self.write(")")
}
// Do not write parentheses for expression.
// Expression formatter will add.
self.format(c.expr)
Expand Down Expand Up @@ -1693,3 +1697,11 @@ fn padding_abs(x: int): int {
}
ret x
}

fn is_prim_type(&t: &ast::TypeDecl): bool {
match type t.kind {
| &ast::IdentTypeDecl:
ret (&ast::IdentTypeDecl)(t.kind).is_prim()
}
ret false
}

0 comments on commit 0c680e8

Please sign in to comment.