@@ -37,7 +37,7 @@ The *embedded_statement* nonterminal is used for statements that appear within o
37
37
38
38
> * Example* : The code
39
39
>
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"]} -->
41
41
> ``` csharp
42
42
> void F (bool b )
43
43
> {
@@ -60,7 +60,7 @@ If a statement can possibly be reached by execution, the statement is said to be
60
60
61
61
> *Example *: In the following code
62
62
>
63
- > < ! -- IncompleteExample : {template : " standalone-console" , name : " Reachability1" , expectedWarnings : [" CS0162 " ," CS8321 " ]} -- >
63
+ > < ! -- Example : {template : " standalone-console" , name : " Reachability1" , expectedWarnings : [" CS8321 " ," CS0162 " ]} -- >
64
64
> ```csharp
65
65
> void F ()
66
66
> {
@@ -82,7 +82,7 @@ A warning is reported if a statement other than *throw_statement*, *block*, or *
82
82
>
83
83
> In the example
84
84
>
85
- > <!-- IncompleteExample : {template:"standalone-console", name:"Reachability2", expectedWarnings:["CS0162 ","CS8321 "]} -- >
85
+ > <!-- Example : {template:"standalone-console", name:"Reachability2", expectedWarnings:["CS8321 ","CS0162 "]} -- >
86
86
> ```csharp
87
87
> void F ()
88
88
> {
@@ -94,7 +94,7 @@ A warning is reported if a statement other than *throw_statement*, *block*, or *
94
94
>
95
95
> 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
96
96
>
97
- > <!-- IncompleteExample : {template : " standalone-console" , name : " Reachability3" , expectedWarnings : [" CS8321" ]} -- >
97
+ > <!-- Example : {template : " standalone-console" , name : " Reachability3" , expectedWarnings : [" CS8321" ]} -- >
98
98
> ```csharp
99
99
> void F ()
100
100
> {
@@ -112,7 +112,7 @@ The *block* of a function member or an anonymous function is always considered r
112
112
113
113
> * Example * : In the following code
114
114
>
115
- > < ! -- IncompleteExample : {template : " standalone-console" , name : " Reachability4" , expectedWarnings : [" CS8321" ]} -- >
115
+ > < ! -- Example : {template : " standalone-console" , name : " Reachability4" , expectedWarnings : [" CS8321" ]} -- >
116
116
> ```csharp
117
117
> void F (int x )
118
118
> {
@@ -203,7 +203,7 @@ Execution of an empty statement simply transfers control to the end point of the
203
203
204
204
> * Example* : An empty statement can be used when writing a ` while ` statement with a null body:
205
205
>
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" ]} -->
207
207
> ``` csharp
208
208
> bool ProcessMessage () {.. .}
209
209
> void ProcessMessages ()
@@ -215,7 +215,7 @@ Execution of an empty statement simply transfers control to the end point of the
215
215
>
216
216
> Also , an empty statement can be used to declare a label just before the closing “`}`” of a block :
217
217
>
218
- > < ! -- Example : {template : " standalone-console" , name : " EmptyStatement2" , replaceEllipsis : true , expectedWarnings : [" CS8321" ]} -- >
218
+ > < ! -- Example : {template : " standalone-console-without-using " , name : " EmptyStatement2" , replaceEllipsis : true , expectedWarnings : [" CS8321" ]} -- >
219
219
> ```csharp
220
220
> void F (bool done )
221
221
> {
@@ -252,7 +252,7 @@ Labels have their own declaration space and do not interfere with other identifi
252
252
253
253
> * Example* : The example
254
254
>
255
- > <!-- Example: {template:"standalone-console", name:"LabeledStatements", expectedWarnings:["CS8321"]} -->
255
+ > <!-- Example: {template:"standalone-console-without-using ", name:"LabeledStatements", expectedWarnings:["CS8321"]} -->
256
256
> ``` csharp
257
257
> int F (int x )
258
258
> {
@@ -335,7 +335,7 @@ In the context of a local variable declaration, the identifier `var` acts as a c
335
335
336
336
> * Example* : The following are incorrect implicitly typed local variable declarations:
337
337
>
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"]} -->
339
339
> ``` csharp
340
340
> var x ; // Error, no initializer to infer type from
341
341
> 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
354
354
355
355
> *Example *: The example
356
356
>
357
- > < ! -- Example : {template : " standalone-console" , name : " LocalVariableDecls2" , ignoredWarnings : [" CS0168" ," CS8321" ]} -- >
357
+ > < ! -- Example : {template : " standalone-console-without-using " , name : " LocalVariableDecls2" , ignoredWarnings : [" CS0168" ," CS8321" ]} -- >
358
358
> ```csharp
359
359
> void F ()
360
360
> {
@@ -364,7 +364,7 @@ A local variable declaration that declares multiple variables is equivalent to m
364
364
>
365
365
> corresponds exactly to
366
366
>
367
- > < ! -- Example : {template : " standalone-console" , name : " LocalVariableDecls3" , ignoredWarnings : [" CS0168" ," CS8321" ]} -- >
367
+ > < ! -- Example : {template : " standalone-console-without-using " , name : " LocalVariableDecls3" , ignoredWarnings : [" CS0168" ," CS8321" ]} -- >
368
368
> ```csharp
369
369
> void F ()
370
370
> {
@@ -380,7 +380,7 @@ In an implicitly typed local variable declaration, the type of the local variabl
380
380
381
381
> *Example *:
382
382
>
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" ]} -- >
384
384
> ```csharp
385
385
> var i = 5 ;
386
386
> var s = " Hello" ;
@@ -391,7 +391,7 @@ In an implicitly typed local variable declaration, the type of the local variabl
391
391
>
392
392
> The implicitly typed local variable declarations above are precisely equivalent to the following explicitly typed declarations :
393
393
>
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" ]} -- >
395
395
> ```csharp
396
396
> int i = 5 ;
397
397
> string s = " Hello" ;
@@ -459,7 +459,7 @@ Grammar note: When recognising a *local_function_body* if both the *null_conditi
459
459
460
460
> * 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:
461
461
>
462
- > <!-- IncompleteExample : {template:"standalone-console ", name:"LocalFunctionDeclarations1", expectedWarnings:["xx","xx"] } -->
462
+ > <!-- Example : {template:"code-in-class-lib ", name:"LocalFunctionDeclarations1"} -->
463
463
> ``` csharp
464
464
> public static IEnumerable < char > AlphabetSubset (char start , char end )
465
465
> {
@@ -505,7 +505,7 @@ Local function bodies are always reachable. The endpoint of a local function dec
505
505
506
506
> *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 ` isn ’t reachable , the statement following the endpoint of `L ` is not reachable :
507
507
>
508
- > < ! -- IncompleteExample : {template : " standalone-console " , name : " LocalFunctionDeclarations2" , expectedWarnings : [" xx " , " xx " ]} -- >
508
+ > < ! -- Example : {template : " standalone-lib-without-using " , name : " LocalFunctionDeclarations2" , expectedWarnings : [" CS0162 " ]} -- >
509
509
> ```csharp
510
510
> class C
511
511
> {
@@ -583,14 +583,16 @@ An `else` part is associated with the lexically nearest preceding `if` that is a
583
583
584
584
> * Example* : Thus, an ` if ` statement of the form
585
585
>
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. -->
587
588
> ``` csharp
588
589
> if (x ) if (y ) F (); else G ();
589
590
> ```
590
591
>
591
592
> is equivalent to
592
593
>
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. -->
594
596
> ```csharp
595
597
> if (x)
596
598
> {
@@ -666,7 +668,8 @@ If the end point of the statement list of a switch section is reachable, a compi
666
668
667
669
> * Example* : The example
668
670
>
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. -->
670
673
> ``` csharp
671
674
> switch (i )
672
675
> {
@@ -684,7 +687,8 @@ If the end point of the statement list of a switch section is reachable, a compi
684
687
>
685
688
> 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
686
689
>
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. -->
688
692
> ```csharp
689
693
> switch (i)
690
694
> {
@@ -699,7 +703,8 @@ If the end point of the statement list of a switch section is reachable, a compi
699
703
>
700
704
> 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:
701
705
>
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. -->
703
708
> ```csharp
704
709
> switch (i)
705
710
> {
@@ -721,7 +726,8 @@ Multiple labels are permitted in a *switch_section*.
721
726
722
727
> * Example * : The example
723
728
>
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. -->
725
731
> ```csharp
726
732
> switch (i)
727
733
> {
@@ -746,7 +752,8 @@ Multiple labels are permitted in a *switch_section*.
746
752
< ! -- markdownlint - enable MD028 -- >
747
753
> * Note * : The “no fall through ” rule 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:
748
754
>
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 . -->
750
757
> ```csharp
751
758
> switch (i )
752
759
> {
@@ -768,7 +775,8 @@ Multiple labels are permitted in a *switch_section*.
768
775
< ! -- markdownlint - enable MD028 -- >
769
776
> * 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:
770
777
>
771
- > <!-- IncompleteExample: {template :" standalone-console" , name :" SwitchStatement6" } -- >
778
+ > <!-- Incomplete$Example: {template :" standalone-console" , name :" SwitchStatement6" } -- >
779
+ > < ! -- FIX : needs defs for i, F. -->
772
780
> ```csharp
773
781
> switch (i)
774
782
> {
@@ -790,7 +798,8 @@ Multiple labels are permitted in a *switch_section*.
790
798
< ! -- markdownlint - enable MD028 -- >
791
799
> * Example * : The governing type of a `switch ` statement can be the type `string`. For example:
792
800
>
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. -->
794
803
> ```csharp
795
804
> void DoCommand(string command )
796
805
> {
@@ -1020,7 +1029,7 @@ The placement of `v` inside the `while` loop is important for how it is captured
1020
1029
1021
1030
> * Example* :
1022
1031
>
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 "]} -->
1024
1033
> ``` csharp
1025
1034
> int [] values = { 7 , 9 , 13 };
1026
1035
> Action f = null ;
@@ -1091,7 +1100,6 @@ The order in which `foreach` traverses the elements of an array, is as follows:
1091
1100
>
1092
1101
> <!-- Example: {template:"standalone-console", name:"ForeachStatement2", replaceEllipsis:true, inferOutput:true} -->
1093
1102
> ``` csharp
1094
- > using System ;
1095
1103
> class Test
1096
1104
> {
1097
1105
> static void Main ()
@@ -1127,7 +1135,7 @@ The order in which `foreach` traverses the elements of an array, is as follows:
1127
1135
> int [] numbers = { 1 , 3 , 5 , 7 , 9 };
1128
1136
> foreach (var n in numbers )
1129
1137
> {
1130
- > System . Console .WriteLine (n );
1138
+ > Console .WriteLine (n );
1131
1139
> }
1132
1140
> ```
1133
1141
>
@@ -1161,7 +1169,6 @@ Execution of jump statements is complicated by the presence of intervening `try`
1161
1169
>
1162
1170
> <!-- Example: {template:"standalone-console", name:"JumpStatements", inferOutput:true} -->
1163
1171
> ``` csharp
1164
- > using System ;
1165
1172
> class Test
1166
1173
> {
1167
1174
> static void Main ()
@@ -1266,8 +1273,6 @@ The target of a `goto` *identifier* statement is the labeled statement with the
1266
1273
>
1267
1274
> <!-- Example: {template : " standalone-console" , name : " GotoStatement" } -- >
1268
1275
> ```csharp
1269
- > using System ;
1270
- >
1271
1276
> class Test
1272
1277
> {
1273
1278
> static void Main (string [] args )
@@ -1431,8 +1436,6 @@ Within a `catch` block, a `throw` statement ([§12.10.6](statements.md#12106-the
1431
1436
>
1432
1437
> <!-- Example: {template : " standalone-console" , name : " TryStatement1" , inferOutput : true } -- >
1433
1438
> ```csharp
1434
- > using System ;
1435
- >
1436
1439
> class Test
1437
1440
> {
1438
1441
> static void F ()
@@ -1501,8 +1504,6 @@ If an exception is thrown during execution of a `finally` block, and is not caug
1501
1504
>
1502
1505
> < ! -- Example : {template : " standalone-console" , name : " TryStatement2" , inferOutput : true } -- >
1503
1506
> ```csharp
1504
- > using System ;
1505
- >
1506
1507
> public class Test
1507
1508
> {
1508
1509
> static void Main ()
@@ -1731,11 +1732,8 @@ using (ResourceType rN = eN)
1731
1732
1732
1733
> * 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.
1733
1734
>
1734
- > <!-- IncompleteExample : {template:"standalone-console", name:"UsingStatement", expectedErrors:["x","x"], expectedWarnings:["x","x"] } -->
1735
+ > <!-- Example : {template:"standalone-console", name:"UsingStatement"} -->
1735
1736
> ``` csharp
1736
- > using System ;
1737
- > using System .IO ;
1738
- >
1739
1737
> class Test
1740
1738
> {
1741
1739
> static void Main ()
@@ -1783,7 +1781,7 @@ There are several restrictions on where a `yield` statement can appear, as descr
1783
1781
1784
1782
> * Example* : The following example shows some valid and invalid uses of ` yield ` statements.
1785
1783
>
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 "]} -->
1787
1785
> ``` csharp
1788
1786
> delegate IEnumerable <int > D ();
1789
1787
>
0 commit comments