Auto return type inference issue?

Jesse Phillips via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 22 17:02:27 PDT 2014


On Tuesday, 22 April 2014 at 07:54:34 UTC, Matthew Dudley wrote:
> Here's the gist of what I'm trying to do.
>
> https://gist.github.com/pontifechs/11169069
>
> I'm getting an error I don't understand:
>
> tinker.d(42): Error: mismatched function return type inference 
> of tinker.B and tinker.A
> tinker.d(55): Error: template instance tinker.DynamicTuple!(A, 
> B).DynamicTuple.notopDispatch!"one" error instantiating
> Failed: 'dmd' '-v' '-o-' 'tinker.d' '-I.'
>
> Also, as an aside, why can't tuples be indexed dynamically? 
> Most of my problems with this have been because you apparently 
> can't.

Might have this a little bit wrong, just a quick hand translation 
of:

     foreach (i, elem; tuple)
         if (names[i] == s)
         {
             return elem;
         }

This becomes something like:

     if (names[0] == "one")
         return A;
     if (names[1] == "one")
         return B;

As said I could have this mixed up, but /elem/ is a type. But 
even if they were an object, you are saying that this method may 
return an A or a B, it is not legal for a function to return 
different types.

I'd suggest a static if, but since /names/ is dynamic, that won't 
work.


More information about the Digitalmars-d-learn mailing list