1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

add support for errcode in or{} optional blocks.

This commit is contained in:
Delyan Angelov 2020-04-04 21:47:57 +03:00
parent abd0686043
commit b0567543c9
3 changed files with 14 additions and 4 deletions

View File

@ -834,10 +834,12 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
it.expr_type = c.expr(it.expr)
return table.string_type
}
else {}
// println('checker.expr(): unhandled node')
// TODO: find nil string bug triggered with typeof
// println('checker.expr(): unhandled node (${typeof(node)})')
else {
tnode := typeof(node)
if tnode != 'unknown v.ast.Expr' {
println('checker.expr(): unhandled node with typeof(`${tnode}`)')
}
}
}
return table.void_type
}

View File

@ -23,6 +23,10 @@ pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr {
name: 'err'
typ: table.string_type
})
p.scope.register('errcode', ast.Var{
name: 'errcode'
typ: table.int_type
})
or_stmts = p.parse_block_no_scope()
p.close_scope()
}

View File

@ -965,6 +965,10 @@ fn (p mut Parser) dot_expr(left ast.Expr) ast.Expr {
if p.tok.kind == .key_orelse {
p.next()
p.open_scope()
p.scope.register('errcode', ast.Var{
name: 'errcode'
typ: table.int_type
})
p.scope.register('err', ast.Var{
name: 'err'
typ: table.string_type