www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20351] New: Unknown error, should actually be: pure function

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

          Issue ID: 20351
           Summary: Unknown error, should actually be: pure function
                    cannot call impure function
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: diagnostic, ice-on-invalid-code
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: elpenguino+D gmail.com

```
import std.format : formattedWrite;
import std.typecons : Nullable;

struct GS {
        BS bs;

        static int gTD() {
                static Nullable!GS ltd;
                return 0;
        }
}



struct BS {
        void toString(T)(T sink) const {
                sink.formattedWrite!"%s"(c());
        }
}

static immutable uint d;

struct C(T) {
        void toString(F)(F sink) const {
                import std.format : formattedWrite;
                sink.formattedWrite!"%s"(1.0);
        }
        void __toString() pure {
                import std.array : Appender;
                auto buf = new Appender!(char[]);
                toString(buf);
        }
}

auto c()() {
        return C!(double)();
}
```

The real error here is that C!double.__toString() can't call impure function
C!double.toString().

--
Nov 03 2019