Skip to content

Commit d08523d

Browse files
committed
Merge pull request #5252 from 9rnsr/fix4350
Issue 4350 - (mixin) mixed in template identifier is not accessible by "with" statement
2 parents c8da977 + a746233 commit d08523d

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

src/expression.d

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,19 +3556,12 @@ public:
35563556
}
35573557
}
35583558
s = s.toAlias();
3559+
35593560
// Same as wthis.ident
3560-
if (s.needThis() || s.isTemplateDeclaration())
3561-
{
3562-
e = new VarExp(loc, withsym.withstate.wthis);
3563-
e = new DotIdExp(loc, e, ident);
3564-
}
3565-
else
3566-
{
3567-
Type t = withsym.withstate.wthis.type;
3568-
if (t.ty == Tpointer)
3569-
t = (cast(TypePointer)t).next;
3570-
e = typeDotIdExp(loc, t, ident);
3571-
}
3561+
// TODO: DotIdExp.semantic will find 'ident' from 'wthis' again.
3562+
// The redudancy should be removed.
3563+
e = new VarExp(loc, withsym.withstate.wthis);
3564+
e = new DotIdExp(loc, e, ident);
35723565
e = e.semantic(sc);
35733566
}
35743567
else

test/runnable/testrightthis.d

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,41 @@ void test7()
467467
static assert(!__traits(compiles, S7.bar(1)));
468468
}
469469

470+
/********************************************************/
471+
// 4350
472+
473+
template Mix4350() { int b; }
474+
475+
struct S4350
476+
{
477+
int a;
478+
479+
mixin Mix4350 mix;
480+
481+
int c;
482+
template Func() { void call(int n) { c = n; } }
483+
alias func = Func!();
484+
}
485+
486+
void test4350()
487+
{
488+
S4350 s;
489+
490+
s.a = 1;
491+
s.mix.b = 2;
492+
s.func.call(3);
493+
assert(s.a == 1);
494+
assert(s.b == 2);
495+
assert(s.c == 3);
496+
497+
with (s) { a = 2; }
498+
with (s) { mix.b = 3; }
499+
with (s) { func.call(4); }
500+
assert(s.a == 2);
501+
assert(s.b == 3);
502+
assert(s.c == 4);
503+
}
504+
470505
/********************************************************/
471506
// 6430
472507

@@ -604,6 +639,7 @@ int main()
604639
test5();
605640
test6();
606641
test7();
642+
test4350();
607643
test9619();
608644
test9633();
609645

0 commit comments

Comments
 (0)