mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: improve error message for mod.unknownsubmod.Type
(#9976)
This commit is contained in:
parent
298fc533e4
commit
1e856c0f94
@ -330,17 +330,31 @@ pub fn (mut p Parser) parse_any_type(language ast.Language, is_ptr bool, check_d
|
||||
} else if p.peek_tok.kind == .dot && check_dot {
|
||||
// `module.Type`
|
||||
// /if !(p.tok.lit in p.table.imports) {
|
||||
if !p.known_import(name) {
|
||||
p.error('unknown module `$p.tok.lit`')
|
||||
return 0
|
||||
}
|
||||
if p.tok.lit in p.imports {
|
||||
p.register_used_import(p.tok.lit)
|
||||
}
|
||||
mut mod := name
|
||||
mut mod_pos := p.tok.position()
|
||||
p.next()
|
||||
p.check(.dot)
|
||||
mut mod_last_part := mod
|
||||
for p.peek_tok.kind == .dot {
|
||||
mod_pos = mod_pos.extend(p.tok.position())
|
||||
mod_last_part = p.tok.lit
|
||||
mod += '.$mod_last_part'
|
||||
p.next()
|
||||
p.check(.dot)
|
||||
}
|
||||
if !p.known_import(mod) {
|
||||
mut msg := 'unknown module `$mod`'
|
||||
if mod.len > mod_last_part.len && p.known_import(mod_last_part) {
|
||||
msg += '; did you mean `$mod_last_part`?'
|
||||
}
|
||||
p.error_with_pos(msg, mod_pos)
|
||||
return 0
|
||||
}
|
||||
if mod in p.imports {
|
||||
p.register_used_import(mod)
|
||||
}
|
||||
// prefix with full module
|
||||
name = '${p.imports[name]}.$p.tok.lit'
|
||||
name = '${p.imports[mod]}.$p.tok.lit'
|
||||
if p.tok.lit.len > 0 && !p.tok.lit[0].is_capital() {
|
||||
p.error('imported types must start with a capital letter')
|
||||
return 0
|
||||
|
5
vlib/v/parser/tests/struct_field_unknown_module_a.out
Normal file
5
vlib/v/parser/tests/struct_field_unknown_module_a.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/parser/tests/struct_field_unknown_module_a.vv:2:7: error: unknown module `ui`
|
||||
1 | struct Inter {
|
||||
2 | code ui.KeyCode
|
||||
| ~~
|
||||
3 | }
|
3
vlib/v/parser/tests/struct_field_unknown_module_a.vv
Normal file
3
vlib/v/parser/tests/struct_field_unknown_module_a.vv
Normal file
@ -0,0 +1,3 @@
|
||||
struct Inter {
|
||||
code ui.KeyCode
|
||||
}
|
5
vlib/v/parser/tests/struct_field_unknown_module_b.out
Normal file
5
vlib/v/parser/tests/struct_field_unknown_module_b.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/parser/tests/struct_field_unknown_module_b.vv:2:7: error: unknown module `term.unknownmod`
|
||||
1 | struct Inter {
|
||||
2 | code term.unknownmod.KeyCode
|
||||
| ~~~~~~~~~~~~~~~
|
||||
3 | }
|
3
vlib/v/parser/tests/struct_field_unknown_module_b.vv
Normal file
3
vlib/v/parser/tests/struct_field_unknown_module_b.vv
Normal file
@ -0,0 +1,3 @@
|
||||
struct Inter {
|
||||
code term.unknownmod.KeyCode
|
||||
}
|
6
vlib/v/parser/tests/struct_field_unknown_module_c.out
Normal file
6
vlib/v/parser/tests/struct_field_unknown_module_c.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/parser/tests/struct_field_unknown_module_c.vv:4:7: error: unknown module `term.ui`; did you mean `ui`?
|
||||
2 |
|
||||
3 | struct Inter {
|
||||
4 | code term.ui.KeyCode
|
||||
| ~~~~~~~
|
||||
5 | }
|
5
vlib/v/parser/tests/struct_field_unknown_module_c.vv
Normal file
5
vlib/v/parser/tests/struct_field_unknown_module_c.vv
Normal file
@ -0,0 +1,5 @@
|
||||
import term.ui
|
||||
|
||||
struct Inter {
|
||||
code term.ui.KeyCode
|
||||
}
|
Loading…
Reference in New Issue
Block a user