D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1142 - .stringof performs semantic analysis
Summary: .stringof performs semantic analysis
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull, rejects-valid, spec
Depends on:
Blocks:
 
Reported: 2007-04-13 20:39 UTC by Don
Modified: 2019-07-16 14:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2007-04-13 20:39:19 UTC
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 Matti Niemenmaa 2007-04-14 09:41:54 UTC
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 3 Mathias LANG 2019-05-21 00:57:37 UTC
Still an issue in D2.
Comment 4 Dlang Bot 2019-07-12 09:38:55 UTC
@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 Dlang Bot 2019-07-16 14:14:32 UTC
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