Skip to content

Commit

Permalink
markused: fix option ptr printing (fix vlang#23559) (vlang#23562)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Jan 23, 2025
1 parent 25f14d3 commit da5bb68
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion vlib/v/checker/used_features.v
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions vlib/v/tests/skip_unused/option_ptr_print.run.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[vlib/v/tests/skip_unused/option_ptr_print.vv:7] hrefs.str(): &<div class="Truncate" >abc</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[vlib/v/tests/skip_unused/option_ptr_print.vv:7] hrefs.str(): &<div class="Truncate" >abc</div>
8 changes: 8 additions & 0 deletions vlib/v/tests/skip_unused/option_ptr_print.vv
Original file line number Diff line number Diff line change
@@ -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())
}

0 comments on commit da5bb68

Please sign in to comment.