From e33805b2b38f821a4ed2316e1c7dec676a74d233 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 6 May 2020 21:44:46 +0300 Subject: [PATCH] json.decode: fix expressions in the second argument, also fixes news_fetcher.v --- examples/news_fetcher.v | 4 ++-- vlib/v/checker/checker.v | 2 ++ vlib/v/gen/cgen.v | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/news_fetcher.v b/examples/news_fetcher.v index 33815552c0..e32abc2b0c 100644 --- a/examples/news_fetcher.v +++ b/examples/news_fetcher.v @@ -11,7 +11,7 @@ struct Story { } fn worker_fetch(p &sync.PoolProcessor, cursor int, worker_id int) voidptr { - id := p.get_item(cursor) + id := p.get_int_item(cursor) resp := http.get('https://hacker-news.firebaseio.com/v0/item/${id}.json') or { println('failed to fetch data from /v0/item/${id}.json') return sync.no_result @@ -45,5 +45,5 @@ fn main() { // cases is what you want anyway... You can override the automatic choice // by setting the VJOBS environment variable too. // fetcher_pool.set_max_jobs( 4 ) - fetcher_pool.work_on_items(ids) + fetcher_pool.work_on_items_i(ids) } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 24d5ac909c..f5519f837a 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -759,6 +759,8 @@ pub fn (mut c Checker) call_fn(call_expr mut ast.CallExpr) table.Type { c.error('json.decode: first argument needs to be a type, got `$typ`', call_expr.pos) return table.void_type } + c.expected_type = table.string_type + call_expr.args[1].typ = c.expr(call_expr.args[1].expr) typ := expr as ast.Type return typ.typ.set_flag(.optional) } diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 0062f9ad00..bccd4ecbfe 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -1270,7 +1270,7 @@ fn (mut g Gen) expr(node ast.Expr) { g.write('.') } if it.expr_type == 0 { - verror('cgen: SelectorExpr typ=0 field=$it.field $g.file.path $it.pos.line_nr') + verror('cgen: SelectorExpr | expr_type: 0 | it.expr: `${it.expr}` | field: `$it.field` | file: $g.file.path | line: $it.pos.line_nr') } g.write(c_name(it.field)) }