<div class="gmail_quote">On 27 August 2012 16:23, kenji hara <span dir="ltr"><<a href="mailto:k.hara.pg@gmail.com" target="_blank">k.hara.pg@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I think that the function type and its mangled name must not contain<br>
the default args, then I can agree with Walter at the point.<br>
<br>
But, I think the variables of function pointers and delegates still<br>
can have default args as a part of their declarations.<br>
(It will be a part of VarDeclaration, not a part of TypeFunction)<br>
In following case, the default arg looks like a part of the type, but<br>
actually is a part of the declaration of fp.<br>
<br>
void function(int n = 10) fp;<br>
pragma(msg, typeof(fp));  // should print void function(int), because<br>
default args are not a part of type.<br>
fp();  // I think this can be allowed, because fp can remember that<br>
the first parameter has the default argument.<br>
<br>
But, it seems to me there are some corner cases.<br>
<br>
  // fp will *inherit* default args from its initializer, or not?<br>
  auto fp = (int n = 10){}<br></blockquote><div><br></div><div>I'd say, will.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">  // what is the actual default arg of fp?<br>

  void function(int n = 10) fp1 = (int n = 20){}<br></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">  void function(int n) fp2 = (int n = 30){}<br>
  void function(int n = 40) fp3 = (int n){}<br></blockquote><div><br></div><div>The declaration (on the left) is correct in all cases. It was explicitly stated when defining the variable.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  // fp has ambiguous default arg, or has no default arg?<br>
  auto fp1 = some_runtime_condition ? (int n = 10){} : (int n = 20){} ;<br></blockquote><div><br></div><div>Finally, a REAL conundrum! :) .. Not sure what to tell you... Error? Warning, and remove the default arg since there's a disagreement?</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  // more complicated case, first defarg is same, then it will be *inherited*?<br>
  auto fp2 = some_runtime_condition ? (int n = 10, string s =<br>
"hello"){} : (int n = 10, string s = "world"){} ;<br></blockquote><div><br></div><div>Same problem as above. I'd say hard error, since this is a) extremely unlikely! And b) it's obvious there's no 'correct' conclusion anyway.</div>
<div>The user writing that code clearly imagines that D is a dynamic language, and doesn't properly understand the nature of a compiled language.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  int function(int n = 10) fp;   // default arg of the first parameter is 10<br>
  fp = (int n = 20){ return n; }  // function literal's default arg<br>
will be ignored (in my opinion), is this expected?<br></blockquote><div><br></div><div>Agree, the variable was already defined by the users explicit request.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  // returning function pointer/delegate type can have default args?<br>
  int delegate(int n = 10) foo(int x) { ... }<br></blockquote><div><br></div><div>Sure, why not? If the recipient is auto, then it should inherit those properties.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If we can take agreements each other about them, it may be supported.<br></blockquote><div><br></div><div>+1 for Kenji :)</div></div>