Skip to content

Commit a86dcad

Browse files
committed
fix: some fmt issue
1 parent e5d5ad9 commit a86dcad

File tree

6 files changed

+36
-18
lines changed

6 files changed

+36
-18
lines changed

src/ast/fmt.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,10 @@ impl FmtBuilder {
624624
self.token(&format!("{:?}", node.content));
625625
}
626626
pub fn parse_trait_def_node(&mut self, node: &TraitDefNode) {
627-
// for c in node.precom.iter() {
628-
// c.format(self);
629-
// }
627+
if let Some((m, _)) = node.modifier {
628+
self.token(m.get_str());
629+
self.space();
630+
}
630631
self.prefix();
631632
self.token("trait");
632633
self.space();
@@ -756,6 +757,9 @@ impl FmtBuilder {
756757
}
757758
expr.format(self);
758759
}
760+
if node.exprs.len() == 1 {
761+
self.comma();
762+
}
759763
self.r_paren();
760764
}
761765
pub fn parse_tuple_type_node(&mut self, node: &TupleTypeNode) {

src/ast/node/operator.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,10 @@ impl Node for TakeOpNode {
353353
_ = s.expect_field_pub(ctx, field, id_range);
354354
ctx.push_semantic_token(id_range, SemanticTokenType::PROPERTY, 0);
355355
ctx.set_field_refs(head_pltype, field, id_range);
356-
ctx.send_if_go_to_def(id_range, field.range, s.path.clone());
356+
if field.range != Default::default() {
357+
// walkaround for tuple types
358+
ctx.send_if_go_to_def(id_range, field.range, s.path.clone());
359+
}
357360
return Ok(NodeOutput::new_value(NodeValue::new(
358361
builder
359362
.build_struct_gep(headptr, field.index, "structgep")

test/fmt/test_fmt.pi

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl TestTrait for A {
5555

5656
}
5757

58-
trait TestTrait {
58+
pub trait TestTrait {
5959
fn name() void;
6060

6161
fn set(i: i64) i64;
@@ -185,12 +185,6 @@ trait TC: TA+TB {
185185
trait TD: TA {
186186
}
187187

188-
fn test_tuple() void {
189-
let a: (i64, i64) = (1, 2);
190-
let b = (1, 2, (8, (9, 0, None{})));
191-
return;
192-
}
193-
194188
fn fn_as_param(f: |i64, i64| => i64) |i64, i64| => i64 {
195189
panic::assert(f(1, 2) == 3);
196190
return f;
@@ -261,3 +255,17 @@ fn test_ret_closure() |i64| => i64 {
261255
return a;
262256
}
263257

258+
pub fn test_tuple() void {
259+
let d: () = ();
260+
let a = (1,);
261+
// tuple
262+
let g = (1);
263+
// i64
264+
let b = (1, 2);
265+
let c: (i64, i64, (i64)) = (1, 2, (3,));
266+
let e = a.0;
267+
let f = c.2;
268+
panic::assert(f.0 == 3);
269+
return;
270+
}
271+

test/test/multi_trait.pi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ trait B {
66

77
}
88

9+
910
trait C: A+B {
1011
fn c() void;
11-
1212
}
1313

1414
pub fn test_multi_trait() void {

test/test/multi_trait_A.pi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ impl A for test_struct {
99
return true;
1010
}
1111

12-
}
12+
}
13+

test/test/tuple.pi

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use core::panic;
2-
32
pub fn test_tuple() void {
4-
let d:() = ();
5-
let a = (1,);// tuple
6-
let g = (1);// i64
3+
let d: () = ();
4+
let a = (1,);
5+
// tuple
6+
let g = (1);
7+
// i64
78
let b = (1, 2);
8-
let c:(i64,i64,(i64)) = (1, 2, (3,),);
9+
let c: (i64, i64, (i64)) = (1, 2, (3,));
910
let e = a.0;
1011
let f = c.2;
1112
panic::assert(f.0 == 3);
1213
return;
1314
}
15+

0 commit comments

Comments
 (0)