Skip to content

Commit e33805b

Browse files
committed
json.decode: fix expressions in the second argument, also fixes news_fetcher.v
1 parent b5a1544 commit e33805b

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

examples/news_fetcher.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct Story {
1111
}
1212

1313
fn worker_fetch(p &sync.PoolProcessor, cursor int, worker_id int) voidptr {
14-
id := p.get_item<int>(cursor)
14+
id := p.get_int_item(cursor)
1515
resp := http.get('https://hacker-news.firebaseio.com/v0/item/${id}.json') or {
1616
println('failed to fetch data from /v0/item/${id}.json')
1717
return sync.no_result
@@ -45,5 +45,5 @@ fn main() {
4545
// cases is what you want anyway... You can override the automatic choice
4646
// by setting the VJOBS environment variable too.
4747
// fetcher_pool.set_max_jobs( 4 )
48-
fetcher_pool.work_on_items(ids)
48+
fetcher_pool.work_on_items_i(ids)
4949
}

vlib/v/checker/checker.v

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,8 @@ pub fn (mut c Checker) call_fn(call_expr mut ast.CallExpr) table.Type {
759759
c.error('json.decode: first argument needs to be a type, got `$typ`', call_expr.pos)
760760
return table.void_type
761761
}
762+
c.expected_type = table.string_type
763+
call_expr.args[1].typ = c.expr(call_expr.args[1].expr)
762764
typ := expr as ast.Type
763765
return typ.typ.set_flag(.optional)
764766
}

vlib/v/gen/cgen.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ fn (mut g Gen) expr(node ast.Expr) {
12701270
g.write('.')
12711271
}
12721272
if it.expr_type == 0 {
1273-
verror('cgen: SelectorExpr typ=0 field=$it.field $g.file.path $it.pos.line_nr')
1273+
verror('cgen: SelectorExpr | expr_type: 0 | it.expr: `${it.expr}` | field: `$it.field` | file: $g.file.path | line: $it.pos.line_nr')
12741274
}
12751275
g.write(c_name(it.field))
12761276
}

0 commit comments

Comments
 (0)