Skip to content

Commit

Permalink
Update checker.v
Browse files Browse the repository at this point in the history
Need check `sum_type` and `function` also.
And `function` type try to get the correct mod name.
  • Loading branch information
kbkpbot authored Jan 21, 2025
1 parent 556c36f commit 9b9edfc
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -5293,11 +5293,25 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool {
return false
}
sym := c.table.sym(typ)
if !c.is_builtin_mod && sym.kind in [.struct, .alias] && !sym.is_pub && sym.mod != c.mod
&& c.comptime.comptime_for_field_var == '' && !c.inside_recheck {
c.error('${sym.kind} `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`',
pos)
return false
if !c.is_builtin_mod && sym.kind in [.struct, .alias, .sum_type, .function]! && !sym.is_pub
&& sym.mod != c.mod && c.comptime.comptime_for_field_var == '' && !c.inside_recheck {
if sym.kind == .function {
fn_info := sym.info as ast.FnType
// hack: recover fn mod from func name
mut fn_mod := fn_info.func.name.all_before_last('.')
if fn_mod == fn_info.func.name {
fn_mod = 'builtin'
}
if fn_mod != '' && fn_mod != c.mod && fn_info.func.name != '' && !fn_info.is_anon {
c.error('function type `${fn_info.func.name}` was declared as private to module `${fn_mod}`, so it can not be used inside module `${c.mod}`',
pos)
return false
}
} else {
c.error('${sym.kind} `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`',
pos)
return false
}
}
match sym.kind {
.placeholder {
Expand Down

0 comments on commit 9b9edfc

Please sign in to comment.