According to the spec, "If applied to an expression, it is the source representation of that expression. Semantic analysis is not done for that expression."
But it seems that semantic analysis always occurs. This does not compile:
---
const char [] q = (1.2143*nonexistent).stringof;
---
By contrast, is() expressions also don't do semantic analysis, and they work correctly:
static assert(!is(typeof(1.2143*nonexistent)));
Comment #1 by matti.niemenmaa+dbugzilla — 2007-04-14T09:41:54Z
The spec's .stringof example doesn't even compile:
import std.stdio;
struct Foo { }
enum Enum { RED }
typedef int myint;
void main()
{
writefln((1+2).stringof); // "1 + 2"
writefln(Foo.stringof); // "Foo"
writefln(test.Foo.stringof); // "test.Foo"
writefln(int.stringof); // "int"
writefln((int*[5][]).stringof); // "int*[5][]"
writefln(Enum.RED.stringof); // "Enum.RED"
writefln(test.myint.stringof); // "test.myint"
writefln((5).stringof); // "5"
}
test.Foo.stringof and test.myint.stringof refuse to compile. Adding "module test;" makes them compile, but then the results are not "test.Foo" and "test.myint", but only "Foo" and "myint".