diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 4371f689a9cace..64f8c93c98d633 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -39,7 +39,7 @@ pub mut: used_veb_types []Type // veb context types, filled in by checker used_maps int // how many times maps were used, filled in by markused used_arrays int // how many times arrays were used, filled in by markused - used_modules map[string]bool // filled in checker + external_types bool // true, when external type is used // json bool // json is imported debugger bool // debugger is used comptime_calls map[string]bool // resolved name to call on comptime diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 49ad605eacdf6e..b9ec682476a7e2 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -4004,7 +4004,7 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type { node.pos) } if c.pref.skip_unused && !c.is_builtin_mod && node.language == .v && node.name.contains('.') { - c.table.used_features.used_modules[node.name.all_before('.')] = true + c.table.used_features.external_types = true } if mut obj := node.scope.find(node.name) { match mut obj { diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 12cd03cd5e2fc2..16491e737c89eb 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -761,15 +761,14 @@ fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type { } } c.expected_or_type = old_expected_or_type - if c.pref.skip_unused && !c.is_builtin_mod && c.mod == 'main' { + if c.pref.skip_unused && !c.is_builtin_mod && c.mod == 'main' + && !c.table.used_features.external_types { if node.is_method { - type_str := c.table.type_to_str(node.left_type) - if c.table.sym(node.left_type).is_builtin() - && type_str !in c.table.used_features.used_modules { - c.table.used_features.used_modules[type_str] = true + if c.table.sym(node.left_type).is_builtin() { + c.table.used_features.external_types = true } } else if node.name.contains('.') { - c.table.used_features.used_modules[node.name.all_before('.')] = true + c.table.used_features.external_types = true } } diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index 7028a6f516fa91..c6a52b575b5a4c 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -443,6 +443,10 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini node.typ = c.expected_type } } + if c.pref.skip_unused && !c.is_builtin_mod && !c.table.used_features.external_types { + type_str := c.table.type_to_str(node.typ) + c.table.used_features.external_types = type_str.contains('.') && type_str.len > 1 + } struct_sym := c.table.sym(node.typ) mut old_inside_generic_struct_init := false mut old_cur_struct_generic_types := []ast.Type{} diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 94c38ba25fbb9c..27ac7ec3ee12cd 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -6169,7 +6169,7 @@ fn (mut g Gen) write_init_function() { g.write('\tas_cast_type_indexes = ') g.writeln(g.as_cast_name_table()) } - if !g.pref.is_shared && (!g.pref.skip_unused || g.table.used_features.used_modules.len > 0) { + if !g.pref.is_shared && (!g.pref.skip_unused || g.table.used_features.external_types) { // shared object does not need this g.writeln('\tbuiltin_init();') } diff --git a/vlib/v/markused/markused.v b/vlib/v/markused/markused.v index 515b41016ea922..779a997ede29c7 100644 --- a/vlib/v/markused/markused.v +++ b/vlib/v/markused/markused.v @@ -81,7 +81,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a core_fns << ref_array_idx_str + '.push' core_fns << ref_array_idx_str + '.pop' } - if table.used_features.used_modules.len > 0 { + if table.used_features.external_types { include_panic_deps = true } if pref_.autofree { @@ -289,7 +289,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a if table.used_features.auto_str || table.used_features.dump || table.used_features.print_types[mfn.receiver.typ.idx()] || table.used_features.asserts || table.used_features.debugger - || table.used_features.used_modules.len > 0 { + || table.used_features.external_types { all_fn_root_names << k } continue @@ -298,7 +298,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a all_fn_root_names << k continue } - if (pref_.autofree || table.used_features.used_modules.len > 0) && k.ends_with('.free') { + if (pref_.autofree || table.used_features.external_types) && k.ends_with('.free') { all_fn_root_names << k continue } diff --git a/vlib/v/tests/skip_unused/ierror_str.run.out b/vlib/v/tests/skip_unused/ierror_str.run.out new file mode 100644 index 00000000000000..88e9183d761a0c --- /dev/null +++ b/vlib/v/tests/skip_unused/ierror_str.run.out @@ -0,0 +1 @@ +No such file or directory; code: 2 diff --git a/vlib/v/tests/skip_unused/ierror_str.skip_unused.run.out b/vlib/v/tests/skip_unused/ierror_str.skip_unused.run.out new file mode 100644 index 00000000000000..88e9183d761a0c --- /dev/null +++ b/vlib/v/tests/skip_unused/ierror_str.skip_unused.run.out @@ -0,0 +1 @@ +No such file or directory; code: 2 diff --git a/vlib/v/tests/skip_unused/ierror_str.vv b/vlib/v/tests/skip_unused/ierror_str.vv new file mode 100644 index 00000000000000..38a3f03f42f7d0 --- /dev/null +++ b/vlib/v/tests/skip_unused/ierror_str.vv @@ -0,0 +1,6 @@ +import os + +fn main() { + mut proc := os.Process{} + proc.run() +}