Skip to content

Commit c98295b

Browse files
authored
markused: fix eprintln(err) on imported module on short program (related: #23498) (#23499)
1 parent 3b0cfbf commit c98295b

File tree

9 files changed

+23
-12
lines changed

9 files changed

+23
-12
lines changed

vlib/v/ast/table.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub mut:
3939
used_veb_types []Type // veb context types, filled in by checker
4040
used_maps int // how many times maps were used, filled in by markused
4141
used_arrays int // how many times arrays were used, filled in by markused
42-
used_modules map[string]bool // filled in checker
42+
external_types bool // true, when external type is used
4343
// json bool // json is imported
4444
debugger bool // debugger is used
4545
comptime_calls map[string]bool // resolved name to call on comptime

vlib/v/checker/checker.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4004,7 +4004,7 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
40044004
node.pos)
40054005
}
40064006
if c.pref.skip_unused && !c.is_builtin_mod && node.language == .v && node.name.contains('.') {
4007-
c.table.used_features.used_modules[node.name.all_before('.')] = true
4007+
c.table.used_features.external_types = true
40084008
}
40094009
if mut obj := node.scope.find(node.name) {
40104010
match mut obj {

vlib/v/checker/fn.v

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -761,15 +761,14 @@ fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type {
761761
}
762762
}
763763
c.expected_or_type = old_expected_or_type
764-
if c.pref.skip_unused && !c.is_builtin_mod && c.mod == 'main' {
764+
if c.pref.skip_unused && !c.is_builtin_mod && c.mod == 'main'
765+
&& !c.table.used_features.external_types {
765766
if node.is_method {
766-
type_str := c.table.type_to_str(node.left_type)
767-
if c.table.sym(node.left_type).is_builtin()
768-
&& type_str !in c.table.used_features.used_modules {
769-
c.table.used_features.used_modules[type_str] = true
767+
if c.table.sym(node.left_type).is_builtin() {
768+
c.table.used_features.external_types = true
770769
}
771770
} else if node.name.contains('.') {
772-
c.table.used_features.used_modules[node.name.all_before('.')] = true
771+
c.table.used_features.external_types = true
773772
}
774773
}
775774

vlib/v/checker/struct.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
443443
node.typ = c.expected_type
444444
}
445445
}
446+
if c.pref.skip_unused && !c.is_builtin_mod && !c.table.used_features.external_types {
447+
type_str := c.table.type_to_str(node.typ)
448+
c.table.used_features.external_types = type_str.contains('.') && type_str.len > 1
449+
}
446450
struct_sym := c.table.sym(node.typ)
447451
mut old_inside_generic_struct_init := false
448452
mut old_cur_struct_generic_types := []ast.Type{}

vlib/v/gen/c/cgen.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6169,7 +6169,7 @@ fn (mut g Gen) write_init_function() {
61696169
g.write('\tas_cast_type_indexes = ')
61706170
g.writeln(g.as_cast_name_table())
61716171
}
6172-
if !g.pref.is_shared && (!g.pref.skip_unused || g.table.used_features.used_modules.len > 0) {
6172+
if !g.pref.is_shared && (!g.pref.skip_unused || g.table.used_features.external_types) {
61736173
// shared object does not need this
61746174
g.writeln('\tbuiltin_init();')
61756175
}

vlib/v/markused/markused.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
8181
core_fns << ref_array_idx_str + '.push'
8282
core_fns << ref_array_idx_str + '.pop'
8383
}
84-
if table.used_features.used_modules.len > 0 {
84+
if table.used_features.external_types {
8585
include_panic_deps = true
8686
}
8787
if pref_.autofree {
@@ -289,7 +289,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
289289
if table.used_features.auto_str || table.used_features.dump
290290
|| table.used_features.print_types[mfn.receiver.typ.idx()]
291291
|| table.used_features.asserts || table.used_features.debugger
292-
|| table.used_features.used_modules.len > 0 {
292+
|| table.used_features.external_types {
293293
all_fn_root_names << k
294294
}
295295
continue
@@ -298,7 +298,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
298298
all_fn_root_names << k
299299
continue
300300
}
301-
if (pref_.autofree || table.used_features.used_modules.len > 0) && k.ends_with('.free') {
301+
if (pref_.autofree || table.used_features.external_types) && k.ends_with('.free') {
302302
all_fn_root_names << k
303303
continue
304304
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No such file or directory; code: 2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No such file or directory; code: 2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import os
2+
3+
fn main() {
4+
mut proc := os.Process{}
5+
proc.run()
6+
}

0 commit comments

Comments
 (0)