1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: make use of private enum from outside module an error. (#9821)

This commit is contained in:
zakuro 2021-04-22 13:07:56 +09:00 committed by GitHub
parent c85eefa5b2
commit 7443179cc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 117 additions and 105 deletions

View File

@ -1,7 +1,7 @@
module builtin module builtin
// ChanState describes the result of an attempted channel transaction. // ChanState describes the result of an attempted channel transaction.
enum ChanState { pub enum ChanState {
success success
not_ready // push()/pop() would have to wait, but no_block was requested not_ready // push()/pop() would have to wait, but no_block was requested
closed closed

View File

@ -1,6 +1,6 @@
module net module net
enum SocketOption { pub enum SocketOption {
// TODO: SO_ACCEPT_CONN is not here becuase windows doesnt support it // TODO: SO_ACCEPT_CONN is not here becuase windows doesnt support it
// and there is no easy way to define it // and there is no easy way to define it
@ -28,10 +28,10 @@ enum SocketOption {
const ( const (
opts_bool = [SocketOption.broadcast, .debug, .dont_route, .error, .keep_alive, .oob_inline] opts_bool = [SocketOption.broadcast, .debug, .dont_route, .error, .keep_alive, .oob_inline]
opts_int = [ opts_int = [
.recieve_buf_size, .recieve_buf_size,
.recieve_low_size, .recieve_low_size,
.recieve_timeout, .recieve_timeout,
.send_buf_size, .send_buf_size,
.send_low_size, .send_low_size,
.send_timeout, .send_timeout,
@ -39,15 +39,15 @@ const (
opts_can_set = [ opts_can_set = [
SocketOption.broadcast, SocketOption.broadcast,
.debug, .debug,
.dont_route, .dont_route,
.keep_alive, .keep_alive,
.linger, .linger,
.oob_inline, .oob_inline,
.recieve_buf_size, .recieve_buf_size,
.recieve_low_size, .recieve_low_size,
.recieve_timeout, .recieve_timeout,
.send_buf_size, .send_buf_size,
.send_low_size, .send_low_size,
.send_timeout, .send_timeout,

View File

@ -1,42 +1,42 @@
import os module os
const ( const (
// tfolder will contain all the temporary files/subfolders made by // tfolder will contain all the temporary files/subfolders made by
// the different tests. It would be removed in testsuite_end(), so // the different tests. It would be removed in testsuite_end(), so
// individual os tests do not need to clean up after themselves. // individual os tests do not need to clean up after themselves.
tfolder = os.join_path(os.temp_dir(), 'v', 'tests', 'inode_test') tfolder = join_path(temp_dir(), 'v', 'tests', 'inode_test')
) )
fn testsuite_begin() { fn testsuite_begin() {
eprintln('testsuite_begin, tfolder = $tfolder') eprintln('testsuite_begin, tfolder = $os.tfolder')
os.rmdir_all(tfolder) or {} rmdir_all(os.tfolder) or {}
assert !os.is_dir(tfolder) assert !is_dir(os.tfolder)
os.mkdir_all(tfolder) or { panic(err) } mkdir_all(os.tfolder) or { panic(err) }
os.chdir(tfolder) chdir(os.tfolder)
assert os.is_dir(tfolder) assert is_dir(os.tfolder)
} }
fn testsuite_end() { fn testsuite_end() {
os.chdir(os.wd_at_startup) chdir(wd_at_startup)
os.rmdir_all(tfolder) or { panic(err) } rmdir_all(os.tfolder) or { panic(err) }
assert !os.is_dir(tfolder) assert !is_dir(os.tfolder)
} }
fn test_inode_file_type() { fn test_inode_file_type() {
filename := './test1.txt' filename := './test1.txt'
mut file := os.open_file(filename, 'w', 0o600) or { return } mut file := open_file(filename, 'w', 0o600) or { return }
file.close() file.close()
mode := os.inode(filename) mode := inode(filename)
os.rm(filename) or { panic(err) } rm(filename) or { panic(err) }
assert mode.typ == .regular assert mode.typ == .regular
} }
fn test_inode_file_owner_permission() { fn test_inode_file_owner_permission() {
filename := './test2.txt' filename := './test2.txt'
mut file := os.open_file(filename, 'w', 0o600) or { return } mut file := open_file(filename, 'w', 0o600) or { return }
file.close() file.close()
mode := os.inode(filename) mode := inode(filename)
os.rm(filename) or {} rm(filename) or {}
assert mode.owner.read assert mode.owner.read
assert mode.owner.write assert mode.owner.write
assert !mode.owner.execute assert !mode.owner.execute

View File

@ -6,9 +6,9 @@
* in order to test it independently from the support in the core language * in order to test it independently from the support in the core language
*/ */
import sync module sync
fn do_rec_i64(mut ch sync.Channel) { fn do_rec_i64(mut ch Channel) {
mut sum := i64(0) mut sum := i64(0)
for _ in 0 .. 300 { for _ in 0 .. 300 {
mut a := i64(0) mut a := i64(0)
@ -18,20 +18,20 @@ fn do_rec_i64(mut ch sync.Channel) {
assert sum == 300 * (300 - 1) / 2 assert sum == 300 * (300 - 1) / 2
} }
fn do_send_int(mut ch sync.Channel) { fn do_send_int(mut ch Channel) {
for i in 0 .. 300 { for i in 0 .. 300 {
ch.push(&i) ch.push(&i)
} }
} }
fn do_send_byte(mut ch sync.Channel) { fn do_send_byte(mut ch Channel) {
for i in 0 .. 300 { for i in 0 .. 300 {
ii := byte(i) ii := byte(i)
ch.push(&ii) ch.push(&ii)
} }
} }
fn do_send_i64(mut ch sync.Channel) { fn do_send_i64(mut ch Channel) {
for i in 0 .. 300 { for i in 0 .. 300 {
ii := i64(i) ii := i64(i)
ch.push(&ii) ch.push(&ii)
@ -39,16 +39,16 @@ fn do_send_i64(mut ch sync.Channel) {
} }
fn test_select() { fn test_select() {
mut chi := sync.new_channel<int>(0) mut chi := new_channel<int>(0)
mut chl := sync.new_channel<i64>(1) mut chl := new_channel<i64>(1)
mut chb := sync.new_channel<byte>(10) mut chb := new_channel<byte>(10)
mut recch := sync.new_channel<i64>(0) mut recch := new_channel<i64>(0)
go do_rec_i64(mut recch) go do_rec_i64(mut recch)
go do_send_int(mut chi) go do_send_int(mut chi)
go do_send_byte(mut chb) go do_send_byte(mut chb)
go do_send_i64(mut chl) go do_send_i64(mut chl)
mut channels := [chi, recch, chl, chb] mut channels := [chi, recch, chl, chb]
directions := [sync.Direction.pop, .push, .pop, .pop] directions := [Direction.pop, .push, .pop, .pop]
mut sum := i64(0) mut sum := i64(0)
mut rl := i64(0) mut rl := i64(0)
mut ri := int(0) mut ri := int(0)
@ -56,7 +56,7 @@ fn test_select() {
mut sl := i64(0) mut sl := i64(0)
mut objs := [voidptr(&ri), &sl, &rl, &rb] mut objs := [voidptr(&ri), &sl, &rl, &rb]
for _ in 0 .. 1200 { for _ in 0 .. 1200 {
idx := sync.channel_select(mut channels, directions, mut objs, -1) idx := channel_select(mut channels, directions, mut objs, -1)
match idx { match idx {
0 { 0 {
sum += ri sum += ri

View File

@ -1,7 +1,8 @@
import sync module sync
import time import time
fn do_rec_i64(mut ch sync.Channel) { fn do_rec_i64(mut ch Channel) {
mut sum := i64(0) mut sum := i64(0)
for i in 0 .. 300 { for i in 0 .. 300 {
if i == 200 { if i == 200 {
@ -15,14 +16,14 @@ fn do_rec_i64(mut ch sync.Channel) {
assert sum == 200 * (200 - 1) / 2 assert sum == 200 * (200 - 1) / 2
} }
fn do_send_int(mut ch sync.Channel) { fn do_send_int(mut ch Channel) {
for i in 0 .. 300 { for i in 0 .. 300 {
ch.push(&i) ch.push(&i)
} }
ch.close() ch.close()
} }
fn do_send_byte(mut ch sync.Channel) { fn do_send_byte(mut ch Channel) {
for i in 0 .. 300 { for i in 0 .. 300 {
ii := byte(i) ii := byte(i)
ch.push(&ii) ch.push(&ii)
@ -30,7 +31,7 @@ fn do_send_byte(mut ch sync.Channel) {
ch.close() ch.close()
} }
fn do_send_i64(mut ch sync.Channel) { fn do_send_i64(mut ch Channel) {
for i in 0 .. 300 { for i in 0 .. 300 {
ii := i64(i) ii := i64(i)
ch.push(&ii) ch.push(&ii)
@ -39,16 +40,16 @@ fn do_send_i64(mut ch sync.Channel) {
} }
fn test_select() { fn test_select() {
mut chi := sync.new_channel<int>(0) mut chi := new_channel<int>(0)
mut chl := sync.new_channel<i64>(1) mut chl := new_channel<i64>(1)
mut chb := sync.new_channel<byte>(10) mut chb := new_channel<byte>(10)
mut recch := sync.new_channel<i64>(0) mut recch := new_channel<i64>(0)
go do_rec_i64(mut recch) go do_rec_i64(mut recch)
go do_send_int(mut chi) go do_send_int(mut chi)
go do_send_byte(mut chb) go do_send_byte(mut chb)
go do_send_i64(mut chl) go do_send_i64(mut chl)
mut channels := [chi, recch, chl, chb] mut channels := [chi, recch, chl, chb]
directions := [sync.Direction.pop, .push, .pop, .pop] directions := [Direction.pop, .push, .pop, .pop]
mut sum := i64(0) mut sum := i64(0)
mut rl := i64(0) mut rl := i64(0)
mut ri := int(0) mut ri := int(0)
@ -56,7 +57,7 @@ fn test_select() {
mut sl := i64(0) mut sl := i64(0)
mut objs := [voidptr(&ri), &sl, &rl, &rb] mut objs := [voidptr(&ri), &sl, &rl, &rb]
for j in 0 .. 1101 { for j in 0 .. 1101 {
idx := sync.channel_select(mut channels, directions, mut objs, time.infinite) idx := channel_select(mut channels, directions, mut objs, time.infinite)
match idx { match idx {
0 { 0 {
sum += ri sum += ri

View File

@ -6031,6 +6031,9 @@ pub fn (mut c Checker) enum_val(mut node ast.EnumVal) ast.Type {
c.error('not an enum', node.pos) c.error('not an enum', node.pos)
return ast.void_type return ast.void_type
} }
if !(typ_sym.is_public || typ_sym.mod == c.mod) {
c.error('enum `$typ_sym.name` is private', node.pos)
}
// info := typ_sym.info as ast.Enum // info := typ_sym.info as ast.Enum
info := typ_sym.enum_info() info := typ_sym.enum_info()
// rintln('checker: x = $info.x enum val $c.expected_type $typ_sym.name') // rintln('checker: x = $info.x enum val $c.expected_type $typ_sym.name')

View File

@ -1,6 +0,0 @@
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 | }

View File

@ -1,5 +0,0 @@
import v.scanner
fn main() {
println(scanner.single_quote)
}

View File

@ -1,18 +0,0 @@
vlib/v/checker/tests/import_symbol_fn_private_err.vv:1:20: error: module `time` function `since()` is private
1 | import time { now, since }
| ~~~~~
2 | fn main() {
3 | since(now())
vlib/v/checker/tests/import_symbol_fn_private_err.vv:3:3: error: function `time.since` is private
1 | import time { now, since }
2 | fn main() {
3 | since(now())
| ~~~~~~~~~~~~
4 | }
5 |
vlib/v/checker/tests/import_symbol_fn_private_err.vv:7:20: error: method `map[string]int.exists` is private
5 |
6 | fn method() {
7 | _ = map{'h':2}.exists('h')
| ~~~~~~~~~~~
8 | }

View File

@ -1,8 +0,0 @@
import time { now, since }
fn main() {
since(now())
}
fn method() {
_ = map{'h':2}.exists('h')
}

View File

@ -0,0 +1,48 @@
vlib/v/checker/tests/import_symbol_private_err.vv:3:20: error: module `time` function `since()` is private
1 | import v.scanner
2 | import v.parser
3 | import time { now, since }
| ~~~~~
4 | import io { ReaderWriterImpl }
5 |
vlib/v/checker/tests/import_symbol_private_err.vv:4:13: error: module `io` type `ReaderWriterImpl` is private
2 | import v.parser
3 | import time { now, since }
4 | import io { ReaderWriterImpl }
| ~~~~~~~~~~~~~~~~
5 |
6 | fn main() {
vlib/v/checker/tests/import_symbol_private_err.vv:7:18: error: constant `v.scanner.single_quote` is private
5 |
6 | fn main() {
7 | println(scanner.single_quote)
| ~~~~~~~~~~~~
8 | println(parser.State.html)
9 | since(now())
vlib/v/checker/tests/import_symbol_private_err.vv:8:17: error: enum `v.parser.State` is private
6 | fn main() {
7 | println(scanner.single_quote)
8 | println(parser.State.html)
| ~~~~~~~~~~
9 | since(now())
10 | _ = map{'h': 2}.exists('h')
vlib/v/checker/tests/import_symbol_private_err.vv:9:2: error: function `time.since` is private
7 | println(scanner.single_quote)
8 | println(parser.State.html)
9 | since(now())
| ~~~~~~~~~~~~
10 | _ = map{'h': 2}.exists('h')
11 | _ = ReaderWriterImpl{}
vlib/v/checker/tests/import_symbol_private_err.vv:10:18: error: method `map[string]int.exists` is private
8 | println(parser.State.html)
9 | since(now())
10 | _ = map{'h': 2}.exists('h')
| ~~~~~~~~~~~
11 | _ = ReaderWriterImpl{}
12 | }
vlib/v/checker/tests/import_symbol_private_err.vv:11:6: error: type `io.ReaderWriterImpl` is private
9 | since(now())
10 | _ = map{'h': 2}.exists('h')
11 | _ = ReaderWriterImpl{}
| ~~~~~~~~~~~~~~~~~~
12 | }

View File

@ -0,0 +1,12 @@
import v.scanner
import v.parser
import time { now, since }
import io { ReaderWriterImpl }
fn main() {
println(scanner.single_quote)
println(parser.State.html)
since(now())
_ = map{'h': 2}.exists('h')
_ = ReaderWriterImpl{}
}

View File

@ -1,11 +0,0 @@
vlib/v/checker/tests/import_symbol_type_private_err.vv:1:13: error: module `io` type `ReaderWriterImpl` is private
1 | import io { ReaderWriterImpl }
| ~~~~~~~~~~~~~~~~
2 | fn main() {
3 | _ := ReaderWriterImpl{}
vlib/v/checker/tests/import_symbol_type_private_err.vv:3:8: error: type `io.ReaderWriterImpl` is private
1 | import io { ReaderWriterImpl }
2 | fn main() {
3 | _ := ReaderWriterImpl{}
| ~~~~~~~~~~~~~~~~~~
4 | }

View File

@ -1,4 +0,0 @@
import io { ReaderWriterImpl }
fn main() {
_ := ReaderWriterImpl{}
}

View File

@ -49,7 +49,7 @@ enum Flag {
} }
// State represents the state of the websocket connection. // State represents the state of the websocket connection.
enum State { pub enum State {
connecting = 0 connecting = 0
open open
closing closing