Skip to content

Commit

Permalink
simplify nested reference checking (#16656)
Browse files Browse the repository at this point in the history
  • Loading branch information
0-v-0 authored Jul 4, 2024
1 parent 18c8d78 commit 8f64141
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 18 deletions.
6 changes: 2 additions & 4 deletions compiler/src/dmd/canthrow.d
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ CT canThrow(Expression e, FuncDeclaration func, ErrorSink eSink)
if (ce.f && ce.arguments.length > 0)
{
Type tb = (*ce.arguments)[0].type.toBasetype();
auto tbNext = tb.nextOf();
if (tbNext)
if (auto tbNext = tb.nextOf())
{
auto ts = tbNext.baseElemOf().isTypeStruct();
if (ts)
if (auto ts = tbNext.baseElemOf().isTypeStruct())
{
auto sd = ts.sym;
const id = ce.f.ident;
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/cppmangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,7 @@ private final class CppMangleVisitor : Visitor
*/
static Dsymbol getInstance(Dsymbol s)
{
Dsymbol p = s.toParent();
if (p)
if (Dsymbol p = s.toParent())
{
if (TemplateInstance ti = p.isTemplateInstance())
return ti;
Expand Down
9 changes: 3 additions & 6 deletions compiler/src/dmd/delegatize.d
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,13 @@ bool lambdaCheckForNestedRef(Expression e, Scope* sc)

override void visit(SymOffExp e)
{
VarDeclaration v = e.var.isVarDeclaration();
if (v)
if (VarDeclaration v = e.var.isVarDeclaration())
result = v.checkNestedReference(sc, Loc.initial);
}

override void visit(VarExp e)
{
VarDeclaration v = e.var.isVarDeclaration();
if (v)
if (VarDeclaration v = e.var.isVarDeclaration())
result = v.checkNestedReference(sc, Loc.initial);
}

Expand All @@ -235,8 +233,7 @@ bool lambdaCheckForNestedRef(Expression e, Scope* sc)

override void visit(DeclarationExp e)
{
VarDeclaration v = e.declaration.isVarDeclaration();
if (v)
if (VarDeclaration v = e.declaration.isVarDeclaration())
{
result = v.checkNestedReference(sc, Loc.initial);
if (result)
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dmd/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -1262,8 +1262,7 @@ extern (C++) class FuncDeclaration : Declaration
{
if (type)
{
TypeFunction fdtype = type.isTypeFunction();
if (fdtype) // Could also be TypeError
if (TypeFunction fdtype = type.isTypeFunction()) // Could also be TypeError
return fdtype.parameterList;
}

Expand Down
3 changes: 1 addition & 2 deletions druntime/src/rt/config.d
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ string rt_envvarsOption(string opt, scope rt_configCallBack dg) @nogc nothrow
var[4 + i] = cast(char) toupper(c);
var[4 + opt.length] = 0;

auto p = getenv(var.ptr);
if (p)
if (auto p = getenv(var.ptr))
{
string s = dg(cast(string) p[0 .. strlen(p)]);
if (s != null)
Expand Down
3 changes: 1 addition & 2 deletions druntime/src/rt/trace.d
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,7 @@ extern(C) void _c_trace_pro(size_t idlen, char* idptr)
extern(C) void _c_trace_epi()
{
//printf("_c_trace_epi()\n");
auto tos = trace_tos;
if (tos)
if (auto tos = trace_tos)
{
timer_t endtime;
QueryPerformanceCounter(&endtime);
Expand Down

0 comments on commit 8f64141

Please sign in to comment.