Skip to content

Commit

Permalink
hasIdentityOpAssign reduce indentation (#16927)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilsonator authored Oct 4, 2024
1 parent 21cc69c commit fecc140
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions compiler/src/dmd/clone.d
Original file line number Diff line number Diff line change
Expand Up @@ -101,46 +101,45 @@ StorageClass mergeFuncAttrs(StorageClass s1, const FuncDeclaration f) pure @safe
*/
FuncDeclaration hasIdentityOpAssign(AggregateDeclaration ad, Scope* sc)
{
if (Dsymbol assign = search_function(ad, Id.assign))
{
/* check identity opAssign exists
*/
scope er = new NullExp(ad.loc, ad.type); // dummy rvalue
scope el = new IdentifierExp(ad.loc, Id.p); // dummy lvalue
el.type = ad.type;
const errors = global.startGagging(); // Do not report errors, even if the template opAssign fbody makes it.
sc = sc.push();
sc.tinst = null;
sc.minst = null;
Dsymbol assign = search_function(ad, Id.assign);
if (!assign)
return null;

auto a = new Expressions(1);
(*a)[0] = er;
auto f = resolveFuncCall(ad.loc, sc, assign, null, ad.type, ArgumentList(a), FuncResolveFlag.quiet);
if (!f)
{
(*a)[0] = el;
f = resolveFuncCall(ad.loc, sc, assign, null, ad.type, ArgumentList(a), FuncResolveFlag.quiet);
}
/* check identity opAssign exists
*/
scope er = new NullExp(ad.loc, ad.type); // dummy rvalue
scope el = new IdentifierExp(ad.loc, Id.p); // dummy lvalue
el.type = ad.type;
const errors = global.startGagging(); // Do not report errors, even if the template opAssign fbody makes it.
sc = sc.push();
sc.tinst = null;
sc.minst = null;

sc = sc.pop();
global.endGagging(errors);
if (f)
{
if (f.errors)
return null;
auto fparams = f.getParameterList();
if (fparams.length)
{
auto fparam0 = fparams[0];
if (fparam0.type.toDsymbol(null) != ad)
f = null;
}
}
// BUGS: This detection mechanism cannot find some opAssign-s like follows:
// struct S { void opAssign(ref immutable S) const; }
return f;
auto a = new Expressions(1);
(*a)[0] = er;
auto f = resolveFuncCall(ad.loc, sc, assign, null, ad.type, ArgumentList(a), FuncResolveFlag.quiet);
if (!f)
{
(*a)[0] = el;
f = resolveFuncCall(ad.loc, sc, assign, null, ad.type, ArgumentList(a), FuncResolveFlag.quiet);
}
return null;

sc = sc.pop();
global.endGagging(errors);
if (!f)
return null;
if (f.errors)
return null;
auto fparams = f.getParameterList();
if (fparams.length)
{
auto fparam0 = fparams[0];
if (fparam0.type.toDsymbol(null) != ad)
f = null;
}
// BUGS: This detection mechanism cannot find some opAssign-s like follows:
// struct S { void opAssign(ref immutable S) const; }
return f;
}

/*******************************************
Expand Down

0 comments on commit fecc140

Please sign in to comment.