checker: add check for using a private const in another module (#8501)
parent
3ef4885094
commit
e30e794884
|
@ -7,7 +7,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: remove these and uae the enum everywhere
|
// TODO: remove these and uae the enum everywhere
|
||||||
const (
|
pub const (
|
||||||
align_left = HorizontalAlign.left
|
align_left = HorizontalAlign.left
|
||||||
align_right = HorizontalAlign.right
|
align_right = HorizontalAlign.right
|
||||||
)
|
)
|
||||||
|
|
|
@ -111,12 +111,12 @@ const (
|
||||||
|
|
||||||
// no_timeout should be given to functions when no timeout is wanted (i.e. all functions
|
// no_timeout should be given to functions when no timeout is wanted (i.e. all functions
|
||||||
// return instantly)
|
// return instantly)
|
||||||
const (
|
pub const (
|
||||||
no_timeout = time.Duration(0)
|
no_timeout = time.Duration(0)
|
||||||
)
|
)
|
||||||
|
|
||||||
// infinite_timeout should be given to functions when an infinite_timeout is wanted (i.e. functions
|
// infinite_timeout should be given to functions when an infinite_timeout is wanted (i.e. functions
|
||||||
// only ever return with data)
|
// only ever return with data)
|
||||||
const (
|
pub const (
|
||||||
infinite_timeout = time.Duration(-1)
|
infinite_timeout = time.Duration(-1)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
module net
|
module net
|
||||||
|
|
||||||
// Well defined errors that are returned from socket functions
|
|
||||||
const (
|
const (
|
||||||
errors_base = 0
|
errors_base = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
// Well defined errors that are returned from socket functions
|
||||||
|
pub const (
|
||||||
err_new_socket_failed = error_with_code('net: new_socket failed to create socket', errors_base+1)
|
err_new_socket_failed = error_with_code('net: new_socket failed to create socket', errors_base+1)
|
||||||
err_option_not_settable = error_with_code('net: set_option_xxx option not settable', errors_base+2)
|
err_option_not_settable = error_with_code('net: set_option_xxx option not settable', errors_base+2)
|
||||||
err_option_wrong_type = error_with_code('net: set_option_xxx option wrong type', errors_base+3)
|
err_option_wrong_type = error_with_code('net: set_option_xxx option wrong type', errors_base+3)
|
||||||
|
|
|
@ -5,7 +5,7 @@ module time
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
const (
|
pub const (
|
||||||
days_string = 'MonTueWedThuFriSatSun'
|
days_string = 'MonTueWedThuFriSatSun'
|
||||||
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
||||||
months_string = 'JanFebMarAprMayJunJulAugSepOctNovDec'
|
months_string = 'JanFebMarAprMayJunJulAugSepOctNovDec'
|
||||||
|
|
|
@ -4037,6 +4037,9 @@ pub fn (mut c Checker) ident(mut ident ast.Ident) table.Type {
|
||||||
if obj := c.file.global_scope.find(name) {
|
if obj := c.file.global_scope.find(name) {
|
||||||
match mut obj {
|
match mut obj {
|
||||||
ast.ConstField {
|
ast.ConstField {
|
||||||
|
if !(obj.is_pub || obj.mod == c.mod || c.pref.is_test) {
|
||||||
|
c.error('constant `$obj.name` is private', ident.pos)
|
||||||
|
}
|
||||||
mut typ := obj.typ
|
mut typ := obj.typ
|
||||||
if typ == 0 {
|
if typ == 0 {
|
||||||
c.inside_const = true
|
c.inside_const = true
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/checker/tests/import_symbol_const_private_err.vv:4:19: error: constant `v.scanner.single_quote` is private
|
||||||
|
2 |
|
||||||
|
3 | fn main() {
|
||||||
|
4 | println(scanner.single_quote)
|
||||||
|
| ~~~~~~~~~~~~
|
||||||
|
5 | }
|
|
@ -0,0 +1,5 @@
|
||||||
|
import v.scanner
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println(scanner.single_quote)
|
||||||
|
}
|
|
@ -2002,6 +2002,7 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
|
||||||
field := ast.ConstField{
|
field := ast.ConstField{
|
||||||
name: full_name
|
name: full_name
|
||||||
mod: p.mod
|
mod: p.mod
|
||||||
|
is_pub: is_pub
|
||||||
expr: expr
|
expr: expr
|
||||||
pos: pos
|
pos: pos
|
||||||
comments: comments
|
comments: comments
|
||||||
|
|
|
@ -126,9 +126,12 @@ pub enum Kind {
|
||||||
_end_
|
_end_
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
pub const (
|
||||||
assign_tokens = [Kind.assign, .plus_assign, .minus_assign, .mult_assign, .div_assign, .xor_assign,
|
assign_tokens = [Kind.assign, .plus_assign, .minus_assign, .mult_assign, .div_assign, .xor_assign,
|
||||||
.mod_assign, .or_assign, .and_assign, .right_shift_assign, .left_shift_assign]
|
.mod_assign, .or_assign, .and_assign, .right_shift_assign, .left_shift_assign]
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
nr_tokens = int(Kind._end_)
|
nr_tokens = int(Kind._end_)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -160,7 +163,7 @@ pub enum AtKind {
|
||||||
vmod_file
|
vmod_file
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
pub const (
|
||||||
valid_at_tokens = ['@FN', '@MOD', '@STRUCT', '@VEXE', '@FILE', '@LINE', '@COLUMN', '@VHASH',
|
valid_at_tokens = ['@FN', '@MOD', '@STRUCT', '@VEXE', '@FILE', '@LINE', '@COLUMN', '@VHASH',
|
||||||
'@VMOD_FILE',
|
'@VMOD_FILE',
|
||||||
]
|
]
|
||||||
|
@ -291,6 +294,9 @@ fn build_token_str() []string {
|
||||||
|
|
||||||
const (
|
const (
|
||||||
token_str = build_token_str()
|
token_str = build_token_str()
|
||||||
|
)
|
||||||
|
|
||||||
|
pub const (
|
||||||
keywords = build_keys()
|
keywords = build_keys()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue