vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.5k stars 2.15k forks source link

when <circular> printing does not show the number of item in the array #21689

Open Eliyaan opened 1 week ago

Eliyaan commented 1 week ago

Describe the bug

When printing a struct with an array that prints as [<circular>], it does not show the number of items in the array.

Reproduction Steps

 struct Bar {
 mut:
         children []Bar
 }

 fn main() {
         mut a := Bar{}
         a.children << Bar{}
         a.children << Bar{}
         println(a)
         println(a.children)
}

Expected Behavior

Bar{
    children: [<circular>, <circular>]
}
[Bar{
    children: []
}, Bar{
    children: []
}]

Current Behavior

Bar{
    children: [<circular>]
}
[Bar{
    children: []
}, Bar{
    children: []
}]

Possible Solution

No response

Additional Information/Context

And maybe instead of <circular> the print could show <circular?> as it does not know whether or not it is circular.

V version

V full version: V 0.4.6 294f7e4.bebe943

Environment details (OS name and version, etc.)

V full version: V 0.4.6 294f7e4.bebe943
OS: linux, Linux version 6.7.11-200.fc39.x86_64 (mockbuild@bdb8d24f206645e2bda44c1cf867612d) (gcc (GCC) 13.2.1 20240316 (Red Hat 13.2.1-7), GNU ld version 2.40-14.fc39) #1 SMP PREEMPT_DYNAMIC Wed Mar 27 16:50:39 UTC 2024

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

JalonSolov commented 1 week ago

The problem it is reporting is circular references. Why would you need to know how many were in the same array?

Eliyaan commented 1 week ago

Because it is useful when debugging to know how many items are in the array. related conversation: https://discord.com/channels/592103645835821068/592106336838352923/1251933620214693978