[Issue 15537] Private function is not accessible from other module when compiling with -debug flag

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jul 19 12:02:14 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=15537

--- Comment #2 from Roman <freeslave93 at gmail.com> ---
(In reply to Vladimir Panteleev from comment #1)
> The reason why this doesn't compile with -debug is mentioned briefly in the
> assumeSorted documentation:
> 
> > In debug mode, a few random elements of r are checked for sortedness. 
> 
> -- https://dlang.org/library/std/range/assume_sorted.html
> 
> Thus, std.range is failing to use your private compare function when
> attempting to perform this sortedness check.
> 
> Note that even if the code compiled without -debug, the result would still
> not be useful, as you would not be able to pass the resulting SortedRange
> e.g. to std.algorithm.searching.find. It would fail with the same problem,
> being unable to access your private opCmp function.
> 
> Whether symbols passed by alias parameter should be exempted from visibility
> checks is a separate matter.
> 
> You can work around this problem by making the comparison function public,
> but also wrapping it inside a private struct:
> 
> private struct Hidden
> {
>     public static bool myCmp(Data a, Data b) {
>         return a[0] < b[0];
>     }
> }
> 
> auto bar() {
>     return [Data(1, "one"), Data(2, "two")].assumeSorted!(Hidden.myCmp);
> }

Back then I solved this issue by using named enum string variables.
Both solutions are hacks for sure. I think the changes to the compiler are
required.

--


More information about the Digitalmars-d-bugs mailing list