template instance does not match template declaration

kdevel kdevel at vogtner.de
Fri Feb 25 23:34:59 UTC 2022


On Friday, 25 February 2022 at 23:17:14 UTC, Paul Backus wrote:
[...]
> Currently, selective imports are implemented using `alias`es 
> under the hood, which means that the compiler sees your `model` 
> module as having *two* overloads of `read`:
>
> ```d
> alias read = std.file.read; // from selective import
>
> int read (string filename)
> {
>     // etc.
> }
> ```
>
> When you pass an overload set to a template that isn't written 
> to handle multiple overloads, it will usually just choose 
> whichever overload comes first in the source code. And since 
> the `public import` statement comes earlier in your source file 
> than the definition of `read`, the `std.file.read` alias is the 
> one that gets chosen when you write `Parameters!read`.

What about this:

```d
module model; // model.d
import std.file : read; // this line provokes the error

private int read (string filename) // now it's private
{
    import std.file;
    auto data = std.file.read (filename);
    return 0;
}
```

Now dmd reports:
```
main.d(7): Error: undefined identifier `read`
```

Is the lookup and the processing done in different parts/stages 
of the compiler?


More information about the Digitalmars-d-learn mailing list