[Issue 21343] New: When a function takes a tuple created using __parameters, parameters are individually accessible

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 27 08:49:44 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=21343

          Issue ID: 21343
           Summary: When a function takes a tuple created using
                    __parameters, parameters are individually accessible
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: default_357-line at yahoo.de

Consider the following code:

```
import std.stdio;
import std.traits;

void foo(int value) { }

static if (is(FunctionTypeOf!foo Params == __parameters))
{
    void bar(Params params)
    {
        writefln!"%s, but %s also works??"(value, params);
    }
}

void main() { bar(5); }
```

Note how bar, despite taking a tuple called "params", can also access the
individual parameter 'value' from foo.

This can cause name collisions when you try to declare a variable called
'value'. Since this is used for metaprogramming, this introduces the risk of
name collisions based on parameter names in functions passed to a
metaprogramming function, which is quite hard to debug.

Since the parameters are already accessible via 'params', the individual
parameters should not also be visible inside 'bar'.

--


More information about the Digitalmars-d-bugs mailing list