Bug 20351 – Unknown error, should actually be: pure function cannot call impure function

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-11-04T02:21:48Z
Last change time
2023-03-01T11:48:44Z
Keywords
diagnostic, ice-on-invalid-code
Assigned to
No Owner
Creator
elpenguino+D

Comments

Comment #0 by elpenguino+D — 2019-11-04T02:21:48Z
``` 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().
Comment #1 by razvan.nitu1305 — 2023-03-01T11:48:44Z
Hmm, I cannot reproduce this. The code seems to compile.