Skip to content

Commit eeeef41

Browse files
authored
markused: fix x := t.wait(), when t := go fn () string { (fix #24577) (#24580)
1 parent 27d318e commit eeeef41

6 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎vlib/v/ast/table.v‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub mut:
3232
map_update bool // {...foo}
3333
interpolation bool // '${foo} ${bar}'
3434
option_or_result bool // has panic call
35+
waiter bool // has thread waiter
3536
print_types map[int]bool // print() idx types
3637
used_fns map[string]bool // filled in by markused
3738
used_consts map[string]bool // filled in by markused

‎vlib/v/checker/fn.v‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,6 +2726,9 @@ fn (mut c Checker) spawn_expr(mut node ast.SpawnExpr) ast.Type {
27262726
c.error('option handling cannot be done in `spawn` call. Do it when calling `.wait()`',
27272727
node.call_expr.or_block.pos)
27282728
}
2729+
if node.is_expr {
2730+
c.table.used_features.waiter = true
2731+
}
27292732
// Make sure there are no mutable arguments
27302733
for arg in node.call_expr.args {
27312734
if arg.is_mut && !arg.typ.is_ptr() {
@@ -2761,6 +2764,9 @@ fn (mut c Checker) go_expr(mut node ast.GoExpr) ast.Type {
27612764
c.error('option handling cannot be done in `go` call. Do it when calling `.wait()`',
27622765
node.call_expr.or_block.pos)
27632766
}
2767+
if node.is_expr {
2768+
c.table.used_features.waiter = true
2769+
}
27642770
// Make sure there are no mutable arguments
27652771
for arg in node.call_expr.args {
27662772
if arg.is_mut && !arg.typ.is_ptr() {

‎vlib/v/markused/markused.v‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
168168
builderptr_idx + '.write_rune',
169169
]
170170
}
171+
if table.used_features.waiter {
172+
core_fns << 'free'
173+
}
171174
if !table.used_features.arr_init {
172175
table.used_features.arr_init = table.used_features.print_types.keys().any(table.type_to_str(it).contains('[]'))
173176
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
string
2+
hi
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
string
2+
hi
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module main
2+
3+
fn main() {
4+
t := go fn () string {
5+
return 'hi'
6+
}()
7+
x := t.wait()
8+
println(typeof(x).name)
9+
println(x)
10+
}

0 commit comments

Comments
 (0)