D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8985 - Get default parameter value as alias
Summary: Get default parameter value as alias
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: industry
Depends on:
Blocks:
 
Reported: 2012-11-08 14:50 UTC by Manu
Modified: 2024-12-13 18:02 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 Manu 2012-11-08 14:50:57 UTC
import std.traits;

struct Vector
{
	float x,y,z,w;
	immutable Vector one = Vector(1,1,1,1);
}

void func(int x = 10, ref const Vector v = Vector.one);

static if(is(typeof(func) PT == __parameters))
	pragma(msg, PT);


Output: (int x = 10, ref const(Vector) v = one)

Notice: 'one' has had the 'Vector.' removed from infront, it is no longer a valid identifier.
It'd be nice if that string would rather produce a fully justified name: (int x = 10, ref const(Vector) v = modulename.Vector.one)
This way it would remain a valid identifier, and usable in mixins.

Walter has some reservations about making this change, concerned it may be a breaking change.

I argue that the only reason anyone would want to use this string is for something like a mixin, and encouraging people to write a large system around this functionality to parse the string and put 'Vector.' back on is not something you want to stick with. (this is what I was tempted to do, but dismissed it on basis of insanity)
Comment 1 Vladimir Panteleev 2017-06-25 10:20:35 UTC
The problem is not with __parameters, which works as expected. __parameters is not a tuple string, it rather seems to be a tuple of types with default values attached to them.

If there was a way to get said default value as an alias, then it would then be possible to pass it to fullyQualifiedName to achieve your desired goal.
Comment 2 dlangBugzillaToGithub 2024-12-13 18:02:41 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17563

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB