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
@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!