Bug 1142 – .stringof performs semantic analysis

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2007-04-13T20:39:19Z
Last change time
2019-07-16T14:14:32Z
Keywords
pull, rejects-valid, spec
Assigned to
No Owner
Creator
Don
See also
https://issues.dlang.org/show_bug.cgi?id=17546

Comments

Comment #0 by clugdbug — 2007-04-13T20:39:19Z
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".
Comment #2 by thomas-dloop — 2007-04-23T12:56:54Z
Comment #3 by pro.mathias.lang — 2019-05-21T00:57:37Z
Still an issue in D2.
Comment #4 by dlang-bot — 2019-07-12T09:38:55Z
@RazvanN7 created dlang/dlang.org pull request #2679 "Fix Issue 1142 - .stringof performs semantic analysis" fixing this issue: - Fix Issue 1142 - .stringof performs semantic analysis https://github.com/dlang/dlang.org/pull/2679
Comment #5 by dlang-bot — 2019-07-16T14:14:32Z
dlang/dlang.org pull request #2679 "Fix Issue 1142 - .stringof performs semantic analysis" was merged into master: - aeeeac7d2aa62b68d803b3bdb996a1ee06979ce3 by RazvanN7: Fix Issue 1142 - .stringof performs semantic analysis https://github.com/dlang/dlang.org/pull/2679