mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: [noinit] struct attribute
This commit is contained in:
parent
1ce93536d0
commit
e3f8d448c1
@ -33,11 +33,8 @@ pub fn (app &App) index() vweb.Result {
|
||||
|
||||
pub fn (mut app App) init_once() {
|
||||
app.db = sqlite.connect('blog.db') or { panic(err) }
|
||||
app.db.exec('create table if not exists article (' +
|
||||
'id integer primary key, ' +
|
||||
"title text default ''," +
|
||||
"text text default ''" +
|
||||
');')
|
||||
app.db.exec('create table if not exists article (' + 'id integer primary key, ' + "title text default ''," +
|
||||
"text text default ''" + ');')
|
||||
}
|
||||
|
||||
pub fn (mut app App) init() {
|
||||
@ -53,8 +50,7 @@ pub fn (mut app App) new_article() vweb.Result {
|
||||
title := app.form['title']
|
||||
text := app.form['text']
|
||||
if title == '' || text == '' {
|
||||
app.text('Empty text/title')
|
||||
return vweb.Result{}
|
||||
return app.text('Empty text/title')
|
||||
}
|
||||
article := Article{
|
||||
title: title
|
||||
|
@ -504,6 +504,13 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) table.Type {
|
||||
type_sym.language != .c {
|
||||
c.error('type `$type_sym.name` is private', struct_init.pos)
|
||||
}
|
||||
if type_sym.kind == .struct_ {
|
||||
info := type_sym.info as table.Struct
|
||||
if info.attrs.len > 0 && info.attrs[0].name == 'noinit' && type_sym.mod != c.mod {
|
||||
c.error('struct `$type_sym.name` is declared with a `[noinit]` attribute, so ' + 'it cannot be initialized with `$type_sym.name{}`',
|
||||
struct_init.pos)
|
||||
}
|
||||
}
|
||||
match type_sym.kind {
|
||||
.placeholder {
|
||||
c.error('unknown struct: $type_sym.name', struct_init.pos)
|
||||
|
@ -295,6 +295,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
||||
is_union: is_union
|
||||
is_ref_only: attrs.contains('ref_only')
|
||||
generic_types: generic_types
|
||||
attrs: attrs
|
||||
}
|
||||
is_public: is_pub
|
||||
}
|
||||
|
@ -603,6 +603,8 @@ pub fn (kinds []Kind) str() string {
|
||||
}
|
||||
|
||||
pub struct Struct {
|
||||
pub:
|
||||
attrs []Attr
|
||||
pub mut:
|
||||
embeds []Type
|
||||
fields []Field
|
||||
|
@ -72,6 +72,7 @@ pub struct Cookie {
|
||||
http_only bool
|
||||
}
|
||||
|
||||
[noinit]
|
||||
pub struct Result {
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user