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) it.expr_type = c.expr(it.expr)
return table.string_type return table.string_type
} }
else {} else {
// println('checker.expr(): unhandled node') tnode := typeof(node)
// TODO: find nil string bug triggered with typeof if tnode != 'unknown v.ast.Expr' {
// println('checker.expr(): unhandled node (${typeof(node)})') println('checker.expr(): unhandled node with typeof(`${tnode}`)')
}
}
} }
return table.void_type 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' name: 'err'
typ: table.string_type typ: table.string_type
}) })
p.scope.register('errcode', ast.Var{
name: 'errcode'
typ: table.int_type
})
or_stmts = p.parse_block_no_scope() or_stmts = p.parse_block_no_scope()
p.close_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 { if p.tok.kind == .key_orelse {
p.next() p.next()
p.open_scope() p.open_scope()
p.scope.register('errcode', ast.Var{
name: 'errcode'
typ: table.int_type
})
p.scope.register('err', ast.Var{ p.scope.register('err', ast.Var{
name: 'err' name: 'err'
typ: table.string_type typ: table.string_type