Skip to content

Commit cd09566

Browse files
committed
Implement with(auto x = ...)
1 parent dd83410 commit cd09566

File tree

5 files changed

+12
-3
lines changed

5 files changed

+12
-3
lines changed

compiler/src/dmd/astbase.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,7 @@ struct ASTBase
23212321

23222322
extern (C++) final class WithStatement : Statement
23232323
{
2324+
Parameter prm;
23242325
Expression exp;
23252326
Statement _body;
23262327
Loc endloc;

compiler/src/dmd/frontend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5372,6 +5372,7 @@ class WhileStatement final : public Statement
53725372
class WithStatement final : public Statement
53735373
{
53745374
public:
5375+
Parameter* prm;
53755376
Expression* exp;
53765377
Statement* _body;
53775378
VarDeclaration* wthis;

compiler/src/dmd/parse.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6661,7 +6661,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
66616661
exp = parseExpression();
66626662
closeCondition("with", null, exp);
66636663
_body = parseStatement(ParseStatementFlags.scope_, null, &endloc);
6664-
s = new AST.WithStatement(loc, exp, _body, endloc);
6664+
s = new AST.WithStatement(loc, null, exp, _body, endloc);
66656665
break;
66666666
}
66676667
case TOK.try_:

compiler/src/dmd/statement.d

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,22 +1416,28 @@ extern (C++) final class SynchronizedStatement : Statement
14161416
*/
14171417
extern (C++) final class WithStatement : Statement
14181418
{
1419+
Parameter prm;
14191420
Expression exp;
14201421
Statement _body;
14211422
VarDeclaration wthis;
14221423
Loc endloc;
14231424

1424-
extern (D) this(Loc loc, Expression exp, Statement _body, Loc endloc) @safe
1425+
extern (D) this(Loc loc, Parameter prm, Expression exp, Statement _body, Loc endloc) @safe
14251426
{
14261427
super(loc, STMT.With);
1428+
this.prm = prm;
14271429
this.exp = exp;
14281430
this._body = _body;
14291431
this.endloc = endloc;
14301432
}
14311433

14321434
override WithStatement syntaxCopy()
14331435
{
1434-
return new WithStatement(loc, exp.syntaxCopy(), _body ? _body.syntaxCopy() : null, endloc);
1436+
return new WithStatement(loc,
1437+
prm ? prm.syntaxCopy() : null,
1438+
exp.syntaxCopy(),
1439+
_body ? _body.syntaxCopy() : null,
1440+
endloc);
14351441
}
14361442

14371443
override void accept(Visitor v)

compiler/src/dmd/statement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ class SynchronizedStatement final : public Statement
561561
class WithStatement final : public Statement
562562
{
563563
public:
564+
Parameter *prm;
564565
Expression *exp;
565566
Statement *_body;
566567
VarDeclaration *wthis;

0 commit comments

Comments
 (0)