Bug 21343 – When a function takes a tuple created using __parameters, parameters are individually accessible

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-10-27T08:49:44Z
Last change time
2024-12-13T19:12:19Z
Assigned to
No Owner
Creator
FeepingCreature
Moved to GitHub: dmd#19811 →

Comments

Comment #0 by default_357-line — 2020-10-27T08:49:44Z
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'.
Comment #1 by robert.schadek — 2024-12-13T19:12:19Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19811 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB