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:
@ -33,7 +33,7 @@ mut:
|
||||
fn new_cgen(out_name_c string) *CGen {
|
||||
gen := &CGen {
|
||||
out_path: '$TmpPath/$out_name_c'
|
||||
out: os.create_file('$TmpPath/$out_name_c')
|
||||
out: os.create('$TmpPath/$out_name_c')
|
||||
}
|
||||
return gen
|
||||
}
|
||||
|
@ -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 &&
|
||||
|
@ -515,7 +515,7 @@ mut args := ''
|
||||
'/usr/lib/x86_64-linux-gnu/crtn.o')
|
||||
println(ress)
|
||||
if ress.contains('error:') {
|
||||
os.exit(1)
|
||||
exit(1)
|
||||
}
|
||||
println('linux cross compilation done. resulting binary: "$c.out_name"')
|
||||
}
|
||||
|
@ -511,9 +511,6 @@ fn (p mut Parser) struct_decl() {
|
||||
}
|
||||
// `pub` access mod
|
||||
access_mod := if is_pub{PUBLIC} else { PRIVATE}
|
||||
if typ.name == 'Userf' {
|
||||
println('$field_name $access_mod mut=$is_mut')
|
||||
}
|
||||
p.fgen(' ')
|
||||
field_type := p.get_type()
|
||||
is_atomic := p.tok == ATOMIC
|
||||
@ -644,8 +641,8 @@ fn (p mut Parser) check(expected Token) {
|
||||
fn (p mut Parser) error(s string) {
|
||||
// Dump all vars and types for debugging
|
||||
if false {
|
||||
file_types := os.create_file('$TmpPath/types')
|
||||
file_vars := os.create_file('$TmpPath/vars')
|
||||
file_types := os.create('$TmpPath/types')
|
||||
file_vars := os.create('$TmpPath/vars')
|
||||
// ////debug("ALL T", q.J(p.table.types))
|
||||
// os.write_to_file('/var/tmp/lang.types', '')//pes(p.table.types))
|
||||
// //debug("ALL V", q.J(p.table.vars))
|
||||
@ -662,7 +659,7 @@ fn (p mut Parser) error(s string) {
|
||||
if p.file_path.contains('v/compiler') || cur_path.contains('v/compiler') {
|
||||
println('\n====================')
|
||||
println('It looks like you are building V. It is being frequently updated every day.' +
|
||||
' Most likely there was a change that lead to this error. ')
|
||||
' If you didn\'t modify the compiler\'s code, most likely there was a change that lead to this error. ')
|
||||
println('Try to run `git pull`, that will most likely fix it.')
|
||||
println('If `git pull` doesn\'t help, re-install V from source or download a precompiled' +
|
||||
' binary from https://vlang.io')
|
||||
|
@ -239,7 +239,7 @@ fn (t Token) str() string {
|
||||
fn (t Token) is_decl() bool {
|
||||
// TODO return t in [FUNC ,TIP, CONST, IMPORT_CONST ,AT ,EOF]
|
||||
return t == ENUM || t == INTERFACE || t == FUNC || t == STRUCT || t == TIP ||
|
||||
t == CONST || t == IMPORT_CONST || t == AT || t == EOF
|
||||
t == CONST || t == IMPORT_CONST || t == AT || t == PUB || t == EOF
|
||||
}
|
||||
|
||||
const (
|
||||
|
Reference in New Issue
Block a user