D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1168 - Passing a .stringof of an expression as a template value parameter results in the string of the type
Summary: Passing a .stringof of an expression as a template value parameter results in...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P3 normal
Assignee: No Owner
URL:
Keywords: patch, wrong-code
: 1465 (view as issue list)
Depends on:
Blocks:
 
Reported: 2007-04-20 07:12 UTC by Matti Niemenmaa
Modified: 2014-02-16 15:22 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Matti Niemenmaa 2007-04-20 07:12:58 UTC
(Set version as 1.012, since 1.013 wasn't in the list yet.)

template T(char[] s) {
	const char[] T = s;
}

char[] f(char[] s) {
	return s;
}

void main() {
	int foo;
	assert (foo.stringof == f(foo.stringof));  // works
	assert (foo.stringof == T!(foo.stringof)); // fails
}

T!(foo.stringof) results in "int", it should be "foo".
Comment 1 Matti Niemenmaa 2007-09-01 03:49:01 UTC
*** Bug 1465 has been marked as a duplicate of this bug. ***
Comment 2 Jeremie Pelletier 2009-09-05 13:47:22 UTC
The following patch to mtype.c fix the issue:

--- ..\src\orig\mtype.cpp	Thu Sep 03 01:01:40 2009
+++ ..\src\dmd\mtype.cpp	Sat Sep 05 16:42:50 2009
@@ -4530,6 +4530,11 @@
 			goto Lerror;
 		    goto L3;
 		}
+		else if(v && id == Id::stringof) {
+			e = new DsymbolExp(loc, s, 0);
+			*pe = new DotIdExp(loc, e, id);
+			return;
+		}
 		t = s->getType();
 		if (!t && s->isDeclaration())
 		    t = s->isDeclaration()->type;

It turns out stringof was applied on the type of the Dsymbol, not the symbol itself.
Comment 3 Don 2009-09-07 00:37:21 UTC
Cool! Add 'patch' to the list of keywords when you've submitted a patch, it makes them easier to track.
Comment 4 Walter Bright 2009-10-06 02:12:29 UTC
Fixed dmd 1.048 and 2.033