Skip to content

Commit da5bb68

Browse files
authored
markused: fix option ptr printing (fix #23559) (#23562)
1 parent 25f14d3 commit da5bb68

5 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎vlib/v/checker/fn.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type {
759759
c.markused_option_or_result(!c.is_builtin_mod && c.mod != 'strings')
760760
}
761761
c.expected_or_type = old_expected_or_type
762-
c.markused_call_expr(mut node)
762+
c.markused_call_expr(left_type, mut node)
763763
if !c.inside_const && c.table.cur_fn != unsafe { nil } && !c.table.cur_fn.is_main
764764
&& !c.table.cur_fn.is_test {
765765
// TODO: use just `if node.or_block.kind == .propagate_result && !c.table.cur_fn.return_type.has_flag(.result) {` after the deprecation for ?!Type

‎vlib/v/checker/used_features.v‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn (mut c Checker) markused_comptimefor(mut node ast.ComptimeFor, unwrapped_expr
111111
}
112112
}
113113

114-
fn (mut c Checker) markused_call_expr(mut node ast.CallExpr) {
114+
fn (mut c Checker) markused_call_expr(left_type ast.Type, mut node ast.CallExpr) {
115115
if !c.is_builtin_mod && c.mod == 'main' && !c.table.used_features.external_types {
116116
if node.is_method {
117117
if c.table.sym(node.left_type).is_builtin() {
@@ -121,6 +121,10 @@ fn (mut c Checker) markused_call_expr(mut node ast.CallExpr) {
121121
c.table.used_features.external_types = true
122122
}
123123
}
124+
if left_type != 0 && left_type.is_ptr() && !c.table.used_features.auto_str_ptr
125+
&& node.name == 'str' {
126+
c.table.used_features.auto_str_ptr = true
127+
}
124128
}
125129

126130
fn (mut c Checker) markused_fn_call(mut node ast.CallExpr) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[vlib/v/tests/skip_unused/option_ptr_print.vv:7] hrefs.str(): &<div class="Truncate" >abc</div>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[vlib/v/tests/skip_unused/option_ptr_print.vv:7] hrefs.str(): &<div class="Truncate" >abc</div>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import net.html
2+
3+
fn main() {
4+
mut doc := html.parse('<body><div class="Box-footer"><div class="Truncate">abc</div></div></body>')
5+
footer := doc.get_tags_by_class_name('Box-footer')[0]
6+
hrefs := footer.get_tag_by_class_name('Truncate')
7+
dump(hrefs?.str())
8+
}

0 commit comments

Comments
 (0)