compiler: fix module alias resolution

pull/3539/head^2
joe-conigliaro 2020-01-24 07:07:53 +11:00 committed by Alexander Medvednikov
parent 0a93d3b714
commit 20f6cdc53a
3 changed files with 22 additions and 13 deletions

View File

@ -1,6 +1,6 @@
module main module main
import gg2 // as gg import gg2 as gg
import gx import gx
const ( const (
@ -10,12 +10,12 @@ const (
struct App { struct App {
mut: mut:
gg &gg2.GG gg &gg.GG
} }
fn main() { fn main() {
mut app := &App{} mut app := &App{}
app.gg = gg2.new_context({ app.gg = gg.new_context({
bg_color: gx.white bg_color: gx.white
width: win_width width: win_width
height: win_height height: win_height

View File

@ -147,8 +147,10 @@ fn (p mut Parser) get_type2() Type {
// try resolve full submodule // try resolve full submodule
if !p.builtin_mod && p.import_table.known_alias(typ) { if !p.builtin_mod && p.import_table.known_alias(typ) {
mod := p.import_table.resolve_alias(typ) mod := p.import_table.resolve_alias(typ)
if mod.contains('.') { typ = if mod.contains('.') {
typ = mod_gen_name(mod) mod_gen_name(mod)
} else {
mod
} }
} }
p.next() p.next()

View File

@ -1,18 +1,25 @@
import os import os
import time as t import time as t
import crypto.sha256 as s2 import crypto.sha256 as s2
import ( import (
math math
log as l log as l
crypto.sha512 as s5 crypto.sha512 as s5
) )
fn test_import() { struct TestAliasInStruct {
assert os.O_RDONLY == os.O_RDONLY && time t.Time
t.month_days[0] == t.month_days[0] && }
s2.size == s2.size &&
math.pi == math.pi && fn test_import() {
l.INFO == l.INFO && 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
s5.size == s5.size }
fn test_alias_in_struct_field() {
a := TestAliasInStruct{
time: t.Time{
year: 2020
}
}
assert a.time.year == 2020
} }