mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
0ff74dae63
commit
202585e175
@ -290,8 +290,9 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
|
|||||||
&& c.table.cur_concrete_types.len == 0 {
|
&& c.table.cur_concrete_types.len == 0 {
|
||||||
pos := type_sym.name.last_index('.') or { -1 }
|
pos := type_sym.name.last_index('.') or { -1 }
|
||||||
first_letter := type_sym.name[pos + 1]
|
first_letter := type_sym.name[pos + 1]
|
||||||
if !first_letter.is_capital() && type_sym.kind != .placeholder
|
if !first_letter.is_capital()
|
||||||
&& !type_sym.name.starts_with('main._VAnonStruct') {
|
&& (type_sym.kind != .struct_ || !(type_sym.info as ast.Struct).is_anon)
|
||||||
|
&& type_sym.kind != .placeholder {
|
||||||
c.error('cannot initialize builtin type `$type_sym.name`', node.pos)
|
c.error('cannot initialize builtin type `$type_sym.name`', node.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
vlib/v/checker/tests/anon_structs_visibility.out
Normal file
1
vlib/v/checker/tests/anon_structs_visibility.out
Normal file
@ -0,0 +1 @@
|
|||||||
|
foo.bar.baz == 1
|
9
vlib/v/checker/tests/anon_structs_visibility/amod/amod.v
Normal file
9
vlib/v/checker/tests/anon_structs_visibility/amod/amod.v
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module amod
|
||||||
|
|
||||||
|
pub struct Foo {
|
||||||
|
pub mut:
|
||||||
|
bar struct {
|
||||||
|
pub mut:
|
||||||
|
baz int
|
||||||
|
}
|
||||||
|
}
|
10
vlib/v/checker/tests/anon_structs_visibility/main.v
Normal file
10
vlib/v/checker/tests/anon_structs_visibility/main.v
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import v.checker.tests.anon_structs_visibility.amod
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo := amod.Foo{
|
||||||
|
bar: struct {
|
||||||
|
baz: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println('foo.bar.baz == $foo.bar.baz')
|
||||||
|
}
|
@ -8,7 +8,7 @@ import v.ast
|
|||||||
|
|
||||||
pub fn (mut f Fmt) struct_decl(node ast.StructDecl, is_anon bool) {
|
pub fn (mut f Fmt) struct_decl(node ast.StructDecl, is_anon bool) {
|
||||||
f.attrs(node.attrs)
|
f.attrs(node.attrs)
|
||||||
if node.is_pub {
|
if node.is_pub && !is_anon {
|
||||||
f.write('pub ')
|
f.write('pub ')
|
||||||
}
|
}
|
||||||
if node.is_union {
|
if node.is_union {
|
||||||
|
@ -14,10 +14,13 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
|
|||||||
attrs := p.attrs
|
attrs := p.attrs
|
||||||
p.attrs = []
|
p.attrs = []
|
||||||
start_pos := p.tok.pos()
|
start_pos := p.tok.pos()
|
||||||
is_pub := p.tok.kind == .key_pub
|
mut is_pub := p.tok.kind == .key_pub
|
||||||
if is_pub {
|
if is_pub {
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
|
if is_anon {
|
||||||
|
is_pub = true
|
||||||
|
}
|
||||||
is_union := p.tok.kind == .key_union
|
is_union := p.tok.kind == .key_union
|
||||||
if p.tok.kind == .key_struct {
|
if p.tok.kind == .key_struct {
|
||||||
p.next()
|
p.next()
|
||||||
|
Loading…
Reference in New Issue
Block a user