Skip to content

add with compound statement #4163

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 18 additions & 9 deletions spec/statement.dd
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ else
//writeln(m.pre); // Error: undefined identifier 'm'
---
)
)

$(H2 $(LEGACY_LNAME2 WhileStatement, while-statement, While Statement))

Expand Down Expand Up @@ -1762,12 +1761,18 @@ object.)

$(GRAMMAR
$(GNAME WithStatement):
$(D with) $(D $(LPAREN)) $(EXPRESSION) $(D $(RPAREN)) $(PSSCOPE)
$(D with) $(D $(LPAREN)) $(GLINK2 template, Symbol) $(D $(RPAREN)) $(PSSCOPE)
$(D with) $(D $(LPAREN)) $(GLINK2 template, TemplateInstance) $(D $(RPAREN)) $(PSSCOPE)
$(GLINK WithClause) $(PSSCOPE)
$(GLINK WithClause) : $(GLINK StatementList)

$(GNAME WithClause):
$(D with) $(D $(LPAREN)) $(EXPRESSION) $(D $(RPAREN))
$(D with) $(D $(LPAREN)) $(GLINK2 template, Symbol) $(D $(RPAREN))
$(D with) $(D $(LPAREN)) $(GLINK2 template, TemplateInstance) $(D $(RPAREN))
)

where *Expression* evaluates to one of:
$(P The *StatementList* form is equivalent to the *ScopeStatement* form.)

$(P *Expression* evaluates to one of:)

$(UL
$(LI a class reference)
Expand All @@ -1776,8 +1781,8 @@ $(GNAME WithStatement):
$(LI a pointer to one of the above)
)

Within the with body the referenced object is searched first for
identifier symbols.
Within the `with` $(I ScopeStatement) or $(I StatementList) the referenced object is
searched first for identifier symbols.

---
enum E { A, B }
Expand Down Expand Up @@ -1815,8 +1820,8 @@ with (expression)
}(expression);
--------------

$(P Note that *Expression* only gets evaluated once and is not copied.
The with statement does not change what $(D this) or
$(NOTE *Expression* only gets evaluated once and is not copied.
The *WithStatement* does not change what $(D this) or
$(D super) refer to.
)

Expand Down Expand Up @@ -1923,6 +1928,10 @@ void main()
// not implemented in `main`'s scope, so resolution is
// subsequently forward to module scope.
}

with(foo): // StatementList form
f(); // prints "Foo.f"
f(); // prints "Foo.f"
}
---
)
Expand Down