Re: Module function conflicting with reserve function
On Tuesday, 6 November 2018 at 21:29:17 UTC, Stanislav Blinov wrote: On Tuesday, 6 November 2018 at 21:19:29 UTC, Peter Campbell wrote: Given your second example that makes me think that, because object functions are provided by the runtime without me explicitly importing it, this is likely only an issue for object functions? Or can this behaviour happen with any free functions with the same name but completely different parameter types? Not with completely different parameter types, no. But it can happen with functions imported from different modules, as they're from different overload sets. There's an example in that Overload Sets section of the spec. I see what you both mean now and understand what's going on. Thanks for clearing it up
Re: Module function conflicting with reserve function
On Tuesday, 6 November 2018 at 21:03:01 UTC, Stanislav Blinov wrote: It's not a bug, just the way name resolution works. Better have collision than silent overloads. Possible solutions: ``` void reserve(ref Bob system, in size_t capacity) { // explicitly disambiguate object.reserve(system._data, capacity); } ``` or: // pull in the runtime 'reserve' into this module's scope alias reserve = object.reserve; void reserve(ref Bob system, in size_t capacity) { // call reserve as usual system._data.reserve(capacity); } Given your second example that makes me think that, because object functions are provided by the runtime without me explicitly importing it, this is likely only an issue for object functions? Or can this behaviour happen with any free functions with the same name but completely different parameter types?
Module function conflicting with reserve function
Hi there. I've been playing with D and have encountered this really awkward behaviour. Basically I'm getting a compiler error inside a function I wrote in my module as it thinks I'm trying to call itself with invalid parameters, when actually I want it to call the reserve function on the array itself. Is this a bug or expected behaviour? It seems quite strange and potentially annoying to me. https://run.dlang.io/is/9YyAI9 module bob; struct Bob { private ubyte[] _data; } void reserve(ref Bob system, in size_t capacity) { // bob.reserve(ref Bob system, const(ulong) capacity) is not callable with (ubyte[], const(ulong)). system._data.reserve(capacity); } void main() { }
Re: Illegal behaviour or GDC bug?
On Thursday, 13 October 2016 at 20:18:31 UTC, ketmar wrote: sadly, gdc has way older frontend version than ldc (and dmd, of course). gdc is like 2.067, and ldc/dmd is 2.072. that this was fixed in later versions, but gdc is not updated yet. OK that's cool, I'll just avoid GDC for now. Is it generally a good approach to assume if something compiles in DMD then it's correct and just hope that GDC/LDC pick up the latest version at some point?
Illegal behaviour or GDC bug?
Good evening all, I'm just starting to learn D and I've been experimenting with some template stuff as well as checking out DMD, GDC and LDC. During my experimentation I found a piece of code that doesn't compile in GDC but does compile in DMD and LDC. The code snippet can be found here: http://dpaste.com/1BCVKSW Basically it's a 3D vector with some enums that reference the structure itself. In GDC produces the following errors: Line 9: error: cannot create a struct until its size is determined Line 19: error: template instance Vector3.Vector3T!float error instantiating I've seen this error in C++ before and I believe it's illegal behaviour in C++ land. In regard to D, both DMD and LDC seem to believe it's legal syntax and allow me to use it without problems. Have I found a bug with GDC or should I not be able to do this?