checker: struct init: handle C types

pull/4613/head
Alexander Medvednikov 2020-04-26 19:59:03 +02:00
parent 8223efe9df
commit 50a83736ff
2 changed files with 11 additions and 2 deletions

View File

@ -205,7 +205,7 @@ pub fn (mut c Checker) struct_decl(decl ast.StructDecl) {
} }
for fi, field in decl.fields { for fi, field in decl.fields {
sym := c.table.get_type_symbol(field.typ) sym := c.table.get_type_symbol(field.typ)
if sym.kind == .placeholder { if sym.kind == .placeholder && !decl.is_c && !sym.name.starts_with('C.') {
c.error('unknown type `$sym.name`', field.pos) c.error('unknown type `$sym.name`', field.pos)
} }
if field.has_default_expr { if field.has_default_expr {
@ -1855,8 +1855,11 @@ pub fn (mut c Checker) enum_val(node mut ast.EnumVal) table.Type {
c.error('not an enum (name=$node.enum_name) (type_idx=0)', node.pos) c.error('not an enum (name=$node.enum_name) (type_idx=0)', node.pos)
} }
typ := table.new_type(typ_idx) typ := table.new_type(typ_idx)
if typ == table.void_type {
c.error('not an enum', node.pos)
}
typ_sym := c.table.get_type_symbol(typ) typ_sym := c.table.get_type_symbol(typ)
// println('tname=$typ.name') // println('tname=$typ_sym.name $node.pos.line_nr $c.file.path')
if typ_sym.kind != .enum_ { if typ_sym.kind != .enum_ {
c.error('not an enum', node.pos) c.error('not an enum', node.pos)
} }

View File

@ -63,6 +63,12 @@ fn expr() {
} }
*/ */
struct User {
age int
nr_orders int
}
fn main() { fn main() {
if_test() if_test()
loop() loop()