Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
September 09, 2012 [Issue 8634] New: Anonymous function parameters | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=8634 Summary: Anonymous function parameters Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: maxim@maxim-fomin.ru --- Comment #0 from Maxim Fomin <maxim@maxim-fomin.ru> 2012-09-09 05:28:51 PDT --- void foo(int) { } void main() { foo(5); } Although anonymous function parameters may be used in function declarations, it seems that dmd doesn't check whether a function declaration is a definition too. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
September 09, 2012 [Issue 8634] Anonymous function parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | http://d.puremagic.com/issues/show_bug.cgi?id=8634 bearophile_hugs@eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs@eml.cc --- Comment #1 from bearophile_hugs@eml.cc 2012-09-09 06:53:14 PDT --- (In reply to comment #0) > void foo(int) > { > > } > > void main() > { > foo(5); > } > > Although anonymous function parameters may be used in function declarations, it seems that dmd doesn't check whether a function declaration is a definition too. What's the problem here? foo() not giving a name to its first argument means the programmer is stating foo() never uses its first argument, and the D language allows the programmer to enforce this desire. This feature also allows to avoid "unused argument warnings" once/where such warning is available. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
September 09, 2012 [Issue 8634] Anonymous function parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | http://d.puremagic.com/issues/show_bug.cgi?id=8634 --- Comment #2 from Maxim Fomin <maxim@maxim-fomin.ru> 2012-09-09 07:02:06 PDT --- (In reply to comment #1) > (In reply to comment #0) > > void foo(int) > > { > > > > } > > > > void main() > > { > > foo(5); > > } > > > > Although anonymous function parameters may be used in function declarations, it seems that dmd doesn't check whether a function declaration is a definition too. > > What's the problem here? > > foo() not giving a name to its first argument means the programmer is stating > foo() never uses its first argument, and the D language allows the programmer > to enforce this desire. > > This feature also allows to avoid "unused argument warnings" once/where such warning is available. The problem is that such code is likely to be a bug (parameter name was forgotten) and compiler should report about this. BTW dmd doesn't produce any warning for unused variable. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
September 09, 2012 Re: [Issue 8634] Anonymous function parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | > BTW dmd doesn't produce any warning for unused variable.
And this will never change. ;)
|
September 09, 2012 Re: [Issue 8634] Anonymous function parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Sunday, 9 September 2012 at 19:59:02 UTC, Namespace wrote:
>> BTW dmd doesn't produce any warning for unused variable.
>
> And this will never change. ;)
Who knows, maybe eventually I'll be able to convince GDC maintainers to introduce this warning :-)
|
September 09, 2012 Re: [Issue 8634] Anonymous function parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Sunday, 9 September 2012 at 20:19:51 UTC, bearophile wrote:
> On Sunday, 9 September 2012 at 19:59:02 UTC, Namespace wrote:
>>> BTW dmd doesn't produce any warning for unused variable.
>>
>> And this will never change. ;)
>
> Who knows, maybe eventually I'll be able to convince GDC maintainers to introduce this warning :-)
But he said dmd. :P
|
September 09, 2012 [Issue 8634] Anonymous function parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | http://d.puremagic.com/issues/show_bug.cgi?id=8634 --- Comment #3 from bearophile_hugs@eml.cc 2012-09-09 13:35:05 PDT --- (In reply to comment #2) > The problem is that such code is likely to be a bug (parameter name was forgotten) and compiler should report about this. I care a lot about removing bug-prone situations from D language. And I think C# language acts as you ask. Generally C# designers are very careful in avoiding bug-prone features. But in general it's not so common to forget to add a name for the argument. And even in the cases where I have forgotten to put the argument name, this is usually not a big problem, because the compiler doesn't find the name you are using inside the function, and gives you a nice compilation error at the first usage attempt, close enough to the function signature (unless your functions are really long). In theory one bug-prone situation is when you use a name thinking it's the name of a local argument, while you have not given a name to the argument, and you have a name in an outer scope that is the same. So you are actually using the name of the outer scope. In practice my diary of bugs shows I have never hit this bug, also because it's generally a good practice to not define local names equal to outer names. So unless you have evidence that this is a common enough bug (even few anecdotes are enough to keep this discussion open) I think this bug report should be closed. > BTW dmd doesn't produce any warning for unused variable. I know, but probably someday some D compiler will report them. It's an useful feature and it's not too much hard to implement. All the major C++ compilers have an option to report them. But note here I was not referring to a generic "unused variable" warning, I was referring to more specifically to a "unused argument" warning. If you omit the argument name, the warning is silenced. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
September 10, 2012 [Issue 8634] Anonymous function parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | http://d.puremagic.com/issues/show_bug.cgi?id=8634 Maxim Fomin <maxim@maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID --- Comment #4 from Maxim Fomin <maxim@maxim-fomin.ru> 2012-09-10 05:22:14 PDT --- I have no desire for disputes about things which are not necessarily defective (as revealed here) and claimed by D people to be intentional part of the language. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation