Bug 8985 – Get default parameter value as alias

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-08T14:50:57Z
Last change time
2024-12-13T18:02:41Z
Keywords
industry
Assigned to
No Owner
Creator
Manu
Moved to GitHub: dmd#17563 →

Comments

Comment #0 by turkeyman — 2012-11-08T14:50:57Z
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 by dlang-bugzilla — 2017-06-25T10:20:35Z
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 by robert.schadek — 2024-12-13T18:02:41Z
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