www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21343] New: When a function takes a tuple created using


          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 puremagic.com
          Reporter: default_357-line 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'.

Oct 27 2020