Skip to content

Commit f9afafc

Browse files
Sidd-Rthewilsonator
authored andcommitted
fixes dlang#21296 , access member function through member AliasSeq
1 parent 0f33b96 commit f9afafc

2 files changed

Lines changed: 58 additions & 4 deletions

File tree

compiler/src/dmd/expressionsem.d

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9901,20 +9901,43 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
99019901
case expression:
99029902
e = cast(Expression)o;
99039903
if (auto se = e.isDsymbolExp())
9904+
{
99049905
var = se.s.isDeclaration();
9906+
if (auto fd = var ? var.isFuncDeclaration() : null)
9907+
{
9908+
if (!fd.needThis())
9909+
var = null;
9910+
}
9911+
}
99059912
else if (auto ve = e.isVarExp())
9906-
if (!ve.var.isFuncDeclaration())
9913+
{
9914+
if (auto fd = ve.var.isFuncDeclaration())
9915+
{
9916+
// Preserve instance context for member functions.
9917+
if (fd.needThis())
9918+
var = fd;
9919+
}
9920+
else
99079921
// Exempt functions for backwards compatibility reasons.
99089922
// See: https://issues.dlang.org/show_bug.cgi?id=20470#c1
99099923
var = ve.var;
9924+
}
99109925
break;
99119926
case dsymbol:
99129927
Dsymbol s = cast(Dsymbol) o;
99139928
Declaration d = s.isDeclaration();
9914-
if (!d || d.isFuncDeclaration())
9915-
// Exempt functions for backwards compatibility reasons.
9916-
// See: https://issues.dlang.org/show_bug.cgi?id=20470#c1
9929+
if (!d)
99179930
e = new DsymbolExp(exp.loc, s);
9931+
else if (auto fd = d.isFuncDeclaration())
9932+
{
9933+
// Preserve instance context for member functions.
9934+
if (fd.needThis())
9935+
var = d;
9936+
else
9937+
// Exempt functions for backwards compatibility reasons.
9938+
// See: https://issues.dlang.org/show_bug.cgi?id=20470#c1
9939+
e = new DsymbolExp(exp.loc, s);
9940+
}
99189941
else
99199942
var = d;
99209943
break;

compiler/test/runnable/test21296.d

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// https://github.com/dlang/dmd/issues/21296
2+
3+
alias Seq(T...) = T;
4+
5+
struct T1
6+
{
7+
int x;
8+
alias y = x;
9+
alias expand = Seq!x;
10+
}
11+
12+
struct T2
13+
{
14+
int _x;
15+
16+
@property int x() { return _x; }
17+
18+
alias y = x;
19+
alias expand = Seq!x;
20+
}
21+
22+
void main()
23+
{
24+
auto t1 = T1(1);
25+
assert(t1.y == 1);
26+
assert(t1.expand[0] == 1);
27+
28+
auto t2 = T2(2);
29+
assert(t2.y == 2);
30+
assert(t2.expand[0] == 2);
31+
}

0 commit comments

Comments
 (0)