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

parser: disallow or{} block for non-optionals

This commit is contained in:
Simon Heuser 2019-10-12 16:53:53 +02:00 committed by Alexander Medvednikov
parent 336e82d162
commit 85c05b6822
2 changed files with 18 additions and 11 deletions

View File

@ -29,6 +29,9 @@ fn (p mut Parser) gen_var_decl(name string, is_static bool) string {
// p.assigned_var = ''
p.cgen.set_placeholder(pos, '$typ $tmp = ')
p.genln(';')
if !typ.starts_with('Option_') {
p.error('`or` block cannot be applied to non-optional type')
}
typ = typ.replace('Option_', '')
p.next()
p.check(.lcbr)

View File

@ -31,8 +31,12 @@ fn test_option_for_base_type_without_variable() {
println('yep')
return
}
println('nice')
println(val2)
println('$val2 should have been `none`')
assert false
// This is invalid:
// x := 5 or {
// return
// }
}
fn test_if_opt() {