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@onlineapp.d(14): Assertion failure
----------------
??:? _d_assertp [0x56107489bc75]
onlineapp.d:14 _Dmain [0x561074889902]

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

WAT???

  • Bug? RazvanN via Digitalmars-d-learn
    • Re: Bug? Simen Kjærås via Digitalmars-d-learn
      • Re: Bug? RazvanN via Digitalmars-d-learn
    • Bug? Jack Applegame via Digitalmars-d-learn
      • Re: Bug? Jack Applegame via Digitalmars-d-learn
        • Re: Bug? Jack Applegame via Digitalmars-d-learn
      • Re: Bug? Adam D. Ruppe via Digitalmars-d-learn
        • Re: Bug? Jack Applegame via Digitalmars-d-learn
          • Re: Bug? Steven Schveighoffer via Digitalmars-d-learn
            • Re: Bug... Adam D. Ruppe via Digitalmars-d-learn
          • Re: Bug? Simen Kjærås via Digitalmars-d-learn
            • Re: Bug... Jack Applegame via Digitalmars-d-learn

Reply via email to