[Issue 23264] Allow __traits(parameters) in the return type or contract of a function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Aug 29 12:11:42 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23264
--- Comment #2 from Bolpat <qs.il.paperinik at gmail.com> ---
(In reply to wolframw from comment #1)
> There would be an ambiguity for nested functions:
>
> void foo(T1...)(T1 args1)
> {
> typeof(__traits(parameters))[0] bar(T2...)(T2 args2)
> {
> // ...
> }
> }
>
> Would the return value of bar depend on foo's or bar's parameters?
> Currently, it would refer to foo's parameters.
Good catch! I don’t think it’s a big problem. Return types are ambiguous in the
same fashion:
void f(T)()
{
T g(T)() { return T.init; }
}
The `T` value that function `g` returns could – for the uninformed reader –
mean f’s type parameter or g’s type parameter (of course, it’s g’s). I see no
reason why __traits(parameters) would work any differently. Also, if you wanted
the outer function’s parameters, one can alias them.
void foo(T1...)(T1 args1)
{
alias fooParams = typeof(__traits(parameters));
fooParams[0] bar(T2...)(T2 args2)
{
// ...
}
}
--
More information about the Digitalmars-d-bugs
mailing list