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:
parent
336e82d162
commit
85c05b6822
@ -29,6 +29,9 @@ fn (p mut Parser) gen_var_decl(name string, is_static bool) string {
|
|||||||
// p.assigned_var = ''
|
// p.assigned_var = ''
|
||||||
p.cgen.set_placeholder(pos, '$typ $tmp = ')
|
p.cgen.set_placeholder(pos, '$typ $tmp = ')
|
||||||
p.genln(';')
|
p.genln(';')
|
||||||
|
if !typ.starts_with('Option_') {
|
||||||
|
p.error('`or` block cannot be applied to non-optional type')
|
||||||
|
}
|
||||||
typ = typ.replace('Option_', '')
|
typ = typ.replace('Option_', '')
|
||||||
p.next()
|
p.next()
|
||||||
p.check(.lcbr)
|
p.check(.lcbr)
|
||||||
|
@ -31,8 +31,12 @@ fn test_option_for_base_type_without_variable() {
|
|||||||
println('yep')
|
println('yep')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
println('nice')
|
println('$val2 should have been `none`')
|
||||||
println(val2)
|
assert false
|
||||||
|
// This is invalid:
|
||||||
|
// x := 5 or {
|
||||||
|
// return
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_if_opt() {
|
fn test_if_opt() {
|
||||||
|
Loading…
Reference in New Issue
Block a user