File tree Expand file tree Collapse file tree 5 files changed +50
-15
lines changed Expand file tree Collapse file tree 5 files changed +50
-15
lines changed Original file line number Diff line number Diff line change @@ -424,22 +424,21 @@ pub:
424
424
generic_types []Type
425
425
is_pub bool
426
426
// _pos fields for vfmt
427
- mut_pos int = - 1 // mut:
428
- pub_pos int = - 1 // pub:
429
- pub_mut_pos int = - 1 // pub mut:
430
- global_pos int = - 1 // __global:
431
- module_pos int = - 1 // module:
432
- language Language
433
- is_union bool
434
- attrs []Attr
435
- pre_comments []Comment
436
- end_comments []Comment
437
- embeds []Embed
438
-
427
+ mut_pos int = - 1 // mut:
428
+ pub_pos int = - 1 // pub:
429
+ pub_mut_pos int = - 1 // pub mut:
430
+ global_pos int = - 1 // __global:
431
+ module_pos int = - 1 // module:
432
+ is_union bool
433
+ attrs []Attr
434
+ pre_comments []Comment
435
+ end_comments []Comment
436
+ embeds []Embed
439
437
is_implements bool
440
438
implements_types []TypeNode
441
439
pub mut :
442
- fields []StructField
440
+ language Language
441
+ fields []StructField
443
442
}
444
443
445
444
pub struct Embed {
@@ -522,6 +521,7 @@ pub mut:
522
521
has_update_expr bool // has `...a`
523
522
init_fields []StructInitField
524
523
generic_types []Type
524
+ language Language
525
525
}
526
526
527
527
pub enum StructInitKind {
Original file line number Diff line number Diff line change @@ -78,7 +78,10 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
78
78
}
79
79
}
80
80
if is_anon {
81
- g.writeln ('(${styp} ){' )
81
+ if node.language == .v {
82
+ g.write ('(${styp} )' )
83
+ }
84
+ g.writeln ('{' )
82
85
} else if g.is_shared && ! g.inside_opt_data && ! g.is_arraymap_set {
83
86
mut shared_typ := node.typ.set_flag (.shared_f)
84
87
shared_styp = g.styp (shared_typ)
@@ -433,7 +436,8 @@ fn (mut g Gen) zero_struct_field(field ast.StructField) bool {
433
436
}
434
437
if has_option_field || field.anon_struct_decl.fields.len > 0 {
435
438
default_init := ast.StructInit{
436
- typ: field.typ
439
+ typ: field.typ
440
+ language: field.anon_struct_decl.language
437
441
}
438
442
g.write ('.${field_name} = ' )
439
443
if field.typ.has_flag (.option) {
Original file line number Diff line number Diff line change @@ -239,6 +239,7 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
239
239
if p.tok.kind == .key_struct {
240
240
// Anon structs
241
241
p.anon_struct_decl = p.struct_decl (true )
242
+ p.anon_struct_decl.language = language
242
243
// Find the registered anon struct type, it was registered above in `p.struct_decl()`
243
244
typ = p.table.find_type_idx (p.anon_struct_decl.name)
244
245
} else {
Original file line number Diff line number Diff line change
1
+ // anon.h
2
+ #ifndef TEST_H
3
+ #define TEST_H
4
+
5
+ typedef struct {
6
+ struct {
7
+ int x ;
8
+ } inner ;
9
+ } outer ;
10
+
11
+ #endif
Original file line number Diff line number Diff line change
1
+ #insert "@VMODROOT/anon.h"
2
+
3
+ @[typedef]
4
+ struct C.outer {
5
+ inner struct {
6
+ x int
7
+ }
8
+ }
9
+
10
+ struct Outer {
11
+ inner struct {
12
+ val int
13
+ }
14
+ }
15
+
16
+ fn test_main () {
17
+ _ = Outer{}
18
+ _ = C.outer{}
19
+ }
You can’t perform that action at this time.
0 commit comments