markused: fix eprintln(err) on imported module on short program (related: #23498) (#23499)

This commit is contained in:
Felipe Pena 2025-01-17 15:10:59 -03:00 committed by GitHub
parent 3b0cfbfd0f
commit c98295b294
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 23 additions and 12 deletions

View File

@ -39,7 +39,7 @@ pub mut:
used_veb_types []Type // veb context types, filled in by checker 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_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_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 // json bool // json is imported
debugger bool // debugger is used debugger bool // debugger is used
comptime_calls map[string]bool // resolved name to call on comptime comptime_calls map[string]bool // resolved name to call on comptime

View File

@ -4004,7 +4004,7 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
node.pos) node.pos)
} }
if c.pref.skip_unused && !c.is_builtin_mod && node.language == .v && node.name.contains('.') { 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) { if mut obj := node.scope.find(node.name) {
match mut obj { match mut obj {

View File

@ -761,15 +761,14 @@ fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type {
} }
} }
c.expected_or_type = old_expected_or_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 { if node.is_method {
type_str := c.table.type_to_str(node.left_type) if c.table.sym(node.left_type).is_builtin() {
if c.table.sym(node.left_type).is_builtin() c.table.used_features.external_types = true
&& type_str !in c.table.used_features.used_modules {
c.table.used_features.used_modules[type_str] = true
} }
} else if node.name.contains('.') { } else if node.name.contains('.') {
c.table.used_features.used_modules[node.name.all_before('.')] = true c.table.used_features.external_types = true
} }
} }

View File

@ -443,6 +443,10 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
node.typ = c.expected_type 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) struct_sym := c.table.sym(node.typ)
mut old_inside_generic_struct_init := false mut old_inside_generic_struct_init := false
mut old_cur_struct_generic_types := []ast.Type{} mut old_cur_struct_generic_types := []ast.Type{}

View File

@ -6169,7 +6169,7 @@ fn (mut g Gen) write_init_function() {
g.write('\tas_cast_type_indexes = ') g.write('\tas_cast_type_indexes = ')
g.writeln(g.as_cast_name_table()) 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 // shared object does not need this
g.writeln('\tbuiltin_init();') g.writeln('\tbuiltin_init();')
} }

View File

@ -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 + '.push'
core_fns << ref_array_idx_str + '.pop' 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 include_panic_deps = true
} }
if pref_.autofree { 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 if table.used_features.auto_str || table.used_features.dump
|| table.used_features.print_types[mfn.receiver.typ.idx()] || table.used_features.print_types[mfn.receiver.typ.idx()]
|| table.used_features.asserts || table.used_features.debugger || 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 all_fn_root_names << k
} }
continue 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 all_fn_root_names << k
continue 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 all_fn_root_names << k
continue continue
} }

View File

@ -0,0 +1 @@
No such file or directory; code: 2

View File

@ -0,0 +1 @@
No such file or directory; code: 2

View File

@ -0,0 +1,6 @@
import os
fn main() {
mut proc := os.Process{}
proc.run()
}