Bug 18263 – selective import with same name masks out this reference in mixin template
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-01-18T12:50:17Z
Last change time
2018-11-06T08:13:42Z
Assigned to
No Owner
Creator
FeepingCreature
Comments
Comment #0 by default_357-line — 2018-01-18T12:50:17Z
The following code fails with an error:
mixin template HappyFunTime()
{
static void foo()
{
import std.meta : Filter;
alias bar = this.bar;
}
}
struct Filter
{
void bar() { }
mixin HappyFunTime;
}
test.d(9): Error: identifier 'bar' of 'Filter.bar' is not defined
What happens is that because both Filter and std.meta.Filter have the same name, the import for std.meta.Filter somehow masks out the struct Filter for the "this" lookup in the alias.
This is horrifying. If this lookup absolutely has to be done by name, it should at least be done by fqn.
Comment #1 by razvan.nitu1305 — 2018-01-19T13:07:37Z
There is no need for the mixin template. Reduced test case:
struct Filter
{
void bar() { }
static void foo()
{
import std.meta : Filter;
alias bar = this.bar;
}
}
Comment #2 by razvan.nitu1305 — 2018-01-19T13:16:49Z
Come to think of it, there should be no this in static context, so if you remove the static keyword from the foo function, the code will compile. In this case, the compiler should error stating that you cannot you this in a static context.
Comment #3 by default_357-line — 2018-01-22T06:52:54Z
Oh, good point - typeof(this).bar fixes the issue.
Comment #4 by razvan.nitu1305 — 2018-11-05T14:36:28Z
Now that using `this` as a type is deprecated, I think that we can close this. What do you think Feep?
Comment #5 by default_357-line — 2018-11-05T19:14:29Z
Good point! I'd prefer to wait until the actual deprecation goes through, but at least there's some hint towards what is happening now.