DIP 1023--Resolution of Template Alias Formal Parameters in Template Functions--Community Review Round 1

Stefanos Baziotis sdi1600105 at di.uoa.gr
Wed Sep 11 02:02:58 UTC 2019


On Wednesday, 11 September 2019 at 01:39:22 UTC, Stefanos 
Baziotis wrote:
> Yes, it should. As far as I can tell, the draft
> PR had a more complicated test case / example than this.

Actually, just checked on the draft PR, it doesn't work.

First of all, sorry for the fact that I have forgotten a lot of 
things
regarding the implementation and the DIP.
This implementation and DIP were authored 4 months ago.

As I understand it, because this PR and DIP handle template 
alias, they don't handle templates (that may somehow resolve to 
aliases). That may be an omission or
it may be out of scope of this DIP.

Let me try to make this more clear. The first test case in the PR 
is:

struct TestType(T, Q) { }

alias TestAlias(T, Q) = TestType!(T, Q);
static void testFunction(T, Q)(TestAlias!(T, Q) arg) { }

void main()
{
     TestAlias!(int, float) testObj;  // This resolves to TestType
     testFunction(testObj);  // testObj is passed with type 
TestType
}

So, right now, the _actual_ argument has the resolved type but 
the _formal_
argument (i.e. `arg`) has not. It has TestAlias. And so, we try 
to replace
this formal argument type with the actual type.

One could say that your example looks similar. We want to resolve 
the formal argument `x` to its actual type, but we're stuck in 
the Foo!T. The problem
is that `Foo` is not an alias. It's a template. And with a 
contract in it.

To me, it _seems_ like a  similar logic, but the implementation 
and the semantic details (which also implies - the formal 
specification in the DIP) are quite
different and would require major additions.

We may need a separate DIP for this.

Nonetheless, thank you very much for pointing it out! Either it's 
part of this
DIP or not.

- Stefanos


More information about the Digitalmars-d mailing list