all: [noinit] struct attribute

pull/7955/head
Alexander Medvednikov 2021-01-08 04:49:13 +01:00
parent 1ce93536d0
commit e3f8d448c1
5 changed files with 14 additions and 7 deletions

View File

@ -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

View File

@ -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)

View File

@ -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
}

View File

@ -603,6 +603,8 @@ pub fn (kinds []Kind) str() string {
}
pub struct Struct {
pub:
attrs []Attr
pub mut:
embeds []Type
fields []Field

View File

@ -72,6 +72,7 @@ pub struct Cookie {
http_only bool
}
[noinit]
pub struct Result {
}