std.functional.compose compilation error

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 25 11:17:30 PDT 2016


On Thursday, August 25, 2016 17:50:44 bachmeier via Digitalmars-d-learn wrote:
> On Thursday, 25 August 2016 at 17:49:26 UTC, bachmeier wrote:
> > On Thursday, 25 August 2016 at 15:04:43 UTC, Jonathan M Davis
> >
> > wrote:
> >> Yes. Because the module is compose, within that file, compose
> >> will refer to the module, not anything you import. The
> >> selective import essentially creates a local alias like
> >>
> >> alias compose = std.functional.compose;
> >>
> >> as part of the import, so then within that scope, compose
> >> refers to that alias and not to the module. You'll run into
> >> the same problem any time that you give a module the same name
> >> as a symbol that you're importing.
> >>
> >> - Jonathan M Davis
> >
> > Is there a reason there is not a warning for this when
> > compiling? I think it explains a problem I had some time ago
> > that cost me a lot of time.
>
> I mean there should be a better message.

If you have a suggestion for a better message, then feel free to open a bug
report for it - https://issues.dlang.org - or even create a pull request to
fix it if you're feeling ambitious. But shadowing like this is a normal part
of the module system. You'd get the same problem if your module was named
something else, and you declared a function named compose in your module and
then tried to use the compose from std.functional without fully qualifying
it. It can certainly be annoying if you don't realize that that's what's
happening, but how is the compiler going to know that what you meant to use
the version of compose from another module rather than the one in the
current module? All it knows is that you're using it wrong.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list