User defined properties signatures
dvic via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 20 13:41:24 PDT 2015
On Monday, 20 April 2015 at 20:22:40 UTC, Jonathan M Davis wrote:
> On Monday, April 20, 2015 19:42:30 dvic via Digitalmars-d-learn
> wrote:
>> Thanks for your answer Jonathan. But does the return type part
>> of
>> a method
>> signature? I don't know what theory is claiming about that, but
>> for me they
>> are 2 different methods. So contextually, the best fit should
>> prevail.
>
> The return type is not considered in overloading. And it would
> complicate
> things considerably if it were. Some basic cases are pretty
> obvious, like
>
> int foo();
> string foo();
> int a = foo()
>
> But what about something like
>
> int foo();
> float foo();
> auto a = foo() + foo();
>
> or
>
> int foo();
> string foo();
> void bar(int);
> void bar(string);
> bar(foo());
>
> It's far simpler for the language to not consider return types
> in
> overloading and to simply use it for the type of the resulting
> expression.
> Then it's generally straightforward for it to determine what
> the type of
> complex expressions are. But if the return type is considered in
> overloading, then it gets _way_ more complicated, especially
> when the
> expressions get at all complicated.
>
> At best, the compiler would be able to work in the simple cases
> and error
> out in the complex ones, but it wouldn't take much before it
> would have to
> give up and give an error due to ambiguity.
>
> There may be languages out there which take the the return type
> into account
> when overloading, but I've never seen one.
>
> - Jonathan M Davis
Thanks Johnathan for the detailed explanation !
More information about the Digitalmars-d-learn
mailing list