mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: embed always public and mutable (#7722)
This commit is contained in:
parent
b8af81240a
commit
e4edc5925a
@ -158,7 +158,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
||||
field_start_pos := p.tok.position()
|
||||
is_embed := ((p.tok.lit.len > 1 && p.tok.lit[0].is_capital()) ||
|
||||
p.peek_tok.kind == .dot) &&
|
||||
language == .v && ast_fields.len == 0
|
||||
language == .v && ast_fields.len == 0 && !(is_field_mut || is_field_mut || is_field_global)
|
||||
mut field_name := ''
|
||||
mut typ := table.Type(0)
|
||||
mut type_pos := token.Position{}
|
||||
@ -250,8 +250,16 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
||||
typ: typ
|
||||
default_expr: ast.ex2fe(default_expr)
|
||||
has_default_expr: has_default_expr
|
||||
is_pub: is_field_pub
|
||||
is_mut: is_field_mut
|
||||
is_pub: if is_embed {
|
||||
true
|
||||
} else {
|
||||
is_field_pub
|
||||
}
|
||||
is_mut: if is_embed {
|
||||
true
|
||||
} else {
|
||||
is_field_mut
|
||||
}
|
||||
is_global: is_field_global
|
||||
attrs: p.attrs
|
||||
}
|
||||
|
7
vlib/v/parser/tests/embed_pub_mut_err.out
Normal file
7
vlib/v/parser/tests/embed_pub_mut_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/parser/tests/embed_pub_mut_err.vv:6:1: error: expecting type declaration
|
||||
4 | pub mut:
|
||||
5 | Context
|
||||
6 | }
|
||||
| ^
|
||||
7 |
|
||||
8 | fn main() {
|
9
vlib/v/parser/tests/embed_pub_mut_err.vv
Normal file
9
vlib/v/parser/tests/embed_pub_mut_err.vv
Normal file
@ -0,0 +1,9 @@
|
||||
struct Context {}
|
||||
|
||||
struct App {
|
||||
pub mut:
|
||||
Context
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
10
vlib/v/tests/field_publicity/embed.v
Normal file
10
vlib/v/tests/field_publicity/embed.v
Normal file
@ -0,0 +1,10 @@
|
||||
module field_publicity
|
||||
|
||||
pub struct Context {
|
||||
pub:
|
||||
name string
|
||||
}
|
||||
|
||||
pub struct App {
|
||||
Context
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
import flag
|
||||
import field_publicity
|
||||
|
||||
struct Foo {
|
||||
x int
|
||||
@ -80,6 +81,11 @@ fn test_assign() {
|
||||
assert h.x == 5
|
||||
}
|
||||
|
||||
fn test_embed_is_public() {
|
||||
a := field_publicity.App{}
|
||||
assert a.Context.name == ''
|
||||
}
|
||||
|
||||
struct Eggs {}
|
||||
|
||||
fn (f &Eggs) test(x int) int {
|
||||
@ -94,3 +100,8 @@ fn test_embed_method_receiver_ptr() {
|
||||
b := Breakfast{}
|
||||
assert b.test(5) == 5
|
||||
}
|
||||
|
||||
fn test_embed_mutable() {
|
||||
mut a := field_publicity.App{}
|
||||
a.Context = field_publicity.Context{}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user