Bug?

Jack Applegame japplegame at gmail.com
Mon May 11 12:20:06 UTC 2020


Why doesn't it compile?

```
struct Range(R) {
     import std.array : empty, front, popFront;
     R range;
     bool empty() const { return range.empty; }
     auto front() const { return range.front; }
     void popFront() { range.popFront(); }
}

void main() {
     auto rng = Range!string("1234");
     assert(rng.front == 1);
}
```

onlineapp.d(11): Error: void has no value
onlineapp.d(11): Error: incompatible types for (rng.front) == 
(1): void and int

try here: https://run.dlang.io/is/Dg8Fpr

If you move the import to the global scope, you will get a weird 
result:

```
import std.stdio;
import std.array : empty, front, popFront;

struct Range(R) {
     R range;
     bool empty() const { return range.empty; }
     auto front() const { return range.front; }
     void popFront() { range.popFront(); }
}

void main() {
     auto rng = Range!string("1234");
     writefln("front: %s", rng.front);
     assert(rng.front == 1);
}
```

front: 1
core.exception.AssertError at onlineapp.d(14): Assertion failure
----------------
??:? _d_assertp [0x56107489bc75]
onlineapp.d:14 _Dmain [0x561074889902]

try here: https://run.dlang.io/is/arieKR

WAT???



More information about the Digitalmars-d-learn mailing list