From 20f6cdc53a70d0d221412ddbdba17756e3330e4d Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Fri, 24 Jan 2020 07:07:53 +1100 Subject: [PATCH] compiler: fix module alias resolution --- examples/gg2.v | 6 +++--- vlib/compiler/get_type.v | 6 ++++-- vlib/compiler/tests/module_test.v | 23 +++++++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/examples/gg2.v b/examples/gg2.v index 259381237e..5cef9db2e6 100644 --- a/examples/gg2.v +++ b/examples/gg2.v @@ -1,6 +1,6 @@ module main -import gg2 // as gg +import gg2 as gg import gx const ( @@ -10,12 +10,12 @@ const ( struct App { mut: - gg &gg2.GG + gg &gg.GG } fn main() { mut app := &App{} - app.gg = gg2.new_context({ + app.gg = gg.new_context({ bg_color: gx.white width: win_width height: win_height diff --git a/vlib/compiler/get_type.v b/vlib/compiler/get_type.v index a774299987..3be336185a 100644 --- a/vlib/compiler/get_type.v +++ b/vlib/compiler/get_type.v @@ -147,8 +147,10 @@ fn (p mut Parser) get_type2() Type { // try resolve full submodule if !p.builtin_mod && p.import_table.known_alias(typ) { mod := p.import_table.resolve_alias(typ) - if mod.contains('.') { - typ = mod_gen_name(mod) + typ = if mod.contains('.') { + mod_gen_name(mod) + } else { + mod } } p.next() diff --git a/vlib/compiler/tests/module_test.v b/vlib/compiler/tests/module_test.v index bef880c678..e174093615 100644 --- a/vlib/compiler/tests/module_test.v +++ b/vlib/compiler/tests/module_test.v @@ -1,18 +1,25 @@ import os import time as t import crypto.sha256 as s2 - import ( math log as l crypto.sha512 as s5 ) -fn test_import() { - assert os.O_RDONLY == os.O_RDONLY && - t.month_days[0] == t.month_days[0] && - s2.size == s2.size && - math.pi == math.pi && - l.INFO == l.INFO && - s5.size == s5.size +struct TestAliasInStruct { + time t.Time +} + +fn test_import() { + assert os.O_RDONLY == os.O_RDONLY && t.month_days[0] == t.month_days[0] && s2.size == s2.size && math.pi == math.pi && l.INFO == l.INFO && s5.size == s5.size +} + +fn test_alias_in_struct_field() { + a := TestAliasInStruct{ + time: t.Time{ + year: 2020 + } + } + assert a.time.year == 2020 }