<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 2 Oct 2024 at 20:06, kdevel via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wednesday, 2 October 2024 at 08:55:15 UTC, Manu wrote:<br>
> Does anyone understand why this doesn't work?<br>
><br>
> void f(T)(const(T)[] x, const(T)* y) {}<br>
> void test()<br>
> {<br>
> int*[] x;<br>
> const int* y;<br>
> f(x, &y);<br>
> }<br>
><br>
> error : template `f` is not callable using argument types <br>
> `!()(int*[],<br>
> const(int*)*)`<br>
> Candidate is: `f(T)(const(T)[] x, const(T)* y)`<br>
><br>
> Should this work? It looks like it should work to me.<br>
> ...assuming T is inferred to be `int*`... which it's not clear <br>
> why it<br>
> wouldn't be?<br>
><br>
> The argument `y` is an exact match.<br>
<br>
The second actual parameter to f!int is &y not y.<br></blockquote><div><br></div><div>Yes, the `y` argument is `const(int*)*`, so `T` must be inferred `int*`<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> The argument `x` requires a const promotion,<br>
<br>
The type of x is int*[] and not const(int) [];</blockquote><div><br></div><div>Right, `x` is `int*[]`, and matching the argument `const(T)[]` required const promotion `int*[]` -> `const(int*)[]`, which is a perfectly normal promotion. In which case, `T` is `int*`, matching with `y`, and so `T` can be properly inferred.<br></div><div><br></div><div>If you remove the `*` from `x` and `y`, the `T` inference works properly... so something about `T` being inferred as `int*` rather than an `int` causes the type inference to fail.</div><div>The non-uniformity looks like a bug, unless there's a reasonable explanation that I've missed.<br></div></div></div>