On Thursday, 26 April 2012 at 03:44:27 UTC, Walter Bright wrote:
A subtle but nasty problem - are default arguments part of the type, or part of the declaration?

   See http://d.puremagic.com/issues/show_bug.cgi?id=3866

Currently, they are both, which leads to the nasty behavior in the bug report.

From what I would name "normative" view they should be the same type: function type is charcterized by return type and by number and order of parameters' types. Because both functions accept and return the same types they should be the same function type. On the other hand, D is an ongoing project and you are free to implement special behavior.


The problem centers around name mangling. If two types mangle the same, then they are the same type. But default arguments are not part of the mangled string. Hence the schizophrenic behavior.


I think it should be done in reverse order: firstly decide whether they are the same or not, than apply mangling to the decision. Tail doesn't wag a dog.

But if we make default arguments solely a part of the function declaration, then function pointers (and delegates) cannot have default arguments. (And maybe this isn't a bad thing?)

The bad thing is that we would need extra typing, the good thing is that if the declaration changes the bug wouldn't be hidden. That I find similar to the D policy of preventing function hijacking, etc.

Reply via email to