1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt,parser: prevent unknown module error (#10004)

This commit is contained in:
zakuro 2021-05-05 20:09:30 +09:00 committed by GitHub
parent 99a2fd76c8
commit 8c44873674
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -3,6 +3,7 @@ module module_fmt
pub struct MyStruct {
mut:
value int
foo mod.Foo
}
pub fn (m MyStruct) foo() bool {

View File

@ -342,7 +342,7 @@ pub fn (mut p Parser) parse_any_type(language ast.Language, is_ptr bool, check_d
p.next()
p.check(.dot)
}
if !p.known_import(mod) {
if !p.known_import(mod) && !p.pref.is_fmt {
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`?'
@ -352,9 +352,10 @@ pub fn (mut p Parser) parse_any_type(language ast.Language, is_ptr bool, check_d
}
if mod in p.imports {
p.register_used_import(mod)
mod = p.imports[mod]
}
// prefix with full module
name = '${p.imports[mod]}.$p.tok.lit'
name = '${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