[mcs] Better error reporting for wrong unexpected escaped characters. Fixes #27441
authorMarek Safar <marek.safar@gmail.com>
Fri, 27 Feb 2015 15:56:33 +0000 (16:56 +0100)
committerMarek Safar <marek.safar@gmail.com>
Fri, 27 Feb 2015 15:57:35 +0000 (16:57 +0100)
mcs/errors/cs1056-2.cs [new file with mode: 0644]
mcs/errors/cs1056-3.cs [new file with mode: 0644]
mcs/mcs/cs-tokenizer.cs

diff --git a/mcs/errors/cs1056-2.cs b/mcs/errors/cs1056-2.cs
new file mode 100644 (file)
index 0000000..160587d
--- /dev/null
@@ -0,0 +1,6 @@
+// CS1056: Unexpected character `\0001'
+// Line: 4
+
+na\u0001espace Test
+{
+}
\ No newline at end of file
diff --git a/mcs/errors/cs1056-3.cs b/mcs/errors/cs1056-3.cs
new file mode 100644 (file)
index 0000000..0278407
--- /dev/null
@@ -0,0 +1,6 @@
+// CS1056: Unexpected character `\0001'
+// Line: 4
+
+\u0001namespace Test
+{
+}
\ No newline at end of file
index 6f0097e4b2a6dddda69a3441083ce75a1c4dffb2..c36d363da46526fe0db6ab21c94665ef11574be0 100644 (file)
@@ -3153,9 +3153,14 @@ namespace Mono.CSharp
                        if (c == '\\') {
                                int surrogate;
                                c = escape (c, out surrogate);
-                               if (surrogate != 0) {
-                                       id_builder [pos++] = (char) c;
+                               if (quoted || is_identifier_start_character (c)) {
+                                       // it's added bellow
+                               } else if (surrogate != 0) {
+                                       id_builder [pos++] = (char)c;
                                        c = surrogate;
+                               } else {
+                                       Report.Error (1056, Location, "Unexpected character `\\{0}'", c.ToString ("x4"));
+                                       return Token.ERROR;
                                }
                        }
 
@@ -3176,9 +3181,18 @@ namespace Mono.CSharp
                                                        c = escape (c, out surrogate);
                                                        if (is_identifier_part_character ((char) c))
                                                                id_builder[pos++] = (char) c;
-
-                                                       if (surrogate != 0) {
+                                                       else if (surrogate != 0) {
                                                                c = surrogate;
+                                                       } else {
+                                                               switch (c) {
+                                                               // TODO: Probably need more whitespace characters
+                                                               case 0xFEFF:
+                                                                       putback_char = c;
+                                                                       break;
+                                                               default:
+                                                                       Report.Error (1056, Location, "Unexpected character `\\{0}'", c.ToString ("x4"));
+                                                                       return Token.ERROR;
+                                                               }
                                                        }
 
                                                        continue;