mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix panic for parse invalid map type (#14431)
This commit is contained in:
parent
7c6eaa8204
commit
d6aa85d059
@ -113,12 +113,12 @@ pub fn (mut p Parser) parse_map_type() ast.Type {
|
|||||||
}
|
}
|
||||||
p.check(.lsbr)
|
p.check(.lsbr)
|
||||||
key_type := p.parse_type()
|
key_type := p.parse_type()
|
||||||
key_sym := p.table.sym(key_type)
|
|
||||||
is_alias := key_sym.kind == .alias
|
|
||||||
if key_type.idx() == 0 {
|
if key_type.idx() == 0 {
|
||||||
// error is reported in parse_type
|
// error is reported in parse_type
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
key_sym := p.table.sym(key_type)
|
||||||
|
is_alias := key_sym.kind == .alias
|
||||||
key_type_supported := key_type in [ast.string_type_idx, ast.voidptr_type_idx]
|
key_type_supported := key_type in [ast.string_type_idx, ast.voidptr_type_idx]
|
||||||
|| key_sym.kind in [.enum_, .placeholder, .any]
|
|| key_sym.kind in [.enum_, .placeholder, .any]
|
||||||
|| ((key_type.is_int() || key_type.is_float() || is_alias) && !key_type.is_ptr())
|
|| ((key_type.is_int() || key_type.is_float() || is_alias) && !key_type.is_ptr())
|
||||||
|
13
vlib/v/tests/parse_invalid_map_type_test.v
Normal file
13
vlib/v/tests/parse_invalid_map_type_test.v
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import v.ast
|
||||||
|
import v.parser
|
||||||
|
import v.pref
|
||||||
|
|
||||||
|
fn test_parser_map_type() {
|
||||||
|
result := parser.parse_text('a := map[*Node]bool', '', ast.new_table(), .parse_comments,
|
||||||
|
&pref.Preferences{
|
||||||
|
output_mode: .silent
|
||||||
|
is_fmt: true
|
||||||
|
})
|
||||||
|
println(result)
|
||||||
|
assert true
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user