checker,parser: treat C.Struct fields as public by default
parent
6229965569
commit
2c3f695469
|
@ -448,7 +448,8 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) table.Type {
|
|||
return table.void_type
|
||||
}
|
||||
}
|
||||
if !type_sym.is_public && type_sym.kind != .placeholder && type_sym.mod != c.mod {
|
||||
if !type_sym.is_public && type_sym.kind != .placeholder && type_sym.mod != c.mod &&
|
||||
type_sym.language != .c {
|
||||
c.error('type `$type_sym.source_name` is private', struct_init.pos)
|
||||
}
|
||||
match type_sym.kind {
|
||||
|
@ -1736,7 +1737,7 @@ pub fn (mut c Checker) selector_expr(mut selector_expr ast.SelectorExpr) table.T
|
|||
}
|
||||
mut unknown_field_msg := 'type `$sym.source_name` has no field or method `$field_name`'
|
||||
if field := c.table.struct_find_field(sym, field_name) {
|
||||
if sym.mod != c.mod && !field.is_pub {
|
||||
if sym.mod != c.mod && !field.is_pub && sym.language != .c {
|
||||
c.error('field `${sym.source_name}.$field_name` is not public', selector_expr.pos)
|
||||
}
|
||||
selector_expr.typ = field.typ
|
||||
|
|
|
@ -305,14 +305,14 @@ pub fn (mut p Parser) parse_any_type(language table.Language, is_ptr bool, check
|
|||
if p.peek_tok.kind == .lt {
|
||||
return p.parse_generic_struct_inst_type(name)
|
||||
}
|
||||
return p.parse_enum_or_struct_type(name)
|
||||
return p.parse_enum_or_struct_type(name, language)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut p Parser) parse_enum_or_struct_type(name string) table.Type {
|
||||
pub fn (mut p Parser) parse_enum_or_struct_type(name string, language table.Language) table.Type {
|
||||
// struct / enum / placeholder
|
||||
// struct / enum
|
||||
mut idx := p.table.find_type_idx(name)
|
||||
|
@ -320,7 +320,7 @@ pub fn (mut p Parser) parse_enum_or_struct_type(name string) table.Type {
|
|||
return table.new_type(idx)
|
||||
}
|
||||
// not found - add placeholder
|
||||
idx = p.table.add_placeholder_type(name)
|
||||
idx = p.table.add_placeholder_type(name, language)
|
||||
// println('NOT FOUND: $name - adding placeholder - $idx')
|
||||
return table.new_type(idx)
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ pub fn (mut p Parser) parse_generic_struct_inst_type(name string) table.Type {
|
|||
if gt_idx > 0 {
|
||||
return table.new_type(gt_idx)
|
||||
}
|
||||
gt_idx = p.table.add_placeholder_type(bs_name)
|
||||
gt_idx = p.table.add_placeholder_type(bs_name, .v)
|
||||
idx := p.table.register_type_symbol(table.TypeSymbol{
|
||||
kind: .generic_struct_inst
|
||||
name: bs_name
|
||||
|
@ -380,5 +380,5 @@ pub fn (mut p Parser) parse_generic_struct_inst_type(name string) table.Type {
|
|||
})
|
||||
return table.new_type(idx)
|
||||
}
|
||||
return p.parse_enum_or_struct_type(name)
|
||||
return p.parse_enum_or_struct_type(name, .v)
|
||||
}
|
||||
|
|
|
@ -1559,7 +1559,7 @@ fn (mut p Parser) import_syms(mut parent ast.Import) {
|
|||
alias := p.check_name()
|
||||
name := '$parent.mod\.$alias'
|
||||
if alias[0].is_capital() {
|
||||
idx := p.table.add_placeholder_type(name)
|
||||
idx := p.table.add_placeholder_type(name, .v)
|
||||
typ := table.new_type(idx)
|
||||
prepend_mod_name := p.prepend_mod(alias)
|
||||
p.table.register_type_symbol(table.TypeSymbol{
|
||||
|
|
|
@ -249,6 +249,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
|||
t := table.TypeSymbol{
|
||||
kind: .struct_
|
||||
name: name
|
||||
language: language
|
||||
source_name: name
|
||||
mod: p.mod
|
||||
info: table.Struct{
|
||||
|
|
|
@ -41,6 +41,7 @@ pub mut:
|
|||
mod string
|
||||
is_public bool
|
||||
is_written bool // set to true, when the backend definition for a symbol had been written, to avoid duplicates
|
||||
language Language
|
||||
}
|
||||
|
||||
// max of 8
|
||||
|
|
|
@ -621,7 +621,7 @@ pub fn (mut t Table) find_or_register_fn_type(mod string, f Fn, is_anon bool, ha
|
|||
})
|
||||
}
|
||||
|
||||
pub fn (mut t Table) add_placeholder_type(name string) int {
|
||||
pub fn (mut t Table) add_placeholder_type(name string, language Language) int {
|
||||
mut modname := ''
|
||||
if name.contains('.') {
|
||||
modname = name.all_before_last('.')
|
||||
|
@ -629,6 +629,7 @@ pub fn (mut t Table) add_placeholder_type(name string) int {
|
|||
ph_type := TypeSymbol{
|
||||
kind: .placeholder
|
||||
name: name
|
||||
language: language
|
||||
source_name: name
|
||||
mod: modname
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue