Skip to content

Commit

Permalink
[expressionsem.d] use early returns
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilsonator committed Oct 5, 2024
1 parent 50d84e3 commit d3c1d8f
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -4132,18 +4132,18 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return setError();
}
cd = s.isClassDeclaration();
if (cd)
if (!cd)
continue;

cd = cd.baseClass;
if (!cd)
{
cd = cd.baseClass;
if (!cd)
{
error(e.loc, "class `%s` has no `super`", s.toChars());
return setError();
}
e.type = cd.type;
result = e;
return;
error(e.loc, "class `%s` has no `super`", s.toChars());
return setError();
}
e.type = cd.type;
result = e;
return;
}
}
if (!fd)
Expand Down Expand Up @@ -7424,39 +7424,37 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
//printf("targ = %s, %s\n", e.targ.toChars(), e.targ.deco);
//printf("tspec = %s, %s\n", e.tspec.toChars(), e.tspec.deco);

if (e.tok == TOK.colon)
if (e.tok != TOK.colon) /* == */
{
// current scope is itself deprecated, or deprecations are not errors
const bool deprecationAllowed = sc.isDeprecated
|| global.params.useDeprecated != DiagnosticReporting.error;
const bool preventAliasThis = e.targ.hasDeprecatedAliasThis && !deprecationAllowed;
if (e.targ.equals(e.tspec))
return yes();
else
return no();
}

if (preventAliasThis && e.targ.ty == Tstruct)
{
if ((cast(TypeStruct) e.targ).implicitConvToWithoutAliasThis(e.tspec))
return yes();
else
return no();
}
else if (preventAliasThis && e.targ.ty == Tclass)
{
if ((cast(TypeClass) e.targ).implicitConvToWithoutAliasThis(e.tspec))
return yes();
else
return no();
}
else if (e.targ.implicitConvTo(e.tspec))
// current scope is itself deprecated, or deprecations are not errors
const bool deprecationAllowed = sc.isDeprecated
|| global.params.useDeprecated != DiagnosticReporting.error;
const bool preventAliasThis = e.targ.hasDeprecatedAliasThis && !deprecationAllowed;

if (preventAliasThis && e.targ.ty == Tstruct)
{
if ((cast(TypeStruct) e.targ).implicitConvToWithoutAliasThis(e.tspec))
return yes();
else
return no();
}
else /* == */
else if (preventAliasThis && e.targ.ty == Tclass)
{
if (e.targ.equals(e.tspec))
if ((cast(TypeClass) e.targ).implicitConvToWithoutAliasThis(e.tspec))
return yes();
else
return no();
}
else if (e.targ.implicitConvTo(e.tspec))
return yes();
else
return no();
}
else if (e.tspec)
{
Expand Down

0 comments on commit d3c1d8f

Please sign in to comment.