From 6813866141c58ed1ee497e1b36d04074ec2d4432 Mon Sep 17 00:00:00 2001 From: zakuro Date: Tue, 16 Feb 2021 20:39:50 +0900 Subject: [PATCH] fmt: fix bug of disappearing `pub` in struct decl (#8777) --- vlib/v/fmt/tests/structs_expected.vv | 6 ++++++ vlib/v/fmt/tests/structs_input.vv | 6 ++++++ vlib/v/parser/struct.v | 20 ++++++++++---------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/vlib/v/fmt/tests/structs_expected.vv b/vlib/v/fmt/tests/structs_expected.vv index 9299d67f99..dedab4776d 100644 --- a/vlib/v/fmt/tests/structs_expected.vv +++ b/vlib/v/fmt/tests/structs_expected.vv @@ -7,6 +7,12 @@ struct User { very_long_type_field2 very_loooooooong_type // long } +struct FamousUser { + User +pub: + aka string +} + struct Foo { field1 int // f1 field2 string // f2 diff --git a/vlib/v/fmt/tests/structs_input.vv b/vlib/v/fmt/tests/structs_input.vv index 880df9c929..f7fb65e709 100644 --- a/vlib/v/fmt/tests/structs_input.vv +++ b/vlib/v/fmt/tests/structs_input.vv @@ -7,6 +7,12 @@ struct User { very_long_type_field2 very_loooooooong_type // long } +struct FamousUser { +pub: + User + aka string +} + struct Foo { field1 int // f1 field2 string // f2 diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index 981e9b4727..bf781148ce 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -121,7 +121,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { return ast.StructDecl{} } p.next() - pub_mut_pos = fields.len + pub_mut_pos = ast_fields.len is_field_pub = true is_field_mut = true is_field_global = false @@ -130,7 +130,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { p.error('redefinition of `pub` section') return ast.StructDecl{} } - pub_pos = fields.len + pub_pos = ast_fields.len is_field_pub = true is_field_mut = false is_field_global = false @@ -143,7 +143,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { } p.next() p.check(.colon) - mut_pos = fields.len + mut_pos = ast_fields.len is_field_pub = false is_field_mut = true is_field_global = false @@ -154,7 +154,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { } p.next() p.check(.colon) - global_pos = fields.len + global_pos = ast_fields.len is_field_pub = true is_field_mut = true is_field_global = true @@ -165,7 +165,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl { } p.next() p.check(.colon) - module_pos = fields.len + module_pos = ast_fields.len is_field_pub = false is_field_mut = false is_field_global = false @@ -320,11 +320,11 @@ fn (mut p Parser) struct_decl() ast.StructDecl { is_pub: is_pub fields: ast_fields pos: start_pos.extend_with_last_line(name_pos, last_line) - mut_pos: mut_pos - embeds.len - pub_pos: pub_pos - embeds.len - pub_mut_pos: pub_mut_pos - embeds.len - global_pos: global_pos - embeds.len - module_pos: module_pos - embeds.len + mut_pos: mut_pos + pub_pos: pub_pos + pub_mut_pos: pub_mut_pos + global_pos: global_pos + module_pos: module_pos language: language is_union: is_union attrs: attrs