Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[expressionsem.d] use early returns #16933

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 30 additions & 32 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -4127,18 +4127,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
Loading