checker: show error instead of panic, when using a `somemodule.NonExistingEnum.enum_value` (#13295)

pull/13311/head
Yamada Hayao 2022-01-28 18:02:51 +09:00 committed by GitHub
parent 1f20127502
commit edc6c9e24f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 0 deletions

View File

@ -3708,6 +3708,10 @@ pub fn (mut c Checker) enum_val(mut node ast.EnumVal) ast.Type {
c.error('unknown enum `$node.enum_name` (type_idx=0)', node.pos)
return ast.void_type
}
} else {
// if module prefix specified enum name given
c.error('unknown enum `$node.enum_name` (type_idx=0)', node.pos)
return ast.void_type
}
}
mut typ := ast.new_type(typ_idx)

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/enum_error_module.vv:5:13: error: unknown enum `missing_enum.ColoList` (type_idx=0)
3 | fn main() {
4 | mut c := me.Color{
5 | color: me.ColoList.black
| ~~~~~~~~~~~~~~
6 | }
7 | println(c)

View File

@ -0,0 +1,8 @@
import missing_enum as me
fn main() {
mut c := me.Color{
color: me.ColoList.black
}
println(c)
}

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/modules/missing_enum/main.v:1:1: error: project must include a `main` module or be a shared library (compile with `v -shared`)
1 | module missing_enum
| ^
2 |
3 | pub enum ColorList {

View File

@ -0,0 +1,12 @@
module missing_enum
pub enum ColorList {
red
blue
green
black
}
pub struct Color {
color ColorList
}