Skip to content

Commit 8db316d

Browse files
authored
revise example metadata (#712)
1 parent 017a1b7 commit 8db316d

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

standard/statements.md

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The *embedded_statement* nonterminal is used for statements that appear within o
3737

3838
> *Example*: The code
3939
>
40-
> <!-- Example: {template:"standalone-console", name:"Statements", expectedErrors:["CS1023"], ignoredWarnings:["CS8321","CS0219"]} -->
40+
> <!-- Example: {template:"standalone-console-without-using", name:"Statements", expectedErrors:["CS1023"], ignoredWarnings:["CS8321","CS0219"]} -->
4141
> ```csharp
4242
> void F(bool b)
4343
> {
@@ -60,7 +60,7 @@ If a statement can possibly be reached by execution, the statement is said to be
6060
6161
> *Example*: In the following code
6262
>
63-
> <!-- IncompleteExample: {template:"standalone-console", name:"Reachability1", expectedWarnings:["CS0162","CS8321"]} -->
63+
> <!-- Example: {template:"standalone-console", name:"Reachability1", expectedWarnings:["CS8321","CS0162"]} -->
6464
> ```csharp
6565
> void F()
6666
> {
@@ -82,7 +82,7 @@ A warning is reported if a statement other than *throw_statement*, *block*, or *
8282
>
8383
> In the example
8484
>
85-
> <!-- IncompleteExample: {template:"standalone-console", name:"Reachability2", expectedWarnings:["CS0162","CS8321"]} -->
85+
> <!-- Example: {template:"standalone-console", name:"Reachability2", expectedWarnings:["CS8321","CS0162"]} -->
8686
> ```csharp
8787
> void F()
8888
> {
@@ -94,7 +94,7 @@ A warning is reported if a statement other than *throw_statement*, *block*, or *
9494
>
9595
> the Boolean expression of the `if` statement is a constant expression because both operands of the `==operator are constants. As the constant expression is evaluated at compile-time, producing the value `false`, the `Console.WriteLine` invocation is considered unreachable. However, if `i` is changed to be a local variable
9696
>
97-
> <!-- IncompleteExample: {template:"standalone-console", name:"Reachability3", expectedWarnings:["CS8321"]} -->
97+
> <!-- Example: {template:"standalone-console", name:"Reachability3", expectedWarnings:["CS8321"]} -->
9898
> ```csharp
9999
> void F()
100100
> {
@@ -112,7 +112,7 @@ The *block* of a function member or an anonymous function is always considered r
112112
113113
> *Example*: In the following code
114114
>
115-
> <!-- IncompleteExample: {template:"standalone-console", name:"Reachability4", expectedWarnings:["CS8321"]} -->
115+
> <!-- Example: {template:"standalone-console", name:"Reachability4", expectedWarnings:["CS8321"]} -->
116116
> ```csharp
117117
> void F(int x)
118118
> {
@@ -203,7 +203,7 @@ Execution of an empty statement simply transfers control to the end point of the
203203

204204
> *Example*: An empty statement can be used when writing a `while` statement with a null body:
205205
>
206-
> <!-- IncompleteExample: {template:"standalone-console", name:"EmptyStatement1", replaceEllipsis:true, expectedWarnings:["CS8321]} -->
206+
> <!-- Example: {template:"standalone-console-without-using", name:"EmptyStatement1", replaceEllipsis:true, customEllipsisReplacements: ["return true;"], expectedWarnings:["CS8321"]} -->
207207
> ```csharp
208208
> bool ProcessMessage() {...}
209209
> void ProcessMessages()
@@ -215,7 +215,7 @@ Execution of an empty statement simply transfers control to the end point of the
215215
>
216216
> Also, an empty statement can be used to declare a label just before the closing “`}`” of a block:
217217
>
218-
> <!-- Example: {template:"standalone-console", name:"EmptyStatement2", replaceEllipsis:true, expectedWarnings:["CS8321"]} -->
218+
> <!-- Example: {template:"standalone-console-without-using", name:"EmptyStatement2", replaceEllipsis:true, expectedWarnings:["CS8321"]} -->
219219
> ```csharp
220220
> void F(bool done)
221221
> {
@@ -252,7 +252,7 @@ Labels have their own declaration space and do not interfere with other identifi
252252

253253
> *Example*: The example
254254
>
255-
> <!-- Example: {template:"standalone-console", name:"LabeledStatements", expectedWarnings:["CS8321"]} -->
255+
> <!-- Example: {template:"standalone-console-without-using", name:"LabeledStatements", expectedWarnings:["CS8321"]} -->
256256
> ```csharp
257257
> int F(int x)
258258
> {
@@ -335,7 +335,7 @@ In the context of a local variable declaration, the identifier `var` acts as a c
335335

336336
> *Example*: The following are incorrect implicitly typed local variable declarations:
337337
>
338-
> <!-- Example: {template:"standalone-console", name:"LocalVariableDecls1", expectedErrors:["CS0818","CS0820","CS0815","CS8917","CS0841"], ignoredWarnings:["CS0168"]} -->
338+
> <!-- Example: {template:"standalone-console-without-using", name:"LocalVariableDecls1", expectedErrors:["CS0818","CS0820","CS0815","CS8917","CS0841"], ignoredWarnings:["CS0168"]} -->
339339
> ```csharp
340340
> var x; // Error, no initializer to infer type from
341341
> var y = {1, 2, 3}; // Error, array initializer not permitted
@@ -354,7 +354,7 @@ A local variable declaration that declares multiple variables is equivalent to m
354354
355355
> *Example*: The example
356356
>
357-
> <!-- Example: {template:"standalone-console", name:"LocalVariableDecls2", ignoredWarnings:["CS0168","CS8321"]} -->
357+
> <!-- Example: {template:"standalone-console-without-using", name:"LocalVariableDecls2", ignoredWarnings:["CS0168","CS8321"]} -->
358358
> ```csharp
359359
> void F()
360360
> {
@@ -364,7 +364,7 @@ A local variable declaration that declares multiple variables is equivalent to m
364364
>
365365
> corresponds exactly to
366366
>
367-
> <!-- Example: {template:"standalone-console", name:"LocalVariableDecls3", ignoredWarnings:["CS0168","CS8321"]} -->
367+
> <!-- Example: {template:"standalone-console-without-using", name:"LocalVariableDecls3", ignoredWarnings:["CS0168","CS8321"]} -->
368368
> ```csharp
369369
> void F()
370370
> {
@@ -380,7 +380,7 @@ In an implicitly typed local variable declaration, the type of the local variabl
380380
381381
> *Example*:
382382
>
383-
> <!-- IncompleteExample: {template:"standalone-console", name:"LocalVariableDecls4", expectedWarnings:["CS0219","CS0219","CS0219"]} -->
383+
> <!-- Example: {template:"code-in-main", name:"LocalVariableDecls4", additionalFiles:["Order.cs"], expectedWarnings:["CS0219","CS0219","CS0219"]} -->
384384
> ```csharp
385385
> var i = 5;
386386
> var s = "Hello";
@@ -391,7 +391,7 @@ In an implicitly typed local variable declaration, the type of the local variabl
391391
>
392392
> The implicitly typed local variable declarations above are precisely equivalent to the following explicitly typed declarations:
393393
>
394-
> <!-- IncompleteExample: {template:"standalone-console", name:"LocalVariableDecls5", expectedWarnings:["CS0219","CS0219","CS0219"]} -->
394+
> <!-- Example: {template:"code-in-main", name:"LocalVariableDecls5", additionalFiles:["Order.cs"], expectedWarnings:["CS0219","CS0219","CS0219"]} -->
395395
> ```csharp
396396
> int i = 5;
397397
> string s = "Hello";
@@ -459,7 +459,7 @@ Grammar note: When recognising a *local_function_body* if both the *null_conditi
459459

460460
> *Example*: There are two common use cases for local functions: iterator methods and async methods. In iterator methods, any exceptions are observed only when calling code that enumerates the returned sequence. In async methods, any exceptions are only observed when the returned Task is awaited. The following example demonstrates separating parameter validation from the iterator implementation using a local function:
461461
>
462-
> <!-- IncompleteExample: {template:"standalone-console", name:"LocalFunctionDeclarations1", expectedWarnings:["xx","xx"]} -->
462+
> <!-- Example: {template:"code-in-class-lib", name:"LocalFunctionDeclarations1"} -->
463463
> ```csharp
464464
> public static IEnumerable<char> AlphabetSubset(char start, char end)
465465
> {
@@ -505,7 +505,7 @@ Local function bodies are always reachable. The endpoint of a local function dec
505505
506506
> *Example*: In the following example, the body of `L` is reachable even though the beginning point of `L` is not reachable. Because the beginning point of `L` isnt reachable, the statement following the endpoint of `L` is not reachable:
507507
>
508-
> <!-- IncompleteExample: {template:"standalone-console", name:"LocalFunctionDeclarations2", expectedWarnings:["xx","xx"]} -->
508+
> <!-- Example: {template:"standalone-lib-without-using", name:"LocalFunctionDeclarations2", expectedWarnings:["CS0162"]} -->
509509
> ```csharp
510510
> class C
511511
> {
@@ -583,14 +583,16 @@ An `else` part is associated with the lexically nearest preceding `if` that is a
583583

584584
> *Example*: Thus, an `if` statement of the form
585585
>
586-
> <!-- IncompleteExample: {template:"standalone-console", name:"IfStatement1", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
586+
> <!-- Incomplete$Example: {template:"standalone-console", name:"IfStatement1", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
587+
> <!-- FIX: needs defs for x, y, F and G. -->
587588
> ```csharp
588589
> if (x) if (y) F(); else G();
589590
> ```
590591
>
591592
> is equivalent to
592593
>
593-
> <!-- IncompleteExample: {template:"standalone-console", name:"IfStatement2", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
594+
> <!-- Incomplete$Example: {template:"standalone-console", name:"IfStatement2", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
595+
> <!-- FIX: needs defs for x, y, F and G. -->
594596
> ```csharp
595597
> if (x)
596598
> {
@@ -666,7 +668,8 @@ If the end point of the statement list of a switch section is reachable, a compi
666668

667669
> *Example*: The example
668670
>
669-
> <!-- IncompleteExample: {template:"standalone-console", name:"SwitchStatement1", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
671+
> <!-- Incomplete$Example: {template:"standalone-console", name:"SwitchStatement1", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
672+
> <!-- FIX: needs defs for i, CaseZero, CaseOne, and CaseOthers. -->
670673
> ```csharp
671674
> switch (i)
672675
> {
@@ -684,7 +687,8 @@ If the end point of the statement list of a switch section is reachable, a compi
684687
>
685688
> is valid because no switch section has a reachable end point. Unlike C and C++, execution of a switch section is not permitted to “fall through” to the next switch section, and the example
686689
>
687-
> <!-- IncompleteExample: {template:"standalone-console", name:"SwitchStatement2", expectedErrors:["CS0163","CS0163","CS8070"]} -->
690+
> <!-- Incomplete$Example: {template:"standalone-console", name:"SwitchStatement2", expectedErrors:["CS0163","CS0163","CS8070"]} -->
691+
> <!-- FIX: needs defs for i, CaseZero, CaseZeroOrOne, and CaseAny. -->
688692
> ```csharp
689693
> switch (i)
690694
> {
@@ -699,7 +703,8 @@ If the end point of the statement list of a switch section is reachable, a compi
699703
>
700704
> results in a compile-time error. When execution of a switch section is to be followed by execution of another switch section, an explicit `goto case` or `goto default` statement shall be used:
701705
>
702-
> <!-- IncompleteExample: {template:"standalone-console", name:"SwitchStatement3"} -->
706+
> <!-- Incomplete$Example: {template:"standalone-console", name:"SwitchStatement3"} -->
707+
> <!-- FIX: needs defs for i, CaseZero, CaseZeroOrOne, and CaseAny. -->
703708
> ```csharp
704709
> switch (i)
705710
> {
@@ -721,7 +726,8 @@ Multiple labels are permitted in a *switch_section*.
721726
722727
> *Example*: The example
723728
>
724-
> <!-- IncompleteExample: {template:"standalone-console", name:"SwitchStatement4"} -->
729+
> <!-- Incomplete$Example: {template:"standalone-console", name:"SwitchStatement4"} -->
730+
> <!-- FIX: needs defs for i, CaseZero, CaseOne, and CaseTwo. -->
725731
> ```csharp
726732
> switch (i)
727733
> {
@@ -746,7 +752,8 @@ Multiple labels are permitted in a *switch_section*.
746752
<!-- markdownlint-enable MD028 -->
747753
> *Note*: Theno fall throughrule prevents a common class of bugs that occur in C and C++ when `break` statements are accidentally omitted. For example, the sections of the `switch` statement above can be reversed without affecting the behavior of the statement:
748754
>
749-
> <!-- IncompleteExample: {template:"standalone-console", name:"SwitchStatement5"]} -->
755+
> <!-- Incomplete$Example: {template:"standalone-console", name:"SwitchStatement5"]} -->
756+
> <!-- FIX: needs defs for i, CaseZero, CaseZeroOrOne, and CaseAny. -->
750757
> ```csharp
751758
> switch (i)
752759
> {
@@ -768,7 +775,8 @@ Multiple labels are permitted in a *switch_section*.
768775
<!-- markdownlint-enable MD028 -->
769776
> *Note*: The statement list of a switch section typically ends in a `break`, `goto case`, or `goto default` statement, but any construct that renders the end point of the statement list unreachable is permitted. For example, a `while` statement controlled by the Boolean expression `true` is known to never reach its end point. Likewise, a `throw` or `return` statement always transfers control elsewhere and never reaches its end point. Thus, the following example is valid:
770777
>
771-
> <!-- IncompleteExample: {template:"standalone-console", name:"SwitchStatement6"} -->
778+
> <!-- Incomplete$Example: {template:"standalone-console", name:"SwitchStatement6"} -->
779+
> <!-- FIX: needs defs for i, F. -->
772780
> ```csharp
773781
> switch (i)
774782
> {
@@ -790,7 +798,8 @@ Multiple labels are permitted in a *switch_section*.
790798
<!-- markdownlint-enable MD028 -->
791799
> *Example*: The governing type of a `switch` statement can be the type `string`. For example:
792800
>
793-
> <!-- IncompleteExample: {template:"standalone-console", name:"SwitchStatement7", expectedWarnings:["CS8321"]} -->
801+
> <!-- Incomplete$Example: {template:"standalone-console", name:"SwitchStatement7", expectedWarnings:["CS8321"]} -->
802+
> <!-- FIX: top-level must be a console, but then it has no named parent class type, so can't implement Do* as extension methods. -->
794803
> ```csharp
795804
> void DoCommand(string command)
796805
> {
@@ -1020,7 +1029,7 @@ The placement of `v` inside the `while` loop is important for how it is captured
10201029

10211030
> *Example*:
10221031
>
1023-
> <!-- IncompleteExample: {template:"standalone-console", name:"ForeachStatement1", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
1032+
> <!-- Example: {template:"code-in-main", name:"ForeachStatement1", expectedOutput:["First value: 7"]} -->
10241033
> ```csharp
10251034
> int[] values = { 7, 9, 13 };
10261035
> Action f = null;
@@ -1091,7 +1100,6 @@ The order in which `foreach` traverses the elements of an array, is as follows:
10911100
>
10921101
> <!-- Example: {template:"standalone-console", name:"ForeachStatement2", replaceEllipsis:true, inferOutput:true} -->
10931102
> ```csharp
1094-
> using System;
10951103
> class Test
10961104
> {
10971105
> static void Main()
@@ -1127,7 +1135,7 @@ The order in which `foreach` traverses the elements of an array, is as follows:
11271135
> int[] numbers = { 1, 3, 5, 7, 9 };
11281136
> foreach (var n in numbers)
11291137
> {
1130-
> System.Console.WriteLine(n);
1138+
> Console.WriteLine(n);
11311139
> }
11321140
> ```
11331141
>
@@ -1161,7 +1169,6 @@ Execution of jump statements is complicated by the presence of intervening `try`
11611169
>
11621170
> <!-- Example: {template:"standalone-console", name:"JumpStatements", inferOutput:true} -->
11631171
> ```csharp
1164-
> using System;
11651172
> class Test
11661173
> {
11671174
> static void Main()
@@ -1266,8 +1273,6 @@ The target of a `goto` *identifier* statement is the labeled statement with the
12661273
>
12671274
> <!-- Example: {template:"standalone-console", name:"GotoStatement"} -->
12681275
> ```csharp
1269-
> using System;
1270-
>
12711276
> class Test
12721277
> {
12731278
> static void Main(string[] args)
@@ -1431,8 +1436,6 @@ Within a `catch` block, a `throw` statement ([§12.10.6](statements.md#12106-the
14311436
>
14321437
> <!-- Example: {template:"standalone-console", name:"TryStatement1", inferOutput:true} -->
14331438
> ```csharp
1434-
> using System;
1435-
>
14361439
> class Test
14371440
> {
14381441
> static void F()
@@ -1501,8 +1504,6 @@ If an exception is thrown during execution of a `finally` block, and is not caug
15011504
>
15021505
> <!-- Example: {template:"standalone-console", name:"TryStatement2", inferOutput:true} -->
15031506
> ```csharp
1504-
> using System;
1505-
>
15061507
> public class Test
15071508
> {
15081509
> static void Main()
@@ -1731,11 +1732,8 @@ using (ResourceType rN = eN)
17311732

17321733
> *Example*: The example below creates a file named log.txt and writes two lines of text to the file. The example then opens that same file for reading and copies the contained lines of text to the console.
17331734
>
1734-
> <!-- IncompleteExample: {template:"standalone-console", name:"UsingStatement", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
1735+
> <!-- Example: {template:"standalone-console", name:"UsingStatement"} -->
17351736
> ```csharp
1736-
> using System;
1737-
> using System.IO;
1738-
>
17391737
> class Test
17401738
> {
17411739
> static void Main()
@@ -1783,7 +1781,7 @@ There are several restrictions on where a `yield` statement can appear, as descr
17831781

17841782
> *Example*: The following example shows some valid and invalid uses of `yield` statements.
17851783
>
1786-
> <!-- IncompleteExample: {template:"standalone-console", name:"YieldStatement", expectedErrors:["x","x"], expectedWarnings:["x","x"]} -->
1784+
> <!-- Example: {template:"code-in-class-lib-without-using", name:"YieldStatement", expectedErrors:["CS1625","CS1625","CS1626","CS1631","CS1643","CS1621","CS1624"], expectedWarnings:["CS0162"]} -->
17871785
> ```csharp
17881786
> delegate IEnumerable<int> D();
17891787
>

0 commit comments

Comments
 (0)