Thread overview | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 01, 2010 [Issue 3866] New: anonymous delegate with default parameters cross-talks to another anonymous delegate | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=3866 Summary: anonymous delegate with default parameters cross-talks to another anonymous delegate Product: D Version: 2.040 Platform: Other OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: philippe.sigaud@gmail.com --- Comment #0 from Philippe Sigaud <philippe.sigaud@gmail.com> 2010-03-01 18:36:25 CET --- If you declare an anonymous delegate with default parameter, it affects another anonymous delegate with the same type: import std.stdio; void main() { auto foo = (int a = 1) { return a;}; auto bar = (int a) { return a;}; writeln(foo()); // writes '1' writeln(bar()); // writes '1' also! } It provokes (correctly) an error if bar is defined before foo: bar() called with 0 argument instead of 1. It does not affect delegate with another type auto baz = (double a) { return a;}; writeln(baz()); // Error, correct behaviour -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 19, 2011 [Issue 3866] anonymous delegate with default parameters cross-talks to another anonymous delegate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | http://d.puremagic.com/issues/show_bug.cgi?id=3866 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |wrong-code CC| |clugdbug@yahoo.com.au Severity|normal |critical -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 03, 2011 [Issue 3866] anonymous delegate with default parameters cross-talks to another anonymous delegate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | http://d.puremagic.com/issues/show_bug.cgi?id=3866 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch CC| |yebblies@gmail.com Platform|Other |All OS/Version|Windows |All --- Comment #1 from yebblies <yebblies@gmail.com> 2011-07-03 23:14:23 EST --- https://github.com/D-Programming-Language/dmd/pull/204 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
February 12, 2012 [Issue 3866] anonymous delegate with default parameters cross-talks to another anonymous delegate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | http://d.puremagic.com/issues/show_bug.cgi?id=3866 yebblies <yebblies@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|nobody@puremagic.com |yebblies@gmail.com --- Comment #2 from yebblies <yebblies@gmail.com> 2012-02-12 13:55:08 EST --- The problem occurs because default parameters are stored in the type, but types are considered equivalent if their mangled names match, and mangled names don't include parameter names or default arguments. The solution is probably either to include parameter names and default arguments in the comparison for equality, or to move them out of function types and into function declarations. I'm leaning towards the latter. This case _can_ be fixed by refusing to merge function pointers, but the problem will still exists for pointers to function pointers, structs containing function pointers, etc. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
April 26, 2012 [Issue 3866] anonymous delegate with default parameters cross-talks to another anonymous delegate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | http://d.puremagic.com/issues/show_bug.cgi?id=3866 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bugzilla@digitalmars.com --- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2012-04-25 20:35:30 PDT --- Moving the default arguments out of the type and into the function declaration will resolve the problem, at the cost of you would no longer be able to have default arguments for function literals or any pointers to functions. Perhaps that's a good thing. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
April 26, 2012 [Issue 3866] anonymous delegate with default parameters cross-talks to another anonymous delegate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | http://d.puremagic.com/issues/show_bug.cgi?id=3866 Jonathan M Davis <jmdavisProg@gmx.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jmdavisProg@gmx.com --- Comment #4 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-04-26 10:33:19 PDT --- It was my understanding that default arguments were just arguments that were inserted when a function was called and you didn't provide all of the arguments. They aren't actually part of the signature or type at all. As such, they are only known if you call the function directly. If you use a function pointer (or delegate), then all you have is the signature, so you don't have any default arguments. As such, nested functions with default arguments such as static auto foo(int a = 1) { return a; } and auto foo(int a = 1) { return a + b; } should work just fine, but as with any function, as soon as you take their address or turn them into a delegate variable, their default arguments are lost. And so having default arguments in something like auto foo = (int a = 1) { return a;}; auto bar = (int a) { return a;}; is completely pointless, because all you have is a variable which knows the signature of the function/delegate to call. The function itself can't be called directly, so it doesn't have any default arguments associated with it, and so there's no point in the default arguments even being legal. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
April 27, 2012 [Issue 3866] anonymous delegate with default parameters cross-talks to another anonymous delegate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | http://d.puremagic.com/issues/show_bug.cgi?id=3866 --- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2012-04-26 23:06:52 PDT --- Leaving this as-is for D1 to avoid breaking existing code. For D2, changing behavior so that default args are part of the declaration, not the type, and so both function calls in the example are illegal, since calling through a function pointer now cannot have default args. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
April 27, 2012 [Issue 3866] anonymous delegate with default parameters cross-talks to another anonymous delegate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | http://d.puremagic.com/issues/show_bug.cgi?id=3866 --- Comment #6 from github-bugzilla@puremagic.com 2012-04-26 23:10:36 PDT --- Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/acc22ce25db42facfe4917aeceabd28a410f4c95 fix Issue 3866 - anonymous delegate with default parameters cross-talks to another anonymous delegate -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
April 27, 2012 [Issue 3866] anonymous delegate with default parameters cross-talks to another anonymous delegate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | http://d.puremagic.com/issues/show_bug.cgi?id=3866 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 22, 2012 [Issue 3866] anonymous delegate with default parameters cross-talks to another anonymous delegate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | http://d.puremagic.com/issues/show_bug.cgi?id=3866 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |eco@gnuk.net --- Comment #7 from Walter Bright <bugzilla@digitalmars.com> 2012-07-22 13:08:12 PDT --- *** Issue 8258 has been marked as a duplicate of this issue. *** -- 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