Skip to content

Commit 298072f

Browse files
committed
Found a few more files searching
In step 3, use the source from roslyn to find any additional errors and warnings that haven't been covered.
1 parent 4011e2e commit 298072f

File tree

4 files changed

+185
-11
lines changed

4 files changed

+185
-11
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
Add the contents of cs1027.md to the preprocessor-errors.md file, sort that file by 'source_path_from_root'. Add a redirection for cs1027.md to point to preprocessor-errors.md, add "cs1027: to the list of display names in the TOC for preprocessor-errors.md. Finally, delete cs1027.md
22

3-
Search all files in the docs/csharp/language-reference/compiler-messages folder for any other errors and warnings that involve preprocessor tokens. Give me a list to review for possible additional consolidation
3+
Search all files in the docs/csharp/language-reference/compiler-messages folder for any other errors and warnings that involve preprocessor tokens. Give me a list to review for possible additional consolidation.
4+
5+
To make sure you've found all related errors, we'll check the source. Look in `CSharpResources.resx` for any elements where the `<value>` element is a message related to preprocessor tokens. The symbolic constant for that value is in the `name` attribute on the parent `data` element. Find that value in `ErrorCodes.cs`. It will map to the compiler error code, where the code is "CS" followed by the number as a four digit number. Build a list of any not already added to preprocessor-errors.md
6+

docs/csharp/language-reference/compiler-messages/nullable-warnings.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ helpviewer_keywords:
9898
- "CS8634"
9999
- "CS8636"
100100
- "CS8637"
101+
- "CS8668"
101102
- "CS8639"
102103
- "CS8643"
103104
- "CS8644"
@@ -214,6 +215,7 @@ The following warnings indicate that you haven't set the nullable context correc
214215
- **CS8632** - *The annotation for nullable reference types should only be used in code within a `#nullable` annotations context.*
215216
- **CS8636** - *Invalid option for `/nullable`; must be `disable`, `enable`, `warnings` or `annotations`*
216217
- **CS8637** - *Expected `enable`, `disable`, or `restore`*
218+
- **CS8668** - *Expected `warnings`, `annotations`, or end of directive*
217219

218220
To set the nullable context correctly, you have two options:
219221

docs/csharp/language-reference/compiler-messages/preprocessor-errors.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ f1_keywords:
2424
- "CS1695"
2525
- "CS1696"
2626
- "CS1709"
27+
- "CS7009"
28+
- "CS7010"
29+
- "CS7011"
30+
- "CS8097"
31+
- "CS8098"
32+
- "CS8938"
33+
- "CS8939"
34+
- "CS8996"
35+
- "CS9028"
2736
- "CS9297"
2837
- "CS9298"
2938
- "CS9299"
@@ -51,6 +60,15 @@ helpviewer_keywords:
5160
- "CS1695"
5261
- "CS1696"
5362
- "CS1709"
63+
- "CS7009"
64+
- "CS7010"
65+
- "CS7011"
66+
- "CS8097"
67+
- "CS8098"
68+
- "CS8938"
69+
- "CS8939"
70+
- "CS8996"
71+
- "CS9028"
5472
- "CS9297"
5573
- "CS9298"
5674
- "CS9299"
@@ -83,6 +101,15 @@ The compiler generates the following errors for incorrect use of preprocessor di
83101
- **CS1695**: *Invalid #pragma checksum syntax; should be #pragma checksum "filename" "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" "XXXX..."*
84102
- **CS1696**: *Single-line comment or end-of-line expected*
85103
- **CS1709**: *Filename specified for preprocessor directive is empty*
104+
- **CS7009**: *Cannot use #r after first token in file*
105+
- **CS7010**: *Quoted file name expected*
106+
- **CS7011**: *#r is only allowed in scripts*
107+
- **CS8097**: *#load is only allowed in scripts*
108+
- **CS8098**: *Cannot use #load after first token in file*
109+
- **CS8938**: *The #line directive value is missing or out of range*
110+
- **CS8939**: *The #line directive end position must be greater than or equal to the start position*
111+
- **CS8996**: *Raw string literals are not allowed in preprocessor directives*
112+
- **CS9028**: *The #line span directive requires space before the first parenthesis, before the character offset, and before the file name*
86113
- **CS9297**: *`#:` directives cannot be after first token in file*
87114
- **CS9298**: *`#:`directives can be only used in file-based programs (`-features:FileBasedProgram`)*
88115
- **CS9299**: *`#:` directives cannot be after `#if` directive*
@@ -557,3 +584,155 @@ class Test
557584
}
558585
}
559586
```
587+
588+
## CS7009: Cannot use #r after first token in file
589+
590+
The [`#r` directive](../preprocessor-directives/preprocessor-r.md) can only be used before any tokens appear in a script file. After the first token, it's no longer allowed.
591+
592+
The following example generates CS7009:
593+
594+
```csharp
595+
// CS7009.cs
596+
using System;
597+
#r "System.Collections" // CS7009
598+
```
599+
600+
## CS7010: Quoted file name expected
601+
602+
A filename was expected in a [preprocessor directive](../preprocessor-directives.md), but it was not properly quoted.
603+
604+
The following example generates CS7010:
605+
606+
```csharp
607+
// CS7010.cs
608+
#r System.Collections.dll // CS7010 - missing quotes
609+
```
610+
611+
To fix this error, enclose the filename in quotes:
612+
613+
```csharp
614+
#r "System.Collections.dll" // OK
615+
```
616+
617+
## CS7011: #r is only allowed in scripts
618+
619+
The [`#r` directive](../preprocessor-directives/preprocessor-r.md) can only be used in C# scripts (.csx files), not in regular C# source files.
620+
621+
The following example generates CS7011:
622+
623+
```csharp
624+
// CS7011.cs
625+
class Test
626+
{
627+
static void Main()
628+
{
629+
#r "System.Collections" // CS7011
630+
}
631+
}
632+
```
633+
634+
## CS8097: #load is only allowed in scripts
635+
636+
The [`#load` directive](../preprocessor-directives/preprocessor-load.md) can only be used in C# scripts (.csx files), not in regular C# source files.
637+
638+
The following example generates CS8097:
639+
640+
```csharp
641+
// CS8097.cs
642+
class Test
643+
{
644+
static void Main()
645+
{
646+
#load "helper.csx" // CS8097
647+
}
648+
}
649+
```
650+
651+
## CS8098: Cannot use #load after first token in file
652+
653+
The [`#load` directive](../preprocessor-directives/preprocessor-load.md) can only be used before any tokens appear in a script file. After the first token, it's no longer allowed.
654+
655+
The following example generates CS8098:
656+
657+
```csharp
658+
// CS8098.csx
659+
using System;
660+
#load "helper.csx" // CS8098
661+
```
662+
663+
## CS8938: The #line directive value is missing or out of range
664+
665+
The [`#line` directive](../preprocessor-directives/preprocessor-line.md) requires a valid line number. Line numbers must be between 1 and 16,707,566.
666+
667+
The following example generates CS8938:
668+
669+
```csharp
670+
// CS8938.cs
671+
#line // CS8938 - missing value
672+
#line 0 // CS8938 - out of range
673+
class Test { }
674+
```
675+
676+
To fix this error, provide a valid line number:
677+
678+
```csharp
679+
#line 100 // OK
680+
class Test { }
681+
```
682+
683+
## CS8939: The #line directive end position must be greater than or equal to the start position
684+
685+
When using the [`#line` directive](../preprocessor-directives/preprocessor-line.md) with span syntax, the end position must be greater than or equal to the start position.
686+
687+
The following example generates CS8939:
688+
689+
```csharp
690+
// CS8939.cs
691+
#line (1, 10) - (1, 5) "file.cs" // CS8939 - end column < start column
692+
class Test { }
693+
```
694+
695+
To fix this error, ensure the end position is not before the start position:
696+
697+
```csharp
698+
#line (1, 5) - (1, 10) "file.cs" // OK
699+
class Test { }
700+
```
701+
702+
## CS8996: Raw string literals are not allowed in preprocessor directives
703+
704+
[Raw string literals](../../misc/raw-string-literals.md) cannot be used in [preprocessor directives](../preprocessor-directives.md). Use regular string literals instead.
705+
706+
The following example generates CS8996:
707+
708+
```csharp
709+
// CS8996.cs
710+
#pragma checksum """raw_string""" "{406EA660-64CF-4C82-B6F0-42D48172A799}" "hash" // CS8996
711+
class Test { }
712+
```
713+
714+
To fix this error, use a regular string literal:
715+
716+
```csharp
717+
#pragma checksum "filename.cs" "{406EA660-64CF-4C82-B6F0-42D48172A799}" "hash" // OK
718+
class Test { }
719+
```
720+
721+
## CS9028: The #line span directive requires space before the first parenthesis, before the character offset, and before the file name
722+
723+
The [`#line` directive](../preprocessor-directives/preprocessor-line.md) with span syntax requires proper spacing between its components.
724+
725+
The following example generates CS9028:
726+
727+
```csharp
728+
// CS9028.cs
729+
#line(1, 1) - (1, 10)"file.cs" // CS9028 - missing spaces
730+
class Test { }
731+
```
732+
733+
To fix this error, add the required spaces:
734+
735+
```csharp
736+
#line (1, 1) - (1, 10) "file.cs" // OK
737+
class Test { }
738+
```

docs/csharp/misc/sorry-we-don-t-have-specifics-on-this-csharp-error.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ f1_keywords:
105105
- "CS4036"
106106
- "CS7002"
107107
- "CS7006"
108-
- "CS7009"
109-
- "CS7010"
110-
- "CS7011"
111108
- "CS7012"
112109
- "CS7013"
113110
- "CS7014"
@@ -231,8 +228,6 @@ f1_keywords:
231228
- "CS8094"
232229
- "CS8095"
233230
- "CS8096"
234-
- "CS8097"
235-
- "CS8098"
236231
- "CS8099"
237232
- "CS8100"
238233
- "CS8101"
@@ -378,7 +373,6 @@ f1_keywords:
378373
- "CS8664"
379374
- "CS8665"
380375
- "CS8666"
381-
- "CS8668"
382376
- "CS8669"
383377
- "CS8700"
384378
- "CS8701"
@@ -483,8 +477,6 @@ f1_keywords:
483477
- "CS8934"
484478
- "CS8935"
485479
- "CS8937"
486-
- "CS8938"
487-
- "CS8939"
488480
- "CS8940"
489481
- "CS8941"
490482
- "CS8942"
@@ -513,7 +505,6 @@ f1_keywords:
513505
- "CS8986"
514506
- "CS8987"
515507
- "CS8989"
516-
- "CS8996"
517508
- "CS8997"
518509
- "CS8998"
519510
- "CS8999"
@@ -541,7 +532,6 @@ f1_keywords:
541532
- "CS9025"
542533
- "CS9026"
543534
- "CS9027"
544-
- "CS9028"
545535
- "CS9029"
546536
- "CS9030"
547537
- "CS9031"

0 commit comments

Comments
 (0)