@@ -1861,21 +1861,16 @@ $(GRAMMAR
18611861$(GNAME WithStatement):
18621862 $(D with) $(D $(LPAREN)) $(EXPRESSION) $(D $(RPAREN)) $(PSSCOPE)
18631863 $(D with) $(D $(LPAREN)) $(GLINK2 template, Symbol) $(D $(RPAREN)) $(PSSCOPE)
1864- $(D with) $(D $(LPAREN)) $(GLINK2 template, TemplateInstance) $(D $(RPAREN)) $(PSSCOPE)
18651864)
18661865
1867- where *Expression* evaluates to one of:
1866+ $(P *Expression* must be a
1867+ $(DDSUBLINK spec/type, user-defined-types, user-defined type) instance,
1868+ or a pointer to a user-defined type instance.)
18681869
1869- $(UL
1870- $(LI a class reference)
1871- $(LI a struct instance)
1872- $(LI an enum instance)
1873- $(LI a pointer to one of the above)
1874- )
1875-
1876- Within the with body the referenced object is searched first for
1877- identifier symbols.
1870+ $(P Within the *ScopeStatement* the referenced expression/symbol is searched first for
1871+ identifier symbols.)
18781872
1873+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
18791874---
18801875enum E { A, B }
18811876
@@ -1891,11 +1886,12 @@ void test(E e)
18911886 }
18921887}
18931888---
1889+ )
18941890
1895- $(P Below, if `ident` is a member of the type of `expression `, the $(I WithStatement):)
1891+ $(P Below, if `ident` is a member of the type of `expr `, the $(I WithStatement):)
18961892
18971893---
1898- with (expression )
1894+ with (expr )
18991895{
19001896 ...
19011897 ident;
@@ -1905,20 +1901,19 @@ with (expression)
19051901 is semantically equivalent to:
19061902
19071903--------------
1908- (auto ref tmp)
19091904{
1905+ auto ref tmp = expr;
19101906 ...
19111907 tmp.ident;
1912- }(expression);
1908+ }
19131909--------------
19141910
19151911 $(P Note that *Expression* only gets evaluated once and is not copied.
1916- The with statement does not change what $(D this) or
1912+ The ` with` statement does not change what $(D this) or
19171913 $(D super) refer to.
19181914 )
19191915
1920- $(P For $(I Symbol) which is a scope or $(I TemplateInstance),
1921- the corresponding scope is searched when looking up symbols.
1916+ $(P For a $(I Symbol) argument, the corresponding scope is searched when looking up symbols.
19221917 For example:
19231918 )
19241919
@@ -1937,9 +1932,11 @@ with (Foo)
19371932
19381933 $(P Use of `with` object symbols that shadow local symbols with
19391934 the same identifier are not allowed.
1940- This is to reduce the risk of inadvertent breakage of with
1935+ This is to reduce the risk of inadvertent breakage of ` with`
19411936 statements when new members are added to the object declaration.
19421937 )
1938+
1939+ $(SPEC_RUNNABLE_EXAMPLE_FAIL
19431940---
19441941struct S
19451942{
@@ -1956,7 +1953,7 @@ void main()
19561953 }
19571954}
19581955---
1959-
1956+ )
19601957 $(P In nested $(I WithStatement)s, the inner-most scope takes precedence. If
19611958 a symbol cannot be resolved at the inner-most scope, resolution is forwarded
19621959 incrementally up the scope hierarchy.)
0 commit comments