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

pull/10022/head
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 { pub struct MyStruct {
mut: mut:
value int value int
foo mod.Foo
} }
pub fn (m MyStruct) foo() bool { 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.next()
p.check(.dot) p.check(.dot)
} }
if !p.known_import(mod) { if !p.known_import(mod) && !p.pref.is_fmt {
mut msg := 'unknown module `$mod`' mut msg := 'unknown module `$mod`'
if mod.len > mod_last_part.len && p.known_import(mod_last_part) { if mod.len > mod_last_part.len && p.known_import(mod_last_part) {
msg += '; did you mean `$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 { if mod in p.imports {
p.register_used_import(mod) p.register_used_import(mod)
mod = p.imports[mod]
} }
// prefix with full module // 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() { if p.tok.lit.len > 0 && !p.tok.lit[0].is_capital() {
p.error('imported types must start with a capital letter') p.error('imported types must start with a capital letter')
return 0 return 0