markused: fix option ptr printing (fix #23559) (#23562)

This commit is contained in:
Felipe Pena 2025-01-23 15:37:13 -03:00 committed by GitHub
parent 25f14d3bbb
commit da5bb68b61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 16 additions and 2 deletions

View File

@ -759,7 +759,7 @@ fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type {
c.markused_option_or_result(!c.is_builtin_mod && c.mod != 'strings')
}
c.expected_or_type = old_expected_or_type
c.markused_call_expr(mut node)
c.markused_call_expr(left_type, mut node)
if !c.inside_const && c.table.cur_fn != unsafe { nil } && !c.table.cur_fn.is_main
&& !c.table.cur_fn.is_test {
// TODO: use just `if node.or_block.kind == .propagate_result && !c.table.cur_fn.return_type.has_flag(.result) {` after the deprecation for ?!Type

View File

@ -111,7 +111,7 @@ fn (mut c Checker) markused_comptimefor(mut node ast.ComptimeFor, unwrapped_expr
}
}
fn (mut c Checker) markused_call_expr(mut node ast.CallExpr) {
fn (mut c Checker) markused_call_expr(left_type ast.Type, mut node ast.CallExpr) {
if !c.is_builtin_mod && c.mod == 'main' && !c.table.used_features.external_types {
if node.is_method {
if c.table.sym(node.left_type).is_builtin() {
@ -121,6 +121,10 @@ fn (mut c Checker) markused_call_expr(mut node ast.CallExpr) {
c.table.used_features.external_types = true
}
}
if left_type != 0 && left_type.is_ptr() && !c.table.used_features.auto_str_ptr
&& node.name == 'str' {
c.table.used_features.auto_str_ptr = true
}
}
fn (mut c Checker) markused_fn_call(mut node ast.CallExpr) {

View File

@ -0,0 +1 @@
[vlib/v/tests/skip_unused/option_ptr_print.vv:7] hrefs.str(): &<div class="Truncate" >abc</div>

View File

@ -0,0 +1 @@
[vlib/v/tests/skip_unused/option_ptr_print.vv:7] hrefs.str(): &<div class="Truncate" >abc</div>

View File

@ -0,0 +1,8 @@
import net.html
fn main() {
mut doc := html.parse('<body><div class="Box-footer"><div class="Truncate">abc</div></div></body>')
footer := doc.get_tags_by_class_name('Box-footer')[0]
hrefs := footer.get_tag_by_class_name('Truncate')
dump(hrefs?.str())
}