From 139f4881884b8a7bd27d84bee1c4ebd7c0124fe3 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 21 Jan 2025 07:54:21 -0300 Subject: [PATCH 01/15] fix message --- vlib/v/checker/checker.v | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 532bede4f36e9a..c58e1b842fb10a 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -5293,8 +5293,8 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool { return false } sym := c.table.sym(typ) - if !c.is_builtin_mod && sym.kind == .struct && !sym.is_pub && sym.mod != c.mod { - c.error('struct `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`', + if !c.is_builtin_mod && sym.kind in [.struct, .alias] && !sym.is_pub && sym.mod != c.mod { + c.error('${sym.kind} `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`', pos) return false } From 9abf1affa68e4100b6f62faa85cc38d716d1a4bf Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 21 Jan 2025 07:59:18 -0300 Subject: [PATCH 02/15] make intptr_t public --- vlib/builtin/cfns.c.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vlib/builtin/cfns.c.v b/vlib/builtin/cfns.c.v index 5f086d3b3d2ba6..67c646d07800a0 100644 --- a/vlib/builtin/cfns.c.v +++ b/vlib/builtin/cfns.c.v @@ -233,7 +233,7 @@ fn C.sysctl(name &int, namelen u32, oldp voidptr, oldlenp voidptr, newp voidptr, @[trusted] fn C._fileno(int) int -type C.intptr_t = voidptr +pub type C.intptr_t = voidptr fn C._get_osfhandle(fd int) C.intptr_t From 97ad6d943f9ef944115b7d49600b56a0afb424cb Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 21 Jan 2025 08:03:08 -0300 Subject: [PATCH 03/15] make public --- vlib/builtin/int.v | 2 +- vlib/builtin/js/int.js.v | 2 +- vlib/builtin/wasm/wasi/int.v | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vlib/builtin/int.v b/vlib/builtin/int.v index 4c8e1b1d74009e..a085e965fa9220 100644 --- a/vlib/builtin/int.v +++ b/vlib/builtin/int.v @@ -7,7 +7,7 @@ pub struct VContext { allocator int } -type byte = u8 +pub type byte = u8 // ptr_str returns the address of `ptr` as a `string`. pub fn ptr_str(ptr voidptr) string { diff --git a/vlib/builtin/js/int.js.v b/vlib/builtin/js/int.js.v index fdce4078fdebeb..41e53192bc2d94 100644 --- a/vlib/builtin/js/int.js.v +++ b/vlib/builtin/js/int.js.v @@ -1,6 +1,6 @@ module builtin -type byte = u8 +pub type byte = u8 pub const min_i8 = i8(-128) pub const max_i8 = i8(127) diff --git a/vlib/builtin/wasm/wasi/int.v b/vlib/builtin/wasm/wasi/int.v index 289890d8cda224..0c31ce96f47dfe 100644 --- a/vlib/builtin/wasm/wasi/int.v +++ b/vlib/builtin/wasm/wasi/int.v @@ -1,6 +1,6 @@ module builtin -type byte = u8 +pub type byte = u8 // type i32 = int From be507641ffe6b95a724f08cb36110c9c190b9abe Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 21 Jan 2025 09:12:18 -0300 Subject: [PATCH 04/15] avoid checking inside for comptime for now --- vlib/v/checker/checker.v | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index c58e1b842fb10a..4bbd2da888a89e 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -5293,7 +5293,8 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool { return false } sym := c.table.sym(typ) - if !c.is_builtin_mod && sym.kind in [.struct, .alias] && !sym.is_pub && sym.mod != c.mod { + if !c.is_builtin_mod && sym.kind in [.struct, .alias] && !sym.is_pub && sym.mod != c.mod + && c.comptime.comptime_for_field_var == '' { c.error('${sym.kind} `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`', pos) return false From 7e301100a2f4088ba80be12078f2eab2efcdfe10 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 21 Jan 2025 13:26:16 -0300 Subject: [PATCH 05/15] fix --- vlib/v/checker/checker.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 4bbd2da888a89e..c0ab0c47c54911 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -5294,7 +5294,7 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool { } sym := c.table.sym(typ) if !c.is_builtin_mod && sym.kind in [.struct, .alias] && !sym.is_pub && sym.mod != c.mod - && c.comptime.comptime_for_field_var == '' { + && c.comptime.comptime_for_field_var == '' && !c.inside_recheck { c.error('${sym.kind} `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`', pos) return false From e564485cee4736623e63998d5bd8673211b44838 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 21 Jan 2025 14:05:55 -0300 Subject: [PATCH 06/15] make alias compress.szip.Zip public --- vlib/compress/szip/szip.c.v | 2 +- vlib/v/checker/checker.v | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/vlib/compress/szip/szip.c.v b/vlib/compress/szip/szip.c.v index 91a7ee64c75ebf..44bba6bd57f802 100644 --- a/vlib/compress/szip/szip.c.v +++ b/vlib/compress/szip/szip.c.v @@ -14,7 +14,7 @@ pub: pub struct C.zip_t { } -type Zip = C.zip_t +pub type Zip = C.zip_t pub type Fn_on_extract_entry = fn (&&char, &&char) int diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index c0ab0c47c54911..bd24d56497ed5c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -5295,6 +5295,7 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool { sym := c.table.sym(typ) if !c.is_builtin_mod && sym.kind in [.struct, .alias] && !sym.is_pub && sym.mod != c.mod && c.comptime.comptime_for_field_var == '' && !c.inside_recheck { + println('>>> ${sym.mod} ${c.mod}') c.error('${sym.kind} `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`', pos) return false From 556c36f8e6369aff2ab6d00d712d27ba58bcb105 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 21 Jan 2025 17:51:08 -0300 Subject: [PATCH 07/15] fix --- vlib/v/checker/checker.v | 1 - 1 file changed, 1 deletion(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index bd24d56497ed5c..c0ab0c47c54911 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -5295,7 +5295,6 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool { sym := c.table.sym(typ) if !c.is_builtin_mod && sym.kind in [.struct, .alias] && !sym.is_pub && sym.mod != c.mod && c.comptime.comptime_for_field_var == '' && !c.inside_recheck { - println('>>> ${sym.mod} ${c.mod}') c.error('${sym.kind} `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`', pos) return false From 9b9edfc05dd5c41fb2b3de3120aef2ccb8a67e9c Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Wed, 22 Jan 2025 06:42:21 +0800 Subject: [PATCH 08/15] Update checker.v Need check `sum_type` and `function` also. And `function` type try to get the correct mod name. --- vlib/v/checker/checker.v | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index c0ab0c47c54911..b292ef88b7377b 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -5293,11 +5293,25 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool { return false } sym := c.table.sym(typ) - if !c.is_builtin_mod && sym.kind in [.struct, .alias] && !sym.is_pub && sym.mod != c.mod - && c.comptime.comptime_for_field_var == '' && !c.inside_recheck { - c.error('${sym.kind} `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`', - pos) - return false + if !c.is_builtin_mod && sym.kind in [.struct, .alias, .sum_type, .function]! && !sym.is_pub + && sym.mod != c.mod && c.comptime.comptime_for_field_var == '' && !c.inside_recheck { + if sym.kind == .function { + fn_info := sym.info as ast.FnType + // hack: recover fn mod from func name + mut fn_mod := fn_info.func.name.all_before_last('.') + if fn_mod == fn_info.func.name { + fn_mod = 'builtin' + } + if fn_mod != '' && fn_mod != c.mod && fn_info.func.name != '' && !fn_info.is_anon { + c.error('function type `${fn_info.func.name}` was declared as private to module `${fn_mod}`, so it can not be used inside module `${c.mod}`', + pos) + return false + } + } else { + c.error('${sym.kind} `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`', + pos) + return false + } } match sym.kind { .placeholder { From b14eb4529fae5a0f51d3a718fad33f87f129891b Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Wed, 22 Jan 2025 07:36:45 +0800 Subject: [PATCH 09/15] Update checker.v fix error "vlib/x/json2/decoder2/decode_sumtype.v:50:11: error: sum_type `Sum` was declared as private to module `main`, so it can not be used inside module `x.json2.decoder2`" Assume type define in `main` can be used as generic type in other module. --- vlib/v/checker/checker.v | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index b292ef88b7377b..adaafc840585f7 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -5294,7 +5294,8 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool { } sym := c.table.sym(typ) if !c.is_builtin_mod && sym.kind in [.struct, .alias, .sum_type, .function]! && !sym.is_pub - && sym.mod != c.mod && c.comptime.comptime_for_field_var == '' && !c.inside_recheck { + && sym.mod != c.mod && sym.mod != 'main' && c.comptime.comptime_for_field_var == '' + && !c.inside_recheck { if sym.kind == .function { fn_info := sym.info as ast.FnType // hack: recover fn mod from func name From f2f15fa62180f7a4a1a1d92641acf1ae9d0a9a74 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 22 Jan 2025 07:27:36 -0300 Subject: [PATCH 10/15] make sumtype encoding.csv.CellValue public --- vlib/encoding/csv/csv_reader_random_access.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vlib/encoding/csv/csv_reader_random_access.v b/vlib/encoding/csv/csv_reader_random_access.v index e26502ab968271..97f953b9618cbd 100644 --- a/vlib/encoding/csv/csv_reader_random_access.v +++ b/vlib/encoding/csv/csv_reader_random_access.v @@ -421,7 +421,7 @@ pub fn (mut cr RandomAccessReader) get_cell(cfg GetCellConfig) !string { return cr.default_cell } -type CellValue = f32 | int | string +pub type CellValue = f32 | int | string // get_cellt read a single cell and return a sum type CellValue pub fn (mut cr RandomAccessReader) get_cellt(cfg GetCellConfig) !CellValue { From 99f1cdf9b4305c62072f34adbc5522552983b73f Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 22 Jan 2025 07:31:34 -0300 Subject: [PATCH 11/15] simplify --- vlib/v/checker/checker.v | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index adaafc840585f7..49fab657e6b567 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -5294,8 +5294,7 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool { } sym := c.table.sym(typ) if !c.is_builtin_mod && sym.kind in [.struct, .alias, .sum_type, .function]! && !sym.is_pub - && sym.mod != c.mod && sym.mod != 'main' && c.comptime.comptime_for_field_var == '' - && !c.inside_recheck { + && sym.mod != c.mod && sym.mod != 'main' { if sym.kind == .function { fn_info := sym.info as ast.FnType // hack: recover fn mod from func name From 2232a10f7cdc4fd064eb13da3d312b0e9837f3eb Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 22 Jan 2025 07:43:40 -0300 Subject: [PATCH 12/15] add test --- .../checker/tests/modules/private_symbol.out | 21 +++++++++++++++++++ .../tests/modules/private_symbol/main.v | 19 +++++++++++++++++ .../tests/modules/private_symbol/priv_sym.v | 12 +++++++++++ .../templating/dtm/dynamic_template_manager.v | 2 +- 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 vlib/v/checker/tests/modules/private_symbol.out create mode 100644 vlib/v/checker/tests/modules/private_symbol/main.v create mode 100644 vlib/v/checker/tests/modules/private_symbol/priv_sym.v diff --git a/vlib/v/checker/tests/modules/private_symbol.out b/vlib/v/checker/tests/modules/private_symbol.out new file mode 100644 index 00000000000000..04fc3ea3321509 --- /dev/null +++ b/vlib/v/checker/tests/modules/private_symbol.out @@ -0,0 +1,21 @@ +vlib/v/checker/tests/modules/private_symbol/main.v:10:11: error: function `priv_sym.priv` is private + 8 | + 9 | fn main() { + 10 | priv_sym.priv() + | ~~~~~~ + 11 | a := priv_sym.Foo(0) + 12 | dump(a) +vlib/v/checker/tests/modules/private_symbol/main.v:11:16: error: alias `priv_sym.Foo` was declared as private to module `priv_sym`, so it can not be used inside module `main` + 9 | fn main() { + 10 | priv_sym.priv() + 11 | a := priv_sym.Foo(0) + | ~~~~~~ + 12 | dump(a) + 13 | b := priv_sym.BarFn(t) +vlib/v/checker/tests/modules/private_symbol/main.v:13:16: error: function type `priv_sym.BarFn` was declared as private to module `priv_sym`, so it can not be used inside module `main` + 11 | a := priv_sym.Foo(0) + 12 | dump(a) + 13 | b := priv_sym.BarFn(t) + | ~~~~~~~~ + 14 | dump(b) + 15 | c := priv_sym.PubFoo(0) diff --git a/vlib/v/checker/tests/modules/private_symbol/main.v b/vlib/v/checker/tests/modules/private_symbol/main.v new file mode 100644 index 00000000000000..f7084928bdcedc --- /dev/null +++ b/vlib/v/checker/tests/modules/private_symbol/main.v @@ -0,0 +1,19 @@ +module main + +import priv_sym + +fn t() int { + return 0 +} + +fn main() { + priv_sym.priv() + a := priv_sym.Foo(0) + dump(a) + b := priv_sym.BarFn(t) + dump(b) + c := priv_sym.PubFoo(0) + dump(c) + d := priv_sym.PubBarFn(t) + dump(d) +} diff --git a/vlib/v/checker/tests/modules/private_symbol/priv_sym.v b/vlib/v/checker/tests/modules/private_symbol/priv_sym.v new file mode 100644 index 00000000000000..064190589ad13f --- /dev/null +++ b/vlib/v/checker/tests/modules/private_symbol/priv_sym.v @@ -0,0 +1,12 @@ +// sub module +module priv_sym + +type Foo = int +pub type PubFoo = int + +type BarFn = fn () int + +pub type PubBarFn = fn () int + +fn priv() { +} diff --git a/vlib/x/templating/dtm/dynamic_template_manager.v b/vlib/x/templating/dtm/dynamic_template_manager.v index 891e8f3371404b..01053bb7feb731 100644 --- a/vlib/x/templating/dtm/dynamic_template_manager.v +++ b/vlib/x/templating/dtm/dynamic_template_manager.v @@ -7,7 +7,7 @@ import time import regex // These are all the types of dynamic values that the DTM allows to be returned in the context of a map -type DtmMultiTypeMap = f32 | f64 | i16 | i64 | i8 | int | string | u16 | u32 | u64 | u8 +pub type DtmMultiTypeMap = f32 | f64 | i16 | i64 | i8 | int | string | u16 | u32 | u64 | u8 // type MiddlewareFn = fn (mut Context, string) bool From 55e5c729b2dfcbe14f9589b656bba60315c56a0d Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 22 Jan 2025 12:25:17 -0300 Subject: [PATCH 13/15] fix - check all symbols --- vlib/v/ast/table.v | 1 + vlib/v/ast/types.v | 73 ++++++++++++------- vlib/v/checker/checker.v | 14 ++-- .../checker/tests/modules/private_symbol.out | 6 +- .../tests/modules/private_symbol/priv_sym.v | 4 +- 5 files changed, 62 insertions(+), 36 deletions(-) diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 3ff7417c5169ea..2a62889d71cd05 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -1337,6 +1337,7 @@ pub fn (mut t Table) add_placeholder_type(name string, language Language) int { cname: util.no_dots(name).replace_each(['&', '']) language: language mod: modname + is_pub: true is_builtin: name in builtins } return t.register_sym(ph_type) diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index d9df49b3adccd6..939467385996ba 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -1051,32 +1051,53 @@ pub fn (mut t Table) register_builtin_type_symbols() { // save index check, 0 will mean not found // THE ORDER MUST BE THE SAME AS xxx_type_idx CONSTS EARLIER IN THIS FILE t.register_sym(kind: .placeholder, name: 'reserved_0') - t.register_sym(kind: .void, name: 'void', cname: 'void', mod: 'builtin') // 1 - t.register_sym(kind: .voidptr, name: 'voidptr', cname: 'voidptr', mod: 'builtin') // 2 - t.register_sym(kind: .byteptr, name: 'byteptr', cname: 'byteptr', mod: 'builtin') // 3 - t.register_sym(kind: .charptr, name: 'charptr', cname: 'charptr', mod: 'builtin') // 4 - t.register_sym(kind: .i8, name: 'i8', cname: 'i8', mod: 'builtin') // 5 - t.register_sym(kind: .i16, name: 'i16', cname: 'i16', mod: 'builtin') // 6 - t.register_sym(kind: .i32, name: 'i32', cname: 'i32', mod: 'builtin') // 7 - t.register_sym(kind: .int, name: 'int', cname: int_type_name, mod: 'builtin') // 8 - t.register_sym(kind: .i64, name: 'i64', cname: 'i64', mod: 'builtin') // 9 - t.register_sym(kind: .isize, name: 'isize', cname: 'isize', mod: 'builtin') // 10 - t.register_sym(kind: .u8, name: 'u8', cname: 'u8', mod: 'builtin') // 11 - t.register_sym(kind: .u16, name: 'u16', cname: 'u16', mod: 'builtin') // 12 - t.register_sym(kind: .u32, name: 'u32', cname: 'u32', mod: 'builtin') // 13 - t.register_sym(kind: .u64, name: 'u64', cname: 'u64', mod: 'builtin') // 14 - t.register_sym(kind: .usize, name: 'usize', cname: 'usize', mod: 'builtin') // 15 - t.register_sym(kind: .f32, name: 'f32', cname: 'f32', mod: 'builtin') // 16 - t.register_sym(kind: .f64, name: 'f64', cname: 'f64', mod: 'builtin') // 17 - t.register_sym(kind: .char, name: 'char', cname: 'char', mod: 'builtin') // 18 - t.register_sym(kind: .bool, name: 'bool', cname: 'bool', mod: 'builtin') // 19 - t.register_sym(kind: .none, name: 'none', cname: 'none', mod: 'builtin') // 20 - t.register_sym(kind: .string, name: 'string', cname: 'string', mod: 'builtin', is_builtin: true) // 21 - t.register_sym(kind: .rune, name: 'rune', cname: 'rune', mod: 'builtin') // 22 - t.register_sym(kind: .array, name: 'array', cname: 'array', mod: 'builtin', is_builtin: true) // 23 - t.register_sym(kind: .map, name: 'map', cname: 'map', mod: 'builtin', is_builtin: true) // 24 - t.register_sym(kind: .chan, name: 'chan', cname: 'chan', mod: 'builtin') // 25 - t.register_sym(kind: .any, name: 'any', cname: 'any', mod: 'builtin') // 26 + t.register_sym(kind: .void, name: 'void', cname: 'void', mod: 'builtin', is_pub: true) // 1 + t.register_sym(kind: .voidptr, name: 'voidptr', cname: 'voidptr', mod: 'builtin', is_pub: true) // 2 + t.register_sym(kind: .byteptr, name: 'byteptr', cname: 'byteptr', mod: 'builtin', is_pub: true) // 3 + t.register_sym(kind: .charptr, name: 'charptr', cname: 'charptr', mod: 'builtin', is_pub: true) // 4 + t.register_sym(kind: .i8, name: 'i8', cname: 'i8', mod: 'builtin', is_pub: true) // 5 + t.register_sym(kind: .i16, name: 'i16', cname: 'i16', mod: 'builtin', is_pub: true) // 6 + t.register_sym(kind: .i32, name: 'i32', cname: 'i32', mod: 'builtin', is_pub: true) // 7 + t.register_sym(kind: .int, name: 'int', cname: int_type_name, mod: 'builtin', is_pub: true) // 8 + t.register_sym(kind: .i64, name: 'i64', cname: 'i64', mod: 'builtin', is_pub: true) // 9 + t.register_sym(kind: .isize, name: 'isize', cname: 'isize', mod: 'builtin', is_pub: true) // 10 + t.register_sym(kind: .u8, name: 'u8', cname: 'u8', mod: 'builtin', is_pub: true) // 11 + t.register_sym(kind: .u16, name: 'u16', cname: 'u16', mod: 'builtin', is_pub: true) // 12 + t.register_sym(kind: .u32, name: 'u32', cname: 'u32', mod: 'builtin', is_pub: true) // 13 + t.register_sym(kind: .u64, name: 'u64', cname: 'u64', mod: 'builtin', is_pub: true) // 14 + t.register_sym(kind: .usize, name: 'usize', cname: 'usize', mod: 'builtin', is_pub: true) // 15 + t.register_sym(kind: .f32, name: 'f32', cname: 'f32', mod: 'builtin', is_pub: true) // 16 + t.register_sym(kind: .f64, name: 'f64', cname: 'f64', mod: 'builtin', is_pub: true) // 17 + t.register_sym(kind: .char, name: 'char', cname: 'char', mod: 'builtin', is_pub: true) // 18 + t.register_sym(kind: .bool, name: 'bool', cname: 'bool', mod: 'builtin', is_pub: true) // 19 + t.register_sym(kind: .none, name: 'none', cname: 'none', mod: 'builtin', is_pub: true) // 20 + t.register_sym( + kind: .string + name: 'string' + cname: 'string' + mod: 'builtin' + is_builtin: true + is_pub: true + ) // 21 + t.register_sym(kind: .rune, name: 'rune', cname: 'rune', mod: 'builtin', is_pub: true) // 22 + t.register_sym( + kind: .array + name: 'array' + cname: 'array' + mod: 'builtin' + is_builtin: true + is_pub: true + ) // 23 + t.register_sym( + kind: .map + name: 'map' + cname: 'map' + mod: 'builtin' + is_builtin: true + is_pub: true + ) // 24 + t.register_sym(kind: .chan, name: 'chan', cname: 'chan', mod: 'builtin', is_pub: true) // 25 + t.register_sym(kind: .any, name: 'any', cname: 'any', mod: 'builtin', is_pub: true) // 26 t.register_sym( kind: .float_literal name: 'float literal' diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 49fab657e6b567..7bb67c003aae62 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -5293,21 +5293,23 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool { return false } sym := c.table.sym(typ) - if !c.is_builtin_mod && sym.kind in [.struct, .alias, .sum_type, .function]! && !sym.is_pub - && sym.mod != c.mod && sym.mod != 'main' { + if !c.is_builtin_mod && !sym.is_pub && sym.mod != c.mod && sym.mod != 'main' { if sym.kind == .function { fn_info := sym.info as ast.FnType // hack: recover fn mod from func name - mut fn_mod := fn_info.func.name.all_before_last('.') - if fn_mod == fn_info.func.name { - fn_mod = 'builtin' + mut fn_mod := sym.mod + if fn_mod == '' { + fn_mod = fn_info.func.name.all_before_last('.') + if fn_mod == fn_info.func.name { + fn_mod = 'builtin' + } } if fn_mod != '' && fn_mod != c.mod && fn_info.func.name != '' && !fn_info.is_anon { c.error('function type `${fn_info.func.name}` was declared as private to module `${fn_mod}`, so it can not be used inside module `${c.mod}`', pos) return false } - } else { + } else if sym.mod != '' { c.error('${sym.kind} `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`', pos) return false diff --git a/vlib/v/checker/tests/modules/private_symbol.out b/vlib/v/checker/tests/modules/private_symbol.out index 04fc3ea3321509..9fa9da02216143 100644 --- a/vlib/v/checker/tests/modules/private_symbol.out +++ b/vlib/v/checker/tests/modules/private_symbol.out @@ -5,14 +5,16 @@ vlib/v/checker/tests/modules/private_symbol/main.v:10:11: error: function `priv_ | ~~~~~~ 11 | a := priv_sym.Foo(0) 12 | dump(a) -vlib/v/checker/tests/modules/private_symbol/main.v:11:16: error: alias `priv_sym.Foo` was declared as private to module `priv_sym`, so it can not be used inside module `main` +vlib/v/checker/tests/modules/private_symbol/main.v:11:16: error: unknown type `priv_sym.Foo`. +Did you mean `priv_sym.PubFoo`? 9 | fn main() { 10 | priv_sym.priv() 11 | a := priv_sym.Foo(0) | ~~~~~~ 12 | dump(a) 13 | b := priv_sym.BarFn(t) -vlib/v/checker/tests/modules/private_symbol/main.v:13:16: error: function type `priv_sym.BarFn` was declared as private to module `priv_sym`, so it can not be used inside module `main` +vlib/v/checker/tests/modules/private_symbol/main.v:13:16: error: unknown type `priv_sym.BarFn`. +Did you mean `priv_sym.PubFoo`? 11 | a := priv_sym.Foo(0) 12 | dump(a) 13 | b := priv_sym.BarFn(t) diff --git a/vlib/v/checker/tests/modules/private_symbol/priv_sym.v b/vlib/v/checker/tests/modules/private_symbol/priv_sym.v index 064190589ad13f..718b89c41e27fc 100644 --- a/vlib/v/checker/tests/modules/private_symbol/priv_sym.v +++ b/vlib/v/checker/tests/modules/private_symbol/priv_sym.v @@ -1,10 +1,10 @@ // sub module module priv_sym -type Foo = int +type PrivFoo = int pub type PubFoo = int -type BarFn = fn () int +type PrivBarFn = fn () int pub type PubBarFn = fn () int From c35fb1bcce6f0f2299fbccd344e8a79327691c94 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 22 Jan 2025 12:30:40 -0300 Subject: [PATCH 14/15] fix --- vlib/v/ast/types.v | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index 939467385996ba..9aa557f38db7a6 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -1099,25 +1099,28 @@ pub fn (mut t Table) register_builtin_type_symbols() { t.register_sym(kind: .chan, name: 'chan', cname: 'chan', mod: 'builtin', is_pub: true) // 25 t.register_sym(kind: .any, name: 'any', cname: 'any', mod: 'builtin', is_pub: true) // 26 t.register_sym( - kind: .float_literal - name: 'float literal' - cname: 'float_literal' - mod: 'builtin' + kind: .float_literal + name: 'float literal' + cname: 'float_literal' + mod: 'builtin' + is_pub: true ) // 27 t.register_sym( - kind: .int_literal - name: 'int literal' - cname: 'int_literal' - mod: 'builtin' + kind: .int_literal + name: 'int literal' + cname: 'int_literal' + mod: 'builtin' + is_pub: true ) // 28 t.register_sym( - kind: .thread - name: 'thread' - cname: '__v_thread' - mod: 'builtin' - info: Thread{ + kind: .thread + name: 'thread' + cname: '__v_thread' + mod: 'builtin' + info: Thread{ return_type: void_type } + is_pub: true ) // 29 t.register_sym( kind: .interface @@ -1125,6 +1128,7 @@ pub fn (mut t Table) register_builtin_type_symbols() { cname: 'IError' mod: 'builtin' is_builtin: true + is_pub: true ) // 30 t.register_sym(kind: .voidptr, name: 'nil', cname: 'voidptr', mod: 'builtin') // 31 } From 319b4b55e5e0fa958e2d861adbb2cc134de6bb14 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Wed, 22 Jan 2025 12:31:00 -0300 Subject: [PATCH 15/15] fix --- vlib/v/ast/types.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index 9aa557f38db7a6..52afd493c795cc 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -1130,7 +1130,7 @@ pub fn (mut t Table) register_builtin_type_symbols() { is_builtin: true is_pub: true ) // 30 - t.register_sym(kind: .voidptr, name: 'nil', cname: 'voidptr', mod: 'builtin') // 31 + t.register_sym(kind: .voidptr, name: 'nil', cname: 'voidptr', mod: 'builtin', is_pub: true) // 31 } @[inline]