parser/checker: do not allow using private types from other modules
parent
9aa1a65489
commit
32a7bd3a48
|
@ -29,9 +29,9 @@ const (
|
|||
OpenDataConnection = 150
|
||||
CloseDataConnection = 226
|
||||
CommandOk = 200
|
||||
Denied = 550
|
||||
denied = 550
|
||||
PassiveMode = 227
|
||||
Complete = 226
|
||||
complete = 226
|
||||
)
|
||||
|
||||
struct DTP {
|
||||
|
@ -173,13 +173,13 @@ pub fn (ftp FTP) pwd() string {
|
|||
pub fn (ftp FTP) cd(dir string) {
|
||||
ftp.write('CWD $dir') or { return }
|
||||
mut code, mut data := ftp.read()
|
||||
match code {
|
||||
Denied {
|
||||
match int(code) {
|
||||
denied {
|
||||
$if debug {
|
||||
println('CD $dir denied!')
|
||||
}
|
||||
}
|
||||
Complete {
|
||||
complete {
|
||||
code, data = ftp.read()
|
||||
}
|
||||
else {}
|
||||
|
@ -233,7 +233,7 @@ pub fn (ftp FTP) dir() ?[]string {
|
|||
|
||||
ftp.write('LIST') or {}
|
||||
code, _ := ftp.read()
|
||||
if code == Denied {
|
||||
if code == denied {
|
||||
return error('LIST denied')
|
||||
}
|
||||
if code != OpenDataConnection {
|
||||
|
@ -267,7 +267,7 @@ pub fn (ftp FTP) get(file string) ?[]byte {
|
|||
ftp.write('RETR $file') or {}
|
||||
code, _ := ftp.read()
|
||||
|
||||
if code == Denied {
|
||||
if code == denied {
|
||||
return error('Permission denied')
|
||||
}
|
||||
|
||||
|
|
|
@ -393,6 +393,11 @@ fn vpclose(f voidptr) int {
|
|||
}
|
||||
}
|
||||
|
||||
struct Foo2 {
|
||||
x int
|
||||
|
||||
}
|
||||
|
||||
pub struct Result {
|
||||
pub:
|
||||
exit_code int
|
||||
|
|
|
@ -6,7 +6,7 @@ module cflag
|
|||
import os
|
||||
|
||||
// parsed cflag
|
||||
struct CFlag {
|
||||
pub struct CFlag {
|
||||
mod string // the module in which the flag was given
|
||||
os string // eg. windows | darwin | linux
|
||||
name string // eg. -I
|
||||
|
|
|
@ -260,6 +260,9 @@ pub fn (mut c Checker) struct_init(struct_init mut ast.StructInit) table.Type {
|
|||
struct_init.typ = c.expected_type
|
||||
}
|
||||
type_sym := c.table.get_type_symbol(struct_init.typ)
|
||||
if !type_sym.is_public && type_sym.mod != c.mod {
|
||||
c.warn('type `$type_sym.name` is private', struct_init.pos)
|
||||
}
|
||||
// println('check struct $typ_sym.name')
|
||||
match type_sym.kind {
|
||||
.placeholder {
|
||||
|
|
|
@ -12,7 +12,7 @@ import v.util
|
|||
import term
|
||||
import os
|
||||
|
||||
struct Parser {
|
||||
pub struct Parser {
|
||||
scanner &scanner.Scanner
|
||||
file_name string // "/home/user/hello.v"
|
||||
file_name_dir string // "/home/user"
|
||||
|
@ -1202,6 +1202,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
|
|||
info: table.SumType{
|
||||
variants: sum_variants
|
||||
}
|
||||
is_public: is_pub
|
||||
})
|
||||
return ast.SumTypeDecl{
|
||||
name: name
|
||||
|
@ -1220,6 +1221,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
|
|||
info: table.Alias{
|
||||
foo: ''
|
||||
}
|
||||
is_public: is_pub
|
||||
})
|
||||
return ast.AliasTypeDecl{
|
||||
name: name
|
||||
|
|
|
@ -161,6 +161,7 @@ fn (mut p Parser) struct_decl() ast.StructDecl {
|
|||
is_union: is_union
|
||||
}
|
||||
mod: p.mod
|
||||
is_public: is_pub
|
||||
}
|
||||
mut ret := 0
|
||||
if p.builtin_mod && t.name in table.builtin_type_names {
|
||||
|
|
|
@ -26,6 +26,7 @@ mut:
|
|||
name string
|
||||
methods []Fn
|
||||
mod string
|
||||
is_public bool
|
||||
}
|
||||
|
||||
pub enum TypeFlag {
|
||||
|
@ -546,7 +547,7 @@ pub:
|
|||
// NB: FExpr here is a actually an ast.Expr .
|
||||
// It should always be used by casting to ast.Expr, using ast.fe2ex()/ast.ex2fe()
|
||||
// That hack is needed to break an import cycle between v.ast and v.table .
|
||||
type FExpr = byteptr | voidptr
|
||||
pub type FExpr = byteptr | voidptr
|
||||
|
||||
pub struct Field {
|
||||
pub:
|
||||
|
|
Loading…
Reference in New Issue