Debug help - Ranges - Programming in D page 598

Steven Schveighoffer schveiguy at gmail.com
Fri Aug 29 01:24:40 UTC 2025


On Thursday, 28 August 2025 at 11:54:10 UTC, Brother Bill wrote:
> If line 9 of the program is commented out, it runs fine.
> Otherwise lots of error messages which don't pan out for me.
> I tried changing Negative.front to be const, which didn't help.
> I am not quite sure what the error messages are telling me.
>
> Thank you for your assistance!
>
> ```
> C:\D\dmd2\windows\bin64\..\..\src\phobos\std\range\package.d(4560): Error: mutable method `app.Negative!(Take!(FibonacciSeries)).Negative.front` is not callable using a `const` object
>                 return _current.front;
>                        ^
> c:\dev\D\81 - 
> 90\c82_1e_InputRange_does_support_cycle_with_save\source\app.d(44):        Consider adding `const` or `inout` here
>     auto front()
>          ^
> C:\D\dmd2\windows\bin64\..\..\src\phobos\std\range\package.d(4695): Error: template instance `std.range.Cycle!(Negative!(Take!(FibonacciSeries)))` error instantiating
>     else return Cycle!R(input);
>                 ^
> c:\dev\D\81 - 
> 90\c82_1e_InputRange_does_support_cycle_with_save\source\app.d(9):        instantiated from here: `cycle!(Negative!(Take!(FibonacciSeries)))`
>             .cycle      // ← compilation ERROR
>             ^
> ```
This looks like a bug in the library or the compiler.

This code is the code that is failing:

```d
         static if (is(typeof((cast(const R)_current).front)))
         {
             /// ditto
             @property auto ref front() const
             {
                 return _current.front;
             }
         }
```

What the intent looks to me like is, if `_current.front` can be 
called on a const object, then we can forward the const-ness by 
declaring a const-allowing `front` function.

Well, looking at the `Negative.front` function, I see no 
attribute of `const`.

There is something sutble here as well. `is(typeof(funcname))` 
does not check if `funcname` is valid as an *expression*, but as 
a *symbol*.

And part of this also is that you are forming an rvalue, which 
has different implications for pure value types (which this whole 
thing is).

If I change that test to `static if (is(typeof((cast(const 
R*)&_current).front)))` then the code works. But I'm not sure if 
there's still not a compiler bug somewhere.

Will file an issue, and we should get this fixed.

-Steve


More information about the Digitalmars-d-learn mailing list