json.decode: fix expressions in the second argument, also fixes news_fetcher.v

pull/4755/head
Delyan Angelov 2020-05-06 21:44:46 +03:00
parent b5a1544bf8
commit e33805b2b3
3 changed files with 5 additions and 3 deletions

View File

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

View File

@ -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) c.error('json.decode: first argument needs to be a type, got `$typ`', call_expr.pos)
return table.void_type 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 typ := expr as ast.Type
return typ.typ.set_flag(.optional) return typ.typ.set_flag(.optional)
} }

View File

@ -1270,7 +1270,7 @@ fn (mut g Gen) expr(node ast.Expr) {
g.write('.') g.write('.')
} }
if it.expr_type == 0 { 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)) g.write(c_name(it.field))
} }