Recommendations on avoiding range pipeline type hell

Chris Piker chris at hoopjump.com
Sun May 16 22:17:16 UTC 2021


On Sunday, 16 May 2021 at 13:35:02 UTC, Adam D. Ruppe wrote:
> Wait, what's the bug there? The typeof DOES tell you they are 
> separate.
>
> Error: cannot implicitly convert expression `b` of type 
> `S!(func2)` to `S!(func1)`

Sorry, it's a forum post, so I really should have been more 
explicit.

It seems there's a broken symmetry in compiler error reporting 
for the following, ostensibly identical, cases:
```d
struct S(alias Func){ }

int func1(int a){ return a*2; }
int func2(int a){ return a*2; }

void main()
{
    auto a = S!func1();
    auto b = S!func2();

    a = b; // Error message is understandable

    auto c = S!((int a) => a*2)();
    auto d = S!((int a) => a*2)();

    c = d; // Error message says a thing != to a same thing
}
```

Error messages formatted below for readability:
```
test.d(12): Error: cannot implicitly convert expression b of type
    S!(func2)
to
    S!(func1)

test.d(17): Error: cannot implicitly convert expression d of type
    test.S!(function (int a) pure nothrow @nogc @safe => a * 2)
to
    test.S!(function (int a) pure nothrow @nogc @safe => a * 2)
```

As new D programmer, this really threw me off the debugging 
trail. For the second case, had the compiler reported some in the 
order of:
```
test.d(17): Error: cannot implicitly convert expression d of type
    test.S!(__lambda_temp_main_1)
to
    test.S!(__lambda_temp_main_2)
Hint: All lambda function instances have unique auto-generated 
names
```
It would have saved a lot of head scratching.

Oh well, I learned quite a bit from this exchange so that's 
productive.  Thanks all








More information about the Digitalmars-d-learn mailing list