mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
don't allow calling private functions/methods
This commit is contained in:
@ -23,7 +23,7 @@ mut:
|
||||
name string
|
||||
is_c bool
|
||||
receiver_typ string
|
||||
is_private bool
|
||||
is_public bool
|
||||
is_method bool
|
||||
returns_error bool
|
||||
is_decl bool // type myfn fn(int, int)
|
||||
@ -94,11 +94,12 @@ fn (p mut Parser) is_sig() bool {
|
||||
(p.file_path.contains(TmpPath))
|
||||
}
|
||||
|
||||
fn new_fn(pkg string) *Fn {
|
||||
fn new_fn(pkg string, is_public bool) *Fn {
|
||||
mut f := &Fn {
|
||||
pkg: pkg
|
||||
local_vars: [Var{}
|
||||
; MaxLocalVars]
|
||||
is_public: is_public
|
||||
}
|
||||
return f
|
||||
}
|
||||
@ -112,7 +113,7 @@ fn (p mut Parser) fn_decl() {
|
||||
}
|
||||
p.returns = false
|
||||
p.next()
|
||||
mut f := new_fn(p.pkg)
|
||||
mut f := new_fn(p.pkg, is_pub)
|
||||
// Method receiver
|
||||
mut receiver_typ := ''
|
||||
if p.tok == LPAR {
|
||||
@ -493,6 +494,9 @@ fn (p mut Parser) async_fn_call(f Fn, method_ph int, receiver_var, receiver_type
|
||||
}
|
||||
|
||||
fn (p mut Parser) fn_call(f Fn, method_ph int, receiver_var, receiver_type string) {
|
||||
if !f.is_public && !f.is_c && f.pkg != p.pkg && f.pkg != 'builtin' {
|
||||
p.error('$p.run function `$f.name` is private $f.is_public')
|
||||
}
|
||||
p.calling_c = f.is_c
|
||||
is_print := p.is_prod &&// Hide prints only in prod
|
||||
!p.is_test &&
|
||||
|
Reference in New Issue
Block a user