V: circular import causes weird V panic

Created on 17 Jul 2019  Â·  13Comments  Â·  Source: vlang/v

V version: 0.1.15
OS: Xubuntu 18.04 LTS

What did you do?
make following project and execute v main.v

~/W/t/cir ❯❯❯ ls
mod1  mod2  main.v
~/W/t/cir ❯❯❯ cat main.v
module main

import mod1

fn main() {
    _ := mod1.Mod1Const
}
~/W/t/cir ❯❯❯ cat mod1/mod1.v                                                                                                                                                            
module mod1

import mod2

const (
    Mod1Const = mod2.Mod2Const
)
~/W/t/cir ❯❯❯ cat mod2/mod2.v
module mod2

import mod1

const (
    Mod2Const = mod1.Mod1Const
)

What did you expect to see?
compile error showing circular import exists

What did you see instead?

.main.c: In function ‘main’:
.main.c:3107:6: error: variable or field ‘_’ declared void
 void _= mod1__Mod1Const ;
      ^
.main.c:3107:9: error: void value not ignored as it ought to be
 void _= mod1__Mod1Const ;
         ^~~~~~~~~~~~~~~
.main.c: In function ‘init_consts’:
.main.c:3111:63: error: ‘mod1__Mod1Const’ has an incomplete type ‘void’
  void init_consts() { g_str_buf=malloc(1000); mod1__Mod1Const =  mod2__Mod2Const;
                                                               ^
.main.c:3112:17: error: ‘mod2__Mod2Const’ has an incomplete type ‘void’
 mod2__Mod2Const =  mod1__Mod1Const; }
                 ^
V panic: clang error
Bug

All 13 comments

@d2verb it's known issue, it's being worked on. The error is nothing to do with circular imports though, it's to do with deceleration order. But the circular import detection will be implemented.

@d2verb Can you please try this again, still no circular import detection, but this error should be fixed
edit: Sorry my bad, this case has to throw a compiler error. Ill have this done soon.

@d2verb This should fix it: https://github.com/vlang/v/pull/1237

@joe-conigliaro circular import detected!

>> v ./main.v 
V panic: Circular import detected between modules: mod1 & mod2.

nice work!

@joe-conigliaro
If dependency looks like

mod1 -> mod2 -> mod3
 ^               |
 |_______________|

the V panic still occurred...

.main.c: In function ‘init_consts’:
.main.c:3352:63: error: ‘mod1__Mod1Const’ has an incomplete type ‘void’
  void init_consts() { g_str_buf=malloc(1000); mod1__Mod1Const =  mod2__Mod2Const;
                                                               ^
.main.c:3353:17: error: ‘mod3__Mod3Const’ has an incomplete type ‘void’
 mod3__Mod3Const =  mod1__Mod1Const;
                 ^
.main.c:3354:17: error: ‘mod2__Mod2Const’ has an incomplete type ‘void’
 mod2__Mod2Const =  mod3__Mod3Const; }
                 ^
V panic: clang error

@d2verb thanks i will look into it

@d2verb I will have this fixed soon

I have fixed the issue but I need to detect if a const or struct references a circular import module, and only panic then. because that the only time it will cause problems. Otherwise I think they should be allowed. What do you think?

@joe-conigliaro I'm with you. circular import doesn't mean circular dependency.
If there is no circular dependency, I think we can allow circular import.

@d2verb exactly my thoughts, I'm working on this now! almost done

@d2verb I talked to Alex and for now there will be no circular importing allowed at all, like in go.
This has been fixed!

@joe-conigliaro Amazing works! thanks!

@d2verb thanks for reporting!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cjmxp picture cjmxp  Â·  3Comments

medvednikov picture medvednikov  Â·  3Comments

XVilka picture XVilka  Â·  3Comments

arg2das picture arg2das  Â·  3Comments

radare picture radare  Â·  3Comments