mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
parent
1e5c812540
commit
2a3dc5c068
3 changed files with 34 additions and 0 deletions
|
@ -361,6 +361,11 @@ fn (mut p Parser) comptime_for() ast.ComptimeFor {
|
|||
mut typ_pos := p.tok.pos()
|
||||
lang := p.parse_language()
|
||||
mut typ := ast.void_type
|
||||
|
||||
if p.tok.lit.len == 0 {
|
||||
p.error('invalid expr, use `${p.peek_tok.lit}` instead')
|
||||
return ast.ComptimeFor{}
|
||||
}
|
||||
if p.tok.lit[0].is_capital() || p.tok.lit in p.imports {
|
||||
typ = p.parse_any_type(lang, false, true, false)
|
||||
} else {
|
||||
|
|
7
vlib/v/parser/tests/comptime_for_invalid_expr_err.out
Normal file
7
vlib/v/parser/tests/comptime_for_invalid_expr_err.out
Normal file
|
@ -0,0 +1,7 @@
|
|||
vlib/v/parser/tests/comptime_for_invalid_expr_err.vv:19:12: error: invalid expr, use `MyStruct` instead
|
||||
17 | }
|
||||
18 |
|
||||
19 | $for f in $MyStruct.fields {
|
||||
| ^
|
||||
20 | assert a.${f.field_name} == b.${f.field_name}
|
||||
21 | }
|
22
vlib/v/parser/tests/comptime_for_invalid_expr_err.vv
Normal file
22
vlib/v/parser/tests/comptime_for_invalid_expr_err.vv
Normal file
|
@ -0,0 +1,22 @@
|
|||
module main
|
||||
|
||||
struct MyStruct {
|
||||
f_u8 u8
|
||||
f_u16 u16
|
||||
}
|
||||
|
||||
fn main() {
|
||||
a := MyStruct {
|
||||
f_u8 : u8(12)
|
||||
f_u16 : u16(32)
|
||||
}
|
||||
|
||||
b := MyStruct {
|
||||
f_u8 : u8(12)
|
||||
f_u16 : u16(32)
|
||||
}
|
||||
|
||||
$for f in $MyStruct.fields {
|
||||
assert a.${f.field_name} == b.${f.field_name}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue