cannot call impure function

Michael trash at can.edu
Sun Oct 4 16:48:24 UTC 2020


Dear all,

Sorry for the potentially stupid question, but I'm a complete 
newbie to D. Why does compiling the following trivial code fail?

import std.stdio;

void main()
{
     writeln(3.14);
}

Error message:

/Library/D/dmd/src/phobos/std/format.d(1601): Error: pure 
function std.format.FormatSpec!char.FormatSpec.toString cannot 
call impure function 
std.format.FormatSpec!char.FormatSpec.toString!(Appender!string).toString
/Library/D/dmd/src/phobos/std/format.d(478): Error: template 
instance std.format.FormatSpec!char error instantiating
/Library/D/dmd/src/phobos/std/stdio.d(1590):        instantiated 
from here: formattedWrite!(LockingTextWriter, char, double)
/Library/D/dmd/src/phobos/std/stdio.d(3927):        instantiated 
from here: write!(double, char)
test1.d(5):        instantiated from here: writeln!double

Cheers,
Michael


More information about the Digitalmars-d-learn mailing list