From 8c448736748baefd677d6157ba88393079677bcd Mon Sep 17 00:00:00 2001 From: zakuro Date: Wed, 5 May 2021 20:09:30 +0900 Subject: [PATCH] fmt,parser: prevent unknown module error (#10004) --- vlib/v/fmt/tests/module_struct_keep.vv | 1 + vlib/v/parser/parse_type.v | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/vlib/v/fmt/tests/module_struct_keep.vv b/vlib/v/fmt/tests/module_struct_keep.vv index 39dd3daedb..87c6ff8204 100644 --- a/vlib/v/fmt/tests/module_struct_keep.vv +++ b/vlib/v/fmt/tests/module_struct_keep.vv @@ -3,6 +3,7 @@ module module_fmt pub struct MyStruct { mut: value int + foo mod.Foo } pub fn (m MyStruct) foo() bool { diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 3b39ecfbe1..a4c251d0b6 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -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