Skip to content

Commit

Permalink
Merge pull request #8711 from RazvanN7/Issue_19251
Browse files Browse the repository at this point in the history
Fix Issue 19251 - Alias this does not get called on struct qualified type
  • Loading branch information
andralex committed Oct 1, 2018
2 parents 99b0a31 + 37605ec commit 94f3998
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/dmd/expressionsem.d
Expand Up @@ -7845,6 +7845,24 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
e2x = valueNoDtor(e2x);
}
}

// https://issues.dlang.org/show_bug.cgi?id=19251
// if e2 cannot be converted to e1.type, maybe there is an alias this
if (!e2x.implicitConvTo(t1))
{
AggregateDeclaration ad2 = isAggregate(e2x.type);
if (ad2 && ad2.aliasthis && !(exp.att2 && e2x.type == exp.att2))
{
if (!exp.att2 && exp.e2.type.checkAliasThisRec())
exp.att2 = exp.e2.type;
/* Rewrite (e1 op e2) as:
* (e1 op e2.aliasthis)
*/
exp.e2 = new DotIdExp(exp.e2.loc, exp.e2, ad2.aliasthis.ident);
result = exp.expressionSemantic(sc);
return;
}
}
}
else if (!e2x.implicitConvTo(t1))
{
Expand Down
20 changes: 20 additions & 0 deletions test/runnable/test19251.d
@@ -0,0 +1,20 @@
string result;

struct A
{
int[] a;
immutable(A) fun()
{
result ~= "Yo";
return immutable A([7]);
}

alias fun this;
}

void main()
{
A a;
immutable A b = a; // error: cannot implicitly convert expression a of type A to immutable(A)
assert(result == "Yo");
}

0 comments on commit 94f3998

Please sign in to comment.