From 90a4f3b2d8739ab960f039fdf9b3a61ce0c35b42 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 12:02:13 -0700 Subject: [PATCH 01/45] Improve lexing recovery in string literals. --- .../CSharp/Portable/CSharpResources.resx | 5 +- .../CSharp/Portable/Errors/ErrorCode.cs | 2 + src/Compilers/CSharp/Portable/Parser/Lexer.cs | 4 +- .../Portable/Parser/Lexer_StringLiteral.cs | 100 ++++------ .../Portable/xlf/CSharpResources.cs.xlf | 5 + .../Portable/xlf/CSharpResources.de.xlf | 5 + .../Portable/xlf/CSharpResources.es.xlf | 5 + .../Portable/xlf/CSharpResources.fr.xlf | 5 + .../Portable/xlf/CSharpResources.it.xlf | 5 + .../Portable/xlf/CSharpResources.ja.xlf | 5 + .../Portable/xlf/CSharpResources.ko.xlf | 5 + .../Portable/xlf/CSharpResources.pl.xlf | 5 + .../Portable/xlf/CSharpResources.pt-BR.xlf | 5 + .../Portable/xlf/CSharpResources.ru.xlf | 5 + .../Portable/xlf/CSharpResources.tr.xlf | 5 + .../Portable/xlf/CSharpResources.zh-Hans.xlf | 5 + .../Portable/xlf/CSharpResources.zh-Hant.xlf | 5 + .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 188 ++++++++++++++++++ 18 files changed, 306 insertions(+), 58 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 57ee5dcdd6b51..0d045035bf442 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6794,4 +6794,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ At least one top-level statement must be non-empty. - + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 1f2cd0819c3e0..4488962884ea4 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1982,6 +1982,8 @@ internal enum ErrorCode ERR_FileScopedNamespaceNotBeforeAllMembers = 8956, ERR_NoImplicitConvTargetTypedConditional = 8957, + ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9000, + #endregion // Note: you will need to re-generate compiler code after adding warnings (eng\generate-compiler-code.cmd) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer.cs b/src/Compilers/CSharp/Portable/Parser/Lexer.cs index 353f8ffda388b..0f9c353d6841c 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer.cs @@ -764,7 +764,9 @@ private void ScanSyntaxToken(ref TokenInfo info) case '@': if (TextWindow.PeekChar(1) == '"') { - this.ScanVerbatimStringLiteral(ref info); + var errorCode = this.ScanVerbatimStringLiteral(ref info, allowNewlines: true); + if (errorCode != null) + this.AddError(errorCode.Value); } else if (TextWindow.PeekChar(1) == '$' && TextWindow.PeekChar(2) == '"') { diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index e7a04e322aaae..da0aba0a3f8fe 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -152,71 +152,55 @@ private char ScanEscapeSequence(out char surrogateCharacter) return ch; } - private void ScanVerbatimStringLiteral(ref TokenInfo info, bool allowNewlines = true) + private ErrorCode? ScanVerbatimStringLiteral(ref TokenInfo info, bool allowNewlines) { _builder.Length = 0; - if (TextWindow.PeekChar() == '@' && TextWindow.PeekChar(1) == '"') + Debug.Assert(TextWindow.PeekChar() == '@' && TextWindow.PeekChar(1) == '"'); + TextWindow.AdvanceChar(2); + + ErrorCode? error = null; + while (true) { - TextWindow.AdvanceChar(2); - bool done = false; - char ch; - _builder.Length = 0; - while (!done) + var ch = TextWindow.PeekChar(); + if (ch == '"') { - switch (ch = TextWindow.PeekChar()) + TextWindow.AdvanceChar(); + if (TextWindow.PeekChar() == '"') { - case '"': - TextWindow.AdvanceChar(); - if (TextWindow.PeekChar() == '"') - { - // Doubled quote -- skip & put the single quote in the string - TextWindow.AdvanceChar(); - _builder.Append(ch); - } - else - { - done = true; - } + // Doubled quote -- skip & put the single quote in the string and keep goign. + TextWindow.AdvanceChar(); + _builder.Append(ch); + continue; + } - break; + // otherwise, the string is finished. + break; + } - case SlidingTextWindow.InvalidCharacter: - if (!TextWindow.IsReallyAtEnd()) - { - goto default; - } + if (ch == SlidingTextWindow.InvalidCharacter && TextWindow.IsReallyAtEnd()) + { + // Reached the end of the source without finding the end-quote. Give an error back at the + // starting point. And finish lexing this string. + error = ErrorCode.ERR_UnterminatedStringLit; + break; + } - // Reached the end of the source without finding the end-quote. Give - // an error back at the starting point. - this.AddError(ErrorCode.ERR_UnterminatedStringLit); - done = true; - break; + // If we hit a new line when it's not allowed. Give an error at that new line, but keep on consuming + // the verbatim literal to the end to avoid the contents of the string being lexed as C# (which will + // cause a ton of cascaded errors). Only need to do this on the first newline we hit. + if (!allowNewlines && SyntaxFacts.IsNewLine(ch) && error == null) + error = ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string; - default: - if (!allowNewlines && SyntaxFacts.IsNewLine(ch)) - { - this.AddError(ErrorCode.ERR_UnterminatedStringLit); - done = true; - break; - } + TextWindow.AdvanceChar(); + _builder.Append(ch); + } - TextWindow.AdvanceChar(); - _builder.Append(ch); - break; - } - } + info.Kind = SyntaxKind.StringLiteralToken; + info.Text = TextWindow.GetText(false); + info.StringValue = _builder.ToString(); - info.Kind = SyntaxKind.StringLiteralToken; - info.Text = TextWindow.GetText(false); - info.StringValue = _builder.ToString(); - } - else - { - info.Kind = SyntaxKind.None; - info.Text = null; - info.StringValue = null; - } + return error; } private void ScanInterpolatedStringLiteral(bool isVerbatim, ref TokenInfo info) @@ -608,7 +592,11 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool if (_lexer.TextWindow.PeekChar(1) == '"' && !RecoveringFromRunawayLexing()) { // check for verbatim string inside an expression hole. - ScanInterpolatedStringLiteralNestedVerbatimString(); + var nestedStringPosition = _lexer.TextWindow.Position; + var errorCode = ScanInterpolatedStringLiteralNestedVerbatimString(); + if (error == null && errorCode != null) + error = _lexer.MakeError(nestedStringPosition, width: 2, errorCode.Value); + continue; } else if (_lexer.TextWindow.PeekChar(1) == '$' && _lexer.TextWindow.PeekChar(2) == '"') @@ -722,10 +710,10 @@ private void ScanInterpolatedStringLiteralNestedString() _lexer.ScanStringLiteral(ref discarded, inDirective: false); } - private void ScanInterpolatedStringLiteralNestedVerbatimString() + private ErrorCode? ScanInterpolatedStringLiteralNestedVerbatimString() { var discarded = default(TokenInfo); - _lexer.ScanVerbatimStringLiteral(ref discarded, _allowNewlines); + return _lexer.ScanVerbatimStringLiteral(ref discarded, _allowNewlines); } private void ScanInterpolatedStringLiteralHoleBracketed(char start, char end) diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index db9953e8c1368..c12618bff33b5 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -782,6 +782,11 @@ Inicializační metoda modulu {0} musí být statická, nesmí mít žádné parametry a musí vracet void. + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). Ve stejném adresáři nemůže být více konfiguračních souborů analyzátoru ({0}). diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 6b5183033719a..cf2f496f7db3b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -782,6 +782,11 @@ Die Modulinitialisierermethode "{0}" muss statisch sein, darf keine Parameter enthalten und muss "void" zurückgeben. + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). Dasselbe Verzeichnis ({0}) darf nicht mehrere Konfigurationsdateien des Analysetools enthalten. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index ae379d82d027c..17053a00c1711 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -782,6 +782,11 @@ El método inicializador de módulos "{0}" debe ser estático, no debe tener parámetros y debe devolver "void". + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). No es posible que un mismo directorio ("{0}") contenga varios archivos de configuración del analizador. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 0902afbdecc4e..7104363a3eabf 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -782,6 +782,11 @@ La méthode d'initialiseur de module '{0}' doit être statique, ne doit avoir aucun paramètre et doit retourner 'void' + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). Plusieurs fichiers config d'analyseur ne peuvent pas figurer dans le même répertoire ('{0}'). diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index f6f6a2c275125..1c5ba91a132dd 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -782,6 +782,11 @@ Il metodo '{0}' dell'inizializzatore di modulo deve essere statico, non deve contenere parametri e deve restituire 'void' + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). La stessa directory ('{0}') non può contenere più file di configurazione dell'analizzatore. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 24513988bed2d..a03217367159b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -782,6 +782,11 @@ モジュール初期化子メソッド '{0}' は、static でなければならず、パラメーターを持ってはならず、'void' を返す必要があります + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). 複数のアナライザー構成ファイルを同じディレクトリに入れることはできません ('{0}')。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 383578020f22d..c135a8aa2707e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -782,6 +782,11 @@ 모듈 이니셜라이저 메서드 '{0}'은(는) 정적이어야 하고, 매개 변수가 없어야 하며, 'void'를 반환해야 합니다. + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). 분석기 구성 파일 여러 개가 동일한 디렉터리('{0}')에 있을 수 없습니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index a8419c5408640..e42a0422bd5d1 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -782,6 +782,11 @@ Metoda inicjatora modułu „{0}” musi być statyczna, nie może mieć parametrów i musi zwracać typ „void” + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). Wiele plików konfiguracji analizatora nie może znajdować się w tym samym katalogu („{0}”). diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 5f3d624430949..2d269cfceff82 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -782,6 +782,11 @@ O método inicializador do módulo '{0}' precisa ser estático, não pode ter parâmetros e precisa retornar 'void' + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). Não é possível que haja vários arquivos de configuração do analisador no mesmo diretório ('{0}'). diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 17a1d9447d017..37036f9116592 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -782,6 +782,11 @@ Метод инициализатора модуля "{0}" должен быть статическим, не должен иметь параметров и должен возвращать "void". + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). В одном каталоге ("{0}") не может находиться несколько файлов конфигурации анализатора. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 3278de9351c0f..d77d17b9d01bb 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -782,6 +782,11 @@ '{0}' modül başlatıcısı metodu statik olmalıdır, hiç parametresi olmamalıdır ve 'void' döndürmelidir + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). Birden çok çözümleyici yapılandırma dosyası aynı dizinde ('{0}') olamaz. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index a1020fb90f0e7..a9ae8895a6540 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -782,6 +782,11 @@ 模块初始值设定项方法“{0}”必须是静态的,不能有任何参数,并且必须返回 "void" + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). 多个分析器配置文件不能位于同一目录({0})中。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 74453fec95229..615076f82c3a8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -782,6 +782,11 @@ 模組初始設定式方法 '{0}' 必須是靜態,不得具有任何參數,而且必須傳回 'void' + + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiple analyzer config files cannot be in the same directory ('{0}'). 多個分析器組態檔無法處於相同目錄 ('{0}') 中。 diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 0c4526205d828..6da29185f1d5b 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -447,6 +447,194 @@ public static int Main() Diagnostic(ErrorCode.ERR_UnexpectedCharacter, "").WithArguments(@"\u0303")); } + [Fact] + public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string1() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { @"" "" } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string2() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { @"" "" + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string3() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { @"" + "" } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test, + // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + // string s = $"x { @" + Diagnostic(ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + } + + [Fact] + public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string4() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { @"" + "" + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string5() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { + @"" "" } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string6() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { + @"" + "" } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string7() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { + @"" + "" + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string8() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { @"" + + "" } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test, + // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + // string s = $"x { @" + Diagnostic(ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + } + + [Fact] + public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string9() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { @"" + + "" } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test, + // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + // string s = $"x { @" + Diagnostic(ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + } + + [Fact] + public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string10() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { $@"" { @"" + + "" } "" } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test, + // (6,30): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + // string s = $"x { $@" { @" + Diagnostic(ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 30)); + } + #endregion #region "Targeted Warning Tests - please arrange tests in the order of error code" From 944eff36edcebb25d127a70203d73493574c7d34 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 12:19:39 -0700 Subject: [PATCH 02/45] add tests --- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 118 +++++++++++++++++- 1 file changed, 113 insertions(+), 5 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 6da29185f1d5b..297a7f297a553 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -477,7 +477,25 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. + // string s = $"x { @" " + Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), + // (6,28): error CS1002: ; expected + // string s = $"x { @" " + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(6, 28), + // (7,26): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration + // } y"; + Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(7, 26), + // (7,26): error CS1010: Newline in constant + // } y"; + Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(7, 26), + // (7,26): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration + // } y"; + Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(7, 26), + // (9,1): error CS1022: Type or namespace definition, or end-of-file expected + // } + Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(9, 1)); } [Fact] @@ -515,7 +533,25 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + // string s = $"x { @" + Diagnostic(ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24), + // (7,27): error CS1002: ; expected + // " + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(7, 27), + // (8,26): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration + // } y"; + Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(8, 26), + // (8,26): error CS1010: Newline in constant + // } y"; + Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(8, 26), + // (8,26): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration + // } y"; + Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(8, 26), + // (10,1): error CS1022: Type or namespace definition, or end-of-file expected + // } + Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(10, 1)); } [Fact] @@ -532,7 +568,31 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. + // string s = $"x { + Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), + // (6,23): error CS1733: Expected expression + // string s = $"x { + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), + // (6,23): error CS1002: ; expected + // string s = $"x { + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(6, 23), + // (7,30): error CS1002: ; expected + // @" " } y"; + Diagnostic(ErrorCode.ERR_SemicolonExpected, "}").WithLocation(7, 30), + // (7,33): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration + // @" " } y"; + Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(7, 33), + // (7,33): error CS1010: Newline in constant + // @" " } y"; + Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(7, 33), + // (7,33): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration + // @" " } y"; + Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(7, 33), + // (9,1): error CS1022: Type or namespace definition, or end-of-file expected + // } + Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(9, 1)); } [Fact] @@ -550,7 +610,31 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. + // string s = $"x { + Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), + // (6,23): error CS1733: Expected expression + // string s = $"x { + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), + // (6,23): error CS1002: ; expected + // string s = $"x { + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(6, 23), + // (8,28): error CS1002: ; expected + // " } y"; + Diagnostic(ErrorCode.ERR_SemicolonExpected, "}").WithLocation(8, 28), + // (8,31): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration + // " } y"; + Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(8, 31), + // (8,31): error CS1010: Newline in constant + // " } y"; + Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(8, 31), + // (8,31): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration + // " } y"; + Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(8, 31), + // (10,1): error CS1022: Type or namespace definition, or end-of-file expected + // } + Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(10, 1)); } [Fact] @@ -569,7 +653,31 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. + // string s = $"x { + Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), + // (6,23): error CS1733: Expected expression + // string s = $"x { + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), + // (6,23): error CS1002: ; expected + // string s = $"x { + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(6, 23), + // (8,27): error CS1002: ; expected + // " + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(8, 27), + // (9,26): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration + // } y"; + Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(9, 26), + // (9,26): error CS1010: Newline in constant + // } y"; + Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(9, 26), + // (9,26): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration + // } y"; + Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(9, 26), + // (11,1): error CS1022: Type or namespace definition, or end-of-file expected + // } + Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(11, 1)); } [Fact] From 4a25d56a49fa0855923e9840c72f74e78e64a108 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 12:35:05 -0700 Subject: [PATCH 03/45] Improved recovery for comments in strings. --- .../CSharp/Portable/Errors/ErrorCode.cs | 1 + .../Portable/Parser/Lexer_StringLiteral.cs | 31 +++-- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 116 ++++++++++++++++++ 3 files changed, 131 insertions(+), 17 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 4488962884ea4..2c9a858543f64 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1983,6 +1983,7 @@ internal enum ErrorCode ERR_NoImplicitConvTargetTypedConditional = 8957, ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9000, + ERR_New_line_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9001, #endregion diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index da0aba0a3f8fe..bb59fad446d58 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -510,7 +510,11 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { while (true) { - if (IsAtEnd()) + var allowNewLines = _isVerbatim && _allowNewlines; + if (!allowNewLines && SyntaxFacts.IsNewLine(_lexer.TextWindow.PeekChar()) && error == null) + error = _lexer.MakeError(_lexer.TextWindow.Position, width: 1, ErrorCode.ERR_New_line_is_not_allowed_inside_a_non_verbatim_interpolated_string); + + if (IsAtEnd(allowNewline: true)) { // the caller will complain return; @@ -626,26 +630,19 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool switch (_lexer.TextWindow.PeekChar(1)) { case '/': - if (_isVerbatim && _allowNewlines) - { - _lexer.TextWindow.AdvanceChar(); // skip / - _lexer.TextWindow.AdvanceChar(); // skip / - while (!IsAtEnd(false)) - { - _lexer.TextWindow.AdvanceChar(); // skip // comment character - } - } - else + if (!_isVerbatim || !_allowNewlines) { - // error: single-line comment not allowed in an interpolated string + // error: single-line comment not allowed in an interpolated string. + // report the error but keep going for good error recovery. if (error == null) - { error = _lexer.MakeError(_lexer.TextWindow.Position, 2, ErrorCode.ERR_SingleLineCommentInExpressionHole); - } - - _lexer.TextWindow.AdvanceChar(); - _lexer.TextWindow.AdvanceChar(); } + + _lexer.TextWindow.AdvanceChar(); // skip / + _lexer.TextWindow.AdvanceChar(); // skip / + while (!IsAtEnd(allowNewline: false)) + _lexer.TextWindow.AdvanceChar(); // skip // comment character + continue; case '*': // check for and scan /* comment */ diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 297a7f297a553..a350ac7e5ad1e 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -743,6 +743,122 @@ public static int Main() Diagnostic(ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 30)); } + [Fact] + public void CS8077ERR_SingleLineCommentInExpressionHole1() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { // comment + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS1733: Expected expression + // string s = $"x { // comment + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), + // (6,24): error CS8077: A single-line comment may not be used in an interpolated string. + // string s = $"x { // comment + Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 24)); + } + + [Fact] + public void CS8077ERR_SingleLineCommentInExpressionHole2() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $@""x { // comment + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test, + // (6,24): error CS1733: Expected expression + // string s = $@"x { // comment + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 24)); + } + + [Fact] + public void CS8077ERR_SingleLineCommentInExpressionHole3() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { $@"" { // comment + } } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + [Fact] + public void CS8077ERR_SingleLineCommentInExpressionHole4() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { // comment + 0 + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test, + // (6,24): error CS8077: A single-line comment may not be used in an interpolated string. + // string s = $"x { // comment + Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 24)); + } + + [Fact] + public void CS8077ERR_SingleLineCommentInExpressionHole5() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $@""x { // comment + 0 + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS8077ERR_SingleLineCommentInExpressionHole6() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { $@"" { // comment + 0 + } } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + #endregion #region "Targeted Warning Tests - please arrange tests in the order of error code" From 1ea60b17937cbb5ff4d08939cdc0ccf1eb6b3bc9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 12:39:57 -0700 Subject: [PATCH 04/45] Add tests --- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index a350ac7e5ad1e..f94de6e9ce778 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -795,12 +795,18 @@ public class Test public static int Main() { string s = $""x { $@"" { // comment - } } y""; + } "" } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,29): error CS1733: Expected expression + // string s = $"x { $@" { // comment + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29), + // (6,30): error CS8077: A single-line comment may not be used in an interpolated string. + // string s = $"x { $@" { // comment + Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 30)); } [Fact] public void CS8077ERR_SingleLineCommentInExpressionHole4() @@ -851,12 +857,15 @@ public static int Main() { string s = $""x { $@"" { // comment 0 - } } y""; + } "" } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,30): error CS8077: A single-line comment may not be used in an interpolated string. + // string s = $"x { $@" { // comment + Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 30)); } #endregion From b1874f7b4d5a6dbf6f5bf0f112c3e9aaf3e0de70 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 12:54:10 -0700 Subject: [PATCH 05/45] Update tests --- .../CSharp/Portable/CSharpResources.resx | 7 +- .../CSharp/Portable/Errors/ErrorCode.cs | 4 +- .../Portable/Parser/Lexer_StringLiteral.cs | 9 +- .../Portable/xlf/CSharpResources.cs.xlf | 11 +- .../Portable/xlf/CSharpResources.de.xlf | 11 +- .../Portable/xlf/CSharpResources.es.xlf | 11 +- .../Portable/xlf/CSharpResources.fr.xlf | 11 +- .../Portable/xlf/CSharpResources.it.xlf | 11 +- .../Portable/xlf/CSharpResources.ja.xlf | 11 +- .../Portable/xlf/CSharpResources.ko.xlf | 11 +- .../Portable/xlf/CSharpResources.pl.xlf | 11 +- .../Portable/xlf/CSharpResources.pt-BR.xlf | 11 +- .../Portable/xlf/CSharpResources.ru.xlf | 11 +- .../Portable/xlf/CSharpResources.tr.xlf | 11 +- .../Portable/xlf/CSharpResources.zh-Hans.xlf | 11 +- .../Portable/xlf/CSharpResources.zh-Hant.xlf | 11 +- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 153 +++++++----------- 17 files changed, 173 insertions(+), 143 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 0d045035bf442..bcb58e387b8a2 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6794,7 +6794,10 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ At least one top-level statement must be non-empty. - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + + + Newline is not allowed inside a non-verbatim interpolated string \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 2c9a858543f64..24e7c7d33954b 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1982,8 +1982,8 @@ internal enum ErrorCode ERR_FileScopedNamespaceNotBeforeAllMembers = 8956, ERR_NoImplicitConvTargetTypedConditional = 8957, - ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9000, - ERR_New_line_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9001, + ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9000, + ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9001, #endregion diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index bb59fad446d58..0a7e016638563 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -190,7 +190,7 @@ private char ScanEscapeSequence(out char surrogateCharacter) // the verbatim literal to the end to avoid the contents of the string being lexed as C# (which will // cause a ton of cascaded errors). Only need to do this on the first newline we hit. if (!allowNewlines && SyntaxFacts.IsNewLine(ch) && error == null) - error = ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string; + error = ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string; TextWindow.AdvanceChar(); _builder.Append(ch); @@ -510,9 +510,11 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { while (true) { + char ch = _lexer.TextWindow.PeekChar(); + var allowNewLines = _isVerbatim && _allowNewlines; - if (!allowNewLines && SyntaxFacts.IsNewLine(_lexer.TextWindow.PeekChar()) && error == null) - error = _lexer.MakeError(_lexer.TextWindow.Position, width: 1, ErrorCode.ERR_New_line_is_not_allowed_inside_a_non_verbatim_interpolated_string); + if (!allowNewLines && SyntaxFacts.IsNewLine(ch) && error == null) + error = _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string); if (IsAtEnd(allowNewline: true)) { @@ -520,7 +522,6 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool return; } - char ch = _lexer.TextWindow.PeekChar(); switch (ch) { case '#': diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index c12618bff33b5..9059ce20e9a2c 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -782,9 +782,9 @@ Inicializační metoda modulu {0} musí být statická, nesmí mít žádné parametry a musí vracet void. - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ Omezení new() nejde používat s omezením unmanaged. + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? {0}: typ použitý v asynchronním příkazu using musí být implicitně převoditelný na System.IAsyncDisposable nebo musí implementovat odpovídající metodu DisposeAsync. Měli jste v úmyslu použít using nebo await using? diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index cf2f496f7db3b..088102cb0aa85 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -782,9 +782,9 @@ Die Modulinitialisierermethode "{0}" muss statisch sein, darf keine Parameter enthalten und muss "void" zurückgeben. - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ Die new()-Einschränkung kann nicht mit der unmanaged-Einschränkung verwendet werden. + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? "{0}": Der in einer asynchronen using-Anweisung verwendete Typ muss implizit in "System.IAsyncDisposable" konvertiert werden können oder eine geeignete DisposeAsync-Methode implementieren. Meinten Sie "using" anstelle von "await using"? diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 17053a00c1711..f29a8f3308c55 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -782,9 +782,9 @@ El método inicializador de módulos "{0}" debe ser estático, no debe tener parámetros y debe devolver "void". - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ La restricción "new()" no se puede utilizar con la restricción "unmanaged" + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? "{0}": el tipo usado en una instrucción using asincrónica debe poder convertirse de forma implícita en "System.IAsyncDisposable" o implementar un método "DisposeAsync" adecuado. ¿Quiso decir "using" en lugar de "await using"? diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 7104363a3eabf..ccd0f367443ef 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -782,9 +782,9 @@ La méthode d'initialiseur de module '{0}' doit être statique, ne doit avoir aucun paramètre et doit retourner 'void' - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ La contrainte 'new()' ne peut pas être utilisée avec la contrainte 'unmanaged' + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? '{0}' : le type utilisé dans une instruction using asynchrone doit être implicitement convertible en 'System.IAsyncDisposable' ou doit implémenter une méthode 'DisposeAsync' appropriée. Est-ce qu'il ne s'agit pas plutôt de 'using' au lieu de 'await using' ? diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 1c5ba91a132dd..254e62344b438 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -782,9 +782,9 @@ Il metodo '{0}' dell'inizializzatore di modulo deve essere statico, non deve contenere parametri e deve restituire 'void' - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ Non è possibile usare il vincolo 'new()' con il vincolo 'unmanaged' + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? '{0}': il tipo usato in un'istruzione using asincrona deve essere convertibile in modo implicito in 'System.IAsyncDisposable' o implementare un metodo 'DisposeAsync' adatto. Si intendeva 'using' invece di 'await using'? diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index a03217367159b..26760a6a2d0af 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -782,9 +782,9 @@ モジュール初期化子メソッド '{0}' は、static でなければならず、パラメーターを持ってはならず、'void' を返す必要があります - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ new()' 制約は 'unmanaged' 制約と一緒には使用できません + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? '{0}': 非同期 using ステートメントで使用される型は、暗黙的に 'System.IAsyncDisposable' に変換可能であるか、適切な 'DisposeAsync' メソッドを実装する必要があります。'await using' ではなく 'using' ですか? diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index c135a8aa2707e..bbe60a11c8733 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -782,9 +782,9 @@ 모듈 이니셜라이저 메서드 '{0}'은(는) 정적이어야 하고, 매개 변수가 없어야 하며, 'void'를 반환해야 합니다. - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ new()' 제약 조건은 'unmanaged' 제약 조건과 함께 사용할 수 없습니다. + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? '{0}': 비동기 using 문에 사용된 형식은 암시적으로 'System.IAsyncDisposable'로 변환할 수 있거나 적합한 'DisposeAsync' 메서드를 구현해야 합니다. 'await using' 대신 'using'을 사용하시겠습니까? diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index e42a0422bd5d1..15d929f9138fe 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -782,9 +782,9 @@ Metoda inicjatora modułu „{0}” musi być statyczna, nie może mieć parametrów i musi zwracać typ „void” - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ Ograniczenie „new()” nie może być używane z ograniczeniem „unmanaged” + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? „{0}”: Typ użyty w asynchronicznej instrukcji using musi być jawnie konwertowalny na typ „System.IAsyncDisposable” lub musi implementować odpowiednią metodę „DisposeAsync”. Czy chodziło Ci o użycie instrukcji „using”, a nie „await using”? diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 2d269cfceff82..dd2da20e76139 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -782,9 +782,9 @@ O método inicializador do módulo '{0}' precisa ser estático, não pode ter parâmetros e precisa retornar 'void' - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ A restrição 'new()' não pode ser usada com a restrição 'unmanaged' + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? '{0}': o tipo usado em uma instrução using assíncrona deve ser implicitamente conversível em 'System.IAsyncDisposable' ou implementar um método 'DisposeAsync' adequado. Você quis dizer 'using' em vez de 'await using'? diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 37036f9116592..26b85d6343ab5 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -782,9 +782,9 @@ Метод инициализатора модуля "{0}" должен быть статическим, не должен иметь параметров и должен возвращать "void". - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ Ограничение "new()" невозможно использовать вместе с ограничением "unmanaged" + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? "{0}": тип, используемый в асинхронном операторе using, должен допускать неявное преобразование в тип "System.IAsyncDisposable" или реализовывать подходящий метод "DisposeAsync". Возможно, вы имели в виду "using", а не "await using"? diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index d77d17b9d01bb..a83279edaae31 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -782,9 +782,9 @@ '{0}' modül başlatıcısı metodu statik olmalıdır, hiç parametresi olmamalıdır ve 'void' döndürmelidir - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ 'new()' kısıtlaması, 'unmanaged' kısıtlamasıyla kullanılamaz + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? '{0}': Asenkron bir using deyiminde kullanılan tür örtük olarak 'System.IAsyncDisposable' arabirimine dönüştürebilir olmalı veya uygun bir 'DisposeAsync' metodunu uygulamalıdır. 'await using' yerine 'using' mi kullanmak istediniz? diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index a9ae8895a6540..3f29a3245f5d8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -782,9 +782,9 @@ 模块初始值设定项方法“{0}”必须是静态的,不能有任何参数,并且必须返回 "void" - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ "new()" 约束不能与 "unmanaged" 约束一起使用 + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? “{0}”: 异步 using 语句中使用的类型必须可隐式转换为 "System.IAsyncDisposable" 或实现适用的 "DisposeAsync" 方法。是否希望使用 "using" 而非 "await using"? diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 615076f82c3a8..aceafecc2f0f3 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -782,9 +782,9 @@ 模組初始設定式方法 '{0}' 必須是靜態,不得具有任何參數,而且必須傳回 'void' - - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string - Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string + Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string @@ -812,6 +812,11 @@ new()' 條件約束不能和 'unmanaged' 條件約束一起使用 + + Newline is not allowed inside a non-verbatim interpolated string + Newline is not allowed inside a non-verbatim interpolated string + + '{0}': type used in an asynchronous using statement must be implicitly convertible to 'System.IAsyncDisposable' or implement a suitable 'DisposeAsync' method. Did you mean 'using' rather than 'await using'? '{0}': 在非同步 using 陳述式中使用的類型,必須可隱含地轉換為 'System.IAsyncDisposable' 或實作合適的 'DisposeAsync' 方法。您指的是否為 'using',而非 'await using'? diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index f94de6e9ce778..9eee584ab14c7 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -448,7 +448,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string1() + public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string1() { var test = @" public class Test @@ -464,7 +464,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string2() + public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string2() { var test = @" public class Test @@ -478,28 +478,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. + // (6,28): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { @" " - Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), - // (6,28): error CS1002: ; expected - // string s = $"x { @" " - Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(6, 28), - // (7,26): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration - // } y"; - Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(7, 26), - // (7,26): error CS1010: Newline in constant - // } y"; - Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(7, 26), - // (7,26): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration - // } y"; - Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(7, 26), - // (9,1): error CS1022: Type or namespace definition, or end-of-file expected - // } - Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(9, 1)); + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 28)); } [Fact] - public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string3() + public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string3() { var test = @" public class Test @@ -515,11 +500,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); } [Fact] - public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string4() + public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string4() { var test = @" public class Test @@ -534,28 +519,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string + // (6,24): error CS9000: Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24), - // (7,27): error CS1002: ; expected - // " - Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(7, 27), - // (8,26): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration - // } y"; - Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(8, 26), - // (8,26): error CS1010: Newline in constant - // } y"; - Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(8, 26), - // (8,26): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration - // } y"; - Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(8, 26), - // (10,1): error CS1022: Type or namespace definition, or end-of-file expected - // } - Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(10, 1)); + Diagnostic(ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); } [Fact] - public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string5() + public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string5() { var test = @" public class Test @@ -569,34 +539,25 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. - // string s = $"x { - Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), - // (6,23): error CS1733: Expected expression + // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), - // (6,23): error CS1002: ; expected + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), + // (6,23): error CS1525: Invalid expression term '' // string s = $"x { - Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(6, 23), - // (7,30): error CS1002: ; expected + Diagnostic(ErrorCode.ERR_InvalidExprTerm, "").WithArguments("").WithLocation(6, 23), + // (7,1): error CS1073: Unexpected token '@' // @" " } y"; - Diagnostic(ErrorCode.ERR_SemicolonExpected, "}").WithLocation(7, 30), - // (7,33): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration + Diagnostic(ErrorCode.ERR_UnexpectedToken, "").WithArguments("@").WithLocation(7, 1), + // (7,25): error CS1646: Keyword, identifier, or string expected after verbatim specifier: @ // @" " } y"; - Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(7, 33), - // (7,33): error CS1010: Newline in constant + Diagnostic(ErrorCode.ERR_ExpectedVerbatimLiteral, "").WithLocation(7, 25), + // (7,28): error CS1002: ; expected // @" " } y"; - Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(7, 33), - // (7,33): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration - // @" " } y"; - Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(7, 33), - // (9,1): error CS1022: Type or namespace definition, or end-of-file expected - // } - Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(9, 1)); + Diagnostic(ErrorCode.ERR_SemicolonExpected, @""" } y""").WithLocation(7, 28)); } [Fact] - public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string6() + public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string6() { var test = @" public class Test @@ -611,34 +572,25 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. + // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), - // (6,23): error CS1733: Expected expression - // string s = $"x { - Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), - // (6,23): error CS1002: ; expected + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), + // (6,23): error CS1525: Invalid expression term '' // string s = $"x { - Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(6, 23), - // (8,28): error CS1002: ; expected - // " } y"; - Diagnostic(ErrorCode.ERR_SemicolonExpected, "}").WithLocation(8, 28), - // (8,31): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration - // " } y"; - Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(8, 31), - // (8,31): error CS1010: Newline in constant - // " } y"; - Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(8, 31), - // (8,31): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration - // " } y"; - Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(8, 31), - // (10,1): error CS1022: Type or namespace definition, or end-of-file expected - // } - Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(10, 1)); + Diagnostic(ErrorCode.ERR_InvalidExprTerm, "").WithArguments("").WithLocation(6, 23), + // (7,1): error CS1073: Unexpected token '@' + // @" " } y"; + Diagnostic(ErrorCode.ERR_UnexpectedToken, "").WithArguments("@").WithLocation(7, 1), + // (7,25): error CS1646: Keyword, identifier, or string expected after verbatim specifier: @ + // @" " } y"; + Diagnostic(ErrorCode.ERR_ExpectedVerbatimLiteral, "").WithLocation(7, 25), + // (7,28): error CS1002: ; expected + // @" " } y"; + Diagnostic(ErrorCode.ERR_SemicolonExpected, @"").WithLocation(7, 27)); } [Fact] - public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string7() + public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string7() { var test = @" public class Test @@ -654,15 +606,24 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. + // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), - // (6,23): error CS1733: Expected expression - // string s = $"x { - Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), - // (6,23): error CS1002: ; expected + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), + // (6,23): error CS1525: Invalid expression term '' // string s = $"x { - Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(6, 23), + Diagnostic(ErrorCode.ERR_InvalidExprTerm, "").WithArguments("").WithLocation(6, 23), + // (7,1): error CS1073: Unexpected token '@' + // @" + Diagnostic(ErrorCode.ERR_UnexpectedToken, "").WithArguments("@").WithLocation(7, 1), + // (7,25): error CS1646: Keyword, identifier, or string expected after verbatim specifier: @ + // @" + Diagnostic(ErrorCode.ERR_ExpectedVerbatimLiteral, "").WithLocation(7, 25), + // (7,27): error CS1002: ; expected + // @" + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(7, 27), + // (8,26): error CS1010: Newline in constant + // " + Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(8, 26), // (8,27): error CS1002: ; expected // " Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(8, 27), @@ -681,7 +642,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string8() + public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string8() { var test = @" public class Test @@ -698,11 +659,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); } [Fact] - public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string9() + public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string9() { var test = @" public class Test @@ -719,11 +680,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); } [Fact] - public void CS9000ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string10() + public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string10() { var test = @" public class Test @@ -740,7 +701,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,30): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { $@" { @" - Diagnostic(ErrorCode.ERR_Multi_line_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 30)); + Diagnostic(ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 30)); } [Fact] From 804dc4475735d0d7bd97e37d4414971914880d9d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 13:07:06 -0700 Subject: [PATCH 06/45] Improve recovery --- .../Portable/Parser/Lexer_StringLiteral.cs | 23 ++++++- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 60 +------------------ 2 files changed, 23 insertions(+), 60 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 0a7e016638563..5fc050e59e328 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -277,6 +277,7 @@ private class InterpolatedStringScanner private readonly Lexer _lexer; private bool _isVerbatim; private bool _allowNewlines; + public SyntaxDiagnosticInfo error; public InterpolatedStringScanner( @@ -674,10 +675,26 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool } /// - /// The lexer can run away consuming the rest of the input when delimiters are mismatched. - /// This is a test for when we are attempting to recover from that situation. + /// The lexer can run away consuming the rest of the input when delimiters are mismatched. This is a test + /// for when we are attempting to recover from that situation. Note that just running into new lines will + /// not make us thing we're in runaway lexing. /// - private bool RecoveringFromRunawayLexing() => this.error != null; + private bool RecoveringFromRunawayLexing() + { + if (this.error == null) + return false; + + var code = (ErrorCode)this.error.Code; + switch (code) + { + case ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string: + case ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string: + case ErrorCode.ERR_SingleLineCommentInExpressionHole: + return false; + } + + return true; + } private void ScanInterpolatedStringLiteralNestedComment() { diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 9eee584ab14c7..213bcf1eb4cad 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -541,19 +541,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), - // (6,23): error CS1525: Invalid expression term '' - // string s = $"x { - Diagnostic(ErrorCode.ERR_InvalidExprTerm, "").WithArguments("").WithLocation(6, 23), - // (7,1): error CS1073: Unexpected token '@' - // @" " } y"; - Diagnostic(ErrorCode.ERR_UnexpectedToken, "").WithArguments("@").WithLocation(7, 1), - // (7,25): error CS1646: Keyword, identifier, or string expected after verbatim specifier: @ - // @" " } y"; - Diagnostic(ErrorCode.ERR_ExpectedVerbatimLiteral, "").WithLocation(7, 25), - // (7,28): error CS1002: ; expected - // @" " } y"; - Diagnostic(ErrorCode.ERR_SemicolonExpected, @""" } y""").WithLocation(7, 28)); + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] @@ -574,19 +562,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), - // (6,23): error CS1525: Invalid expression term '' - // string s = $"x { - Diagnostic(ErrorCode.ERR_InvalidExprTerm, "").WithArguments("").WithLocation(6, 23), - // (7,1): error CS1073: Unexpected token '@' - // @" " } y"; - Diagnostic(ErrorCode.ERR_UnexpectedToken, "").WithArguments("@").WithLocation(7, 1), - // (7,25): error CS1646: Keyword, identifier, or string expected after verbatim specifier: @ - // @" " } y"; - Diagnostic(ErrorCode.ERR_ExpectedVerbatimLiteral, "").WithLocation(7, 25), - // (7,28): error CS1002: ; expected - // @" " } y"; - Diagnostic(ErrorCode.ERR_SemicolonExpected, @"").WithLocation(7, 27)); + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] @@ -608,37 +584,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), - // (6,23): error CS1525: Invalid expression term '' - // string s = $"x { - Diagnostic(ErrorCode.ERR_InvalidExprTerm, "").WithArguments("").WithLocation(6, 23), - // (7,1): error CS1073: Unexpected token '@' - // @" - Diagnostic(ErrorCode.ERR_UnexpectedToken, "").WithArguments("@").WithLocation(7, 1), - // (7,25): error CS1646: Keyword, identifier, or string expected after verbatim specifier: @ - // @" - Diagnostic(ErrorCode.ERR_ExpectedVerbatimLiteral, "").WithLocation(7, 25), - // (7,27): error CS1002: ; expected - // @" - Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(7, 27), - // (8,26): error CS1010: Newline in constant - // " - Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(8, 26), - // (8,27): error CS1002: ; expected - // " - Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(8, 27), - // (9,26): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration - // } y"; - Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(9, 26), - // (9,26): error CS1010: Newline in constant - // } y"; - Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(9, 26), - // (9,26): error CS1519: Invalid token '";' in class, record, struct, or interface member declaration - // } y"; - Diagnostic(ErrorCode.ERR_InvalidMemberDecl, @""";").WithArguments("\";").WithLocation(9, 26), - // (11,1): error CS1022: Type or namespace definition, or end-of-file expected - // } - Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(11, 1)); + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] From f19a2fca22dc57ba19d12aa2785ec87a1a842d96 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 13:21:35 -0700 Subject: [PATCH 07/45] Remove hardcoded error codes. --- .../Portable/Parser/Lexer_StringLiteral.cs | 94 +++++++++++-------- 1 file changed, 53 insertions(+), 41 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 5fc050e59e328..6477b6bdcfa38 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -231,7 +231,20 @@ internal void ScanInterpolatedStringLiteralTop(ArrayBuilder inter { var subScanner = new InterpolatedStringScanner(this, isVerbatim); subScanner.ScanInterpolatedStringLiteralTop(interpolations, ref info, out closeQuoteMissing); - error = subScanner.error; + + // if there are two syntax errors reported, then notify the user of the one earliest in the file. + if (subScanner.UnrecoverableError != null && subScanner.RecoverableError != null) + { + error = subScanner.UnrecoverableError.Offset <= subScanner.RecoverableError.Offset + ? subScanner.UnrecoverableError + : subScanner.RecoverableError; + } + else + { + // otherwise, just return any syntax error we might have. + error = subScanner.UnrecoverableError ?? subScanner.RecoverableError; + } + info.Text = TextWindow.GetText(false); } @@ -278,7 +291,19 @@ private class InterpolatedStringScanner private bool _isVerbatim; private bool _allowNewlines; - public SyntaxDiagnosticInfo error; + /// + /// There are two types of errors we can encounter when trying to scan out an interpolated string (and it's + /// interpolations). The first are true syntax errors where we do not know what it is going on and have no + /// good strategy to get back on track. This happens when we see things in the interpolation we truly do + /// not know what to do with, or when we find we've gotten into an unbalanced state with the bracket pairs + /// we're consuming. In this case, we will often choose to bail out rather than go on and potentially make + /// things worse. The second (), still indicates that the user code is wrong, + /// however we don't need to stop processing. + /// + public SyntaxDiagnosticInfo UnrecoverableError; + + /// + public SyntaxDiagnosticInfo RecoverableError; public InterpolatedStringScanner( Lexer lexer, @@ -326,10 +351,10 @@ internal void ScanInterpolatedStringLiteralTop(ArrayBuilder inter if (_lexer.TextWindow.PeekChar() != '"') { Debug.Assert(IsAtEnd()); - if (error == null) + if (UnrecoverableError == null) { int position = IsAtEnd(true) ? _lexer.TextWindow.Position - 1 : _lexer.TextWindow.Position; - error = _lexer.MakeError(position, 1, _isVerbatim ? ErrorCode.ERR_UnterminatedStringLit : ErrorCode.ERR_NewlineInConst); + UnrecoverableError = _lexer.MakeError(position, 1, _isVerbatim ? ErrorCode.ERR_UnterminatedStringLit : ErrorCode.ERR_NewlineInConst); } closeQuoteMissing = true; @@ -379,9 +404,9 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder i { _lexer.TextWindow.AdvanceChar(); // } } - else if (error == null) + else if (UnrecoverableError == null) { - error = _lexer.MakeError(pos, 1, ErrorCode.ERR_UnescapedCurly, "}"); + UnrecoverableError = _lexer.MakeError(pos, 1, ErrorCode.ERR_UnescapedCurly, "}"); } continue; case '{': @@ -405,9 +430,9 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder i else { closeBraceMissing = true; - if (error == null) + if (UnrecoverableError == null) { - error = _lexer.MakeError(openBracePosition - 1, 2, ErrorCode.ERR_UnclosedExpressionHole); + UnrecoverableError = _lexer.MakeError(openBracePosition - 1, 2, ErrorCode.ERR_UnclosedExpressionHole); } } @@ -423,9 +448,9 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder i var escapeStart = _lexer.TextWindow.Position; char c2; char ch = _lexer.ScanEscapeSequence(out c2); - if ((ch == '{' || ch == '}') && error == null) + if ((ch == '{' || ch == '}') && UnrecoverableError == null) { - error = _lexer.MakeError(escapeStart, _lexer.TextWindow.Position - escapeStart, ErrorCode.ERR_EscapedCurly, ch); + UnrecoverableError = _lexer.MakeError(escapeStart, _lexer.TextWindow.Position - escapeStart, ErrorCode.ERR_EscapedCurly, ch); } continue; @@ -450,9 +475,9 @@ private void ScanFormatSpecifier() var pos = _lexer.TextWindow.Position; char c2; ch = _lexer.ScanEscapeSequence(out c2); - if ((ch == '{' || ch == '}') && error == null) + if ((ch == '{' || ch == '}') && UnrecoverableError == null) { - error = _lexer.MakeError(pos, 1, ErrorCode.ERR_EscapedCurly, ch); + UnrecoverableError = _lexer.MakeError(pos, 1, ErrorCode.ERR_EscapedCurly, ch); } } else if (ch == '"') @@ -476,9 +501,9 @@ private void ScanFormatSpecifier() { _lexer.TextWindow.AdvanceChar(); // { } - else if (error == null) + else if (UnrecoverableError == null) { - error = _lexer.MakeError(pos, 1, ErrorCode.ERR_UnescapedCurly, "{"); + UnrecoverableError = _lexer.MakeError(pos, 1, ErrorCode.ERR_UnescapedCurly, "{"); } } else if (ch == '}') @@ -513,9 +538,12 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { char ch = _lexer.TextWindow.PeekChar(); + // See if we ran into an disallowed new line. If so, this is recoverable, so just skip past it but + // give a good message about the issue. This will prevent a lot of cascading issues with the remainder + // of the interpolated string that comes on the following lines. var allowNewLines = _isVerbatim && _allowNewlines; - if (!allowNewLines && SyntaxFacts.IsNewLine(ch) && error == null) - error = _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string); + if (!allowNewLines && SyntaxFacts.IsNewLine(ch)) + RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string); if (IsAtEnd(allowNewline: true)) { @@ -527,9 +555,9 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { case '#': // preprocessor directives not allowed. - if (error == null) + if (UnrecoverableError == null) { - error = _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); + UnrecoverableError = _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); } _lexer.TextWindow.AdvanceChar(); @@ -577,9 +605,9 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool return; } - if (error == null) + if (UnrecoverableError == null) { - error = _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); + UnrecoverableError = _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); } goto default; @@ -600,8 +628,8 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool // check for verbatim string inside an expression hole. var nestedStringPosition = _lexer.TextWindow.Position; var errorCode = ScanInterpolatedStringLiteralNestedVerbatimString(); - if (error == null && errorCode != null) - error = _lexer.MakeError(nestedStringPosition, width: 2, errorCode.Value); + if (UnrecoverableError == null && errorCode != null) + UnrecoverableError = _lexer.MakeError(nestedStringPosition, width: 2, errorCode.Value); continue; } @@ -636,8 +664,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { // error: single-line comment not allowed in an interpolated string. // report the error but keep going for good error recovery. - if (error == null) - error = _lexer.MakeError(_lexer.TextWindow.Position, 2, ErrorCode.ERR_SingleLineCommentInExpressionHole); + RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, 2, ErrorCode.ERR_SingleLineCommentInExpressionHole); } _lexer.TextWindow.AdvanceChar(); // skip / @@ -677,24 +704,9 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool /// /// The lexer can run away consuming the rest of the input when delimiters are mismatched. This is a test /// for when we are attempting to recover from that situation. Note that just running into new lines will - /// not make us thing we're in runaway lexing. + /// not make us thing we're in runaway lexing (which is why we ignore here). /// - private bool RecoveringFromRunawayLexing() - { - if (this.error == null) - return false; - - var code = (ErrorCode)this.error.Code; - switch (code) - { - case ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string: - case ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string: - case ErrorCode.ERR_SingleLineCommentInExpressionHole: - return false; - } - - return true; - } + private bool RecoveringFromRunawayLexing() => this.UnrecoverableError != null; private void ScanInterpolatedStringLiteralNestedComment() { From a8c23798c418d0032a43ca81cdf63f35864e7515 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 13:38:07 -0700 Subject: [PATCH 08/45] Doc --- .../Portable/Parser/Lexer_StringLiteral.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 6477b6bdcfa38..6c2b12ee87a5e 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -152,6 +152,9 @@ private char ScanEscapeSequence(out char surrogateCharacter) return ch; } + /// + /// Returns an appropriate error code if scanning this verbatim literal ran into an error. + /// private ErrorCode? ScanVerbatimStringLiteral(ref TokenInfo info, bool allowNewlines) { _builder.Length = 0; @@ -627,9 +630,16 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { // check for verbatim string inside an expression hole. var nestedStringPosition = _lexer.TextWindow.Position; - var errorCode = ScanInterpolatedStringLiteralNestedVerbatimString(); - if (UnrecoverableError == null && errorCode != null) - UnrecoverableError = _lexer.MakeError(nestedStringPosition, width: 2, errorCode.Value); + + // Note that this verbatim string may encounter an error (for example if it contains a + // new line and we don't allow that). This should be reported to the user, but should + // not put us into an unrecoverable position. We can clearly see that this was intended + // to be a normal verbatim string, so we can continue on an attempt to understand the + // outer interpolated string properly. + var discarded = default(TokenInfo); + var errorCode = _lexer.ScanVerbatimStringLiteral(ref discarded, _allowNewlines); + if (errorCode != null) + RecoverableError ??= _lexer.MakeError(nestedStringPosition, width: 2, errorCode.Value); continue; } @@ -737,12 +747,6 @@ private void ScanInterpolatedStringLiteralNestedString() _lexer.ScanStringLiteral(ref discarded, inDirective: false); } - private ErrorCode? ScanInterpolatedStringLiteralNestedVerbatimString() - { - var discarded = default(TokenInfo); - return _lexer.ScanVerbatimStringLiteral(ref discarded, _allowNewlines); - } - private void ScanInterpolatedStringLiteralHoleBracketed(char start, char end) { Debug.Assert(start == _lexer.TextWindow.PeekChar()); From 649f71b30e97446bb0415a86b1fd2272d5bb7f98 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 14:01:18 -0700 Subject: [PATCH 09/45] Before changes --- .../CSharp/Portable/Errors/ErrorCode.cs | 3 +- .../Portable/Parser/Lexer_StringLiteral.cs | 12 +- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 423 ++++++++++++++++++ 3 files changed, 435 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 24e7c7d33954b..49762577cb512 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1983,7 +1983,8 @@ internal enum ErrorCode ERR_NoImplicitConvTargetTypedConditional = 8957, ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9000, - ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9001, + ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9000, + ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9002, #endregion diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 6c2b12ee87a5e..70583bf4e17c2 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -726,12 +726,20 @@ private void ScanInterpolatedStringLiteralNestedComment() _lexer.TextWindow.AdvanceChar(); while (true) { - if (IsAtEnd()) + var ch = _lexer.TextWindow.PeekChar(); + + // See if we ran into an disallowed new line. If so, this is recoverable, so just skip past it but + // give a good message about the issue. This will prevent a lot of cascading issues with the remainder + // of the interpolated string that comes on the following lines. + var allowNewLines = _isVerbatim && _allowNewlines; + if (!allowNewLines && SyntaxFacts.IsNewLine(ch)) + RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string); + + if (IsAtEnd(allowNewline: true)) { return; // let the caller complain about the unterminated quote } - var ch = _lexer.TextWindow.PeekChar(); _lexer.TextWindow.AdvanceChar(); if (ch == '*' && _lexer.TextWindow.PeekChar() == '/') { diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 213bcf1eb4cad..5161c834ddbe2 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -775,6 +775,429 @@ public static int Main() Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 30)); } + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string1() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* comment */ } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string2() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* comment } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string3() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* comment + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string4() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* comment */ 0 } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string5() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* comment */ + 0 } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string6() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* + * comment + */ } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string7() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* comment */ 0 } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string8() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* comment */ + 0 } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test, + // (6,37): error CS9001: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { /* comment */ + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string9() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* comment */ + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS1733: Expected expression + // string s = $"x { /* comment */ + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), + // (6,37): error CS9001: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { /* comment */ + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string10() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* comment */ 0 + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string11() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* comment */ + 0 } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string12() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* + * comment + */ + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string13() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* + * comment + */ 0 + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string14() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* + * comment + */ + 0 } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string15() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { /* + * comment + */ + 0 + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string16() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { + /* comment */ } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string17() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { + /* comment */ 0 } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string18() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { + /* + * comment + */ } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string19() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { + /* + * comment + */ 0 } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string20() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { + /* + * comment + */ + 0 } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string21() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { + /* + * comment + */ + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string22() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { + /* + * comment + */ 0 + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + + [Fact] + public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string23() + { + var test = @" +public class Test +{ + public static int Main() + { + string s = $""x { + /* + *comment + */ + 0 + } y""; + } +} +"; + + ParserErrorMessageTests.ParseAndValidate(test); + } + #endregion #region "Targeted Warning Tests - please arrange tests in the order of error code" From d985d204d847df42f7c84484cad47b33275b8e96 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 14:10:31 -0700 Subject: [PATCH 10/45] Collapse to one error message --- .../CSharp/Portable/CSharpResources.resx | 3 - .../CSharp/Portable/Errors/ErrorCode.cs | 2 - .../Portable/Parser/Lexer_StringLiteral.cs | 4 +- .../Portable/xlf/CSharpResources.cs.xlf | 5 - .../Portable/xlf/CSharpResources.de.xlf | 5 - .../Portable/xlf/CSharpResources.es.xlf | 5 - .../Portable/xlf/CSharpResources.fr.xlf | 5 - .../Portable/xlf/CSharpResources.it.xlf | 5 - .../Portable/xlf/CSharpResources.ja.xlf | 5 - .../Portable/xlf/CSharpResources.ko.xlf | 5 - .../Portable/xlf/CSharpResources.pl.xlf | 5 - .../Portable/xlf/CSharpResources.pt-BR.xlf | 5 - .../Portable/xlf/CSharpResources.ru.xlf | 5 - .../Portable/xlf/CSharpResources.tr.xlf | 5 - .../Portable/xlf/CSharpResources.zh-Hans.xlf | 5 - .../Portable/xlf/CSharpResources.zh-Hant.xlf | 5 - .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 427 +++++++++++------- 17 files changed, 267 insertions(+), 234 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index bcb58e387b8a2..d1e9cb2bae3bb 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6794,9 +6794,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ At least one top-level statement must be non-empty. - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 49762577cb512..58070c3e6e21e 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1982,9 +1982,7 @@ internal enum ErrorCode ERR_FileScopedNamespaceNotBeforeAllMembers = 8956, ERR_NoImplicitConvTargetTypedConditional = 8957, - ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9000, ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9000, - ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9002, #endregion diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 70583bf4e17c2..67acb9473ecb2 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -193,7 +193,7 @@ private char ScanEscapeSequence(out char surrogateCharacter) // the verbatim literal to the end to avoid the contents of the string being lexed as C# (which will // cause a ton of cascaded errors). Only need to do this on the first newline we hit. if (!allowNewlines && SyntaxFacts.IsNewLine(ch) && error == null) - error = ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string; + error = ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string; TextWindow.AdvanceChar(); _builder.Append(ch); @@ -733,7 +733,7 @@ private void ScanInterpolatedStringLiteralNestedComment() // of the interpolated string that comes on the following lines. var allowNewLines = _isVerbatim && _allowNewlines; if (!allowNewLines && SyntaxFacts.IsNewLine(ch)) - RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string); + RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string); if (IsAtEnd(allowNewline: true)) { diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 9059ce20e9a2c..b935253bc216a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -782,11 +782,6 @@ Inicializační metoda modulu {0} musí být statická, nesmí mít žádné parametry a musí vracet void. - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). Ve stejném adresáři nemůže být více konfiguračních souborů analyzátoru ({0}). diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 088102cb0aa85..72f5e07b39b34 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -782,11 +782,6 @@ Die Modulinitialisierermethode "{0}" muss statisch sein, darf keine Parameter enthalten und muss "void" zurückgeben. - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). Dasselbe Verzeichnis ({0}) darf nicht mehrere Konfigurationsdateien des Analysetools enthalten. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index f29a8f3308c55..866e2d5bfd62d 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -782,11 +782,6 @@ El método inicializador de módulos "{0}" debe ser estático, no debe tener parámetros y debe devolver "void". - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). No es posible que un mismo directorio ("{0}") contenga varios archivos de configuración del analizador. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index ccd0f367443ef..729ced96b4f02 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -782,11 +782,6 @@ La méthode d'initialiseur de module '{0}' doit être statique, ne doit avoir aucun paramètre et doit retourner 'void' - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). Plusieurs fichiers config d'analyseur ne peuvent pas figurer dans le même répertoire ('{0}'). diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 254e62344b438..55fdc9acabb8e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -782,11 +782,6 @@ Il metodo '{0}' dell'inizializzatore di modulo deve essere statico, non deve contenere parametri e deve restituire 'void' - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). La stessa directory ('{0}') non può contenere più file di configurazione dell'analizzatore. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 26760a6a2d0af..ca7c769c2c522 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -782,11 +782,6 @@ モジュール初期化子メソッド '{0}' は、static でなければならず、パラメーターを持ってはならず、'void' を返す必要があります - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). 複数のアナライザー構成ファイルを同じディレクトリに入れることはできません ('{0}')。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index bbe60a11c8733..99d7b717d47ff 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -782,11 +782,6 @@ 모듈 이니셜라이저 메서드 '{0}'은(는) 정적이어야 하고, 매개 변수가 없어야 하며, 'void'를 반환해야 합니다. - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). 분석기 구성 파일 여러 개가 동일한 디렉터리('{0}')에 있을 수 없습니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 15d929f9138fe..63c67c9f1dd8b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -782,11 +782,6 @@ Metoda inicjatora modułu „{0}” musi być statyczna, nie może mieć parametrów i musi zwracać typ „void” - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). Wiele plików konfiguracji analizatora nie może znajdować się w tym samym katalogu („{0}”). diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index dd2da20e76139..91cd42c175b78 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -782,11 +782,6 @@ O método inicializador do módulo '{0}' precisa ser estático, não pode ter parâmetros e precisa retornar 'void' - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). Não é possível que haja vários arquivos de configuração do analisador no mesmo diretório ('{0}'). diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 26b85d6343ab5..7bf593ed0b51c 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -782,11 +782,6 @@ Метод инициализатора модуля "{0}" должен быть статическим, не должен иметь параметров и должен возвращать "void". - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). В одном каталоге ("{0}") не может находиться несколько файлов конфигурации анализатора. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index a83279edaae31..df51790f7c679 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -782,11 +782,6 @@ '{0}' modül başlatıcısı metodu statik olmalıdır, hiç parametresi olmamalıdır ve 'void' döndürmelidir - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). Birden çok çözümleyici yapılandırma dosyası aynı dizinde ('{0}') olamaz. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 3f29a3245f5d8..331ab9fc5806d 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -782,11 +782,6 @@ 模块初始值设定项方法“{0}”必须是静态的,不能有任何参数,并且必须返回 "void" - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). 多个分析器配置文件不能位于同一目录({0})中。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index aceafecc2f0f3..b792188c475a1 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -782,11 +782,6 @@ 模組初始設定式方法 '{0}' 必須是靜態,不得具有任何參數,而且必須傳回 'void' - - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string - - Multiple analyzer config files cannot be in the same directory ('{0}'). 多個分析器組態檔無法處於相同目錄 ('{0}') 中。 diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 5161c834ddbe2..15932c4bae4f8 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -448,7 +448,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string1() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string1() { var test = @" public class Test @@ -464,7 +464,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string2() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string2() { var test = @" public class Test @@ -484,7 +484,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string3() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string3() { var test = @" public class Test @@ -500,11 +500,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); } [Fact] - public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string4() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string4() { var test = @" public class Test @@ -521,11 +521,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); } [Fact] - public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string5() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string5() { var test = @" public class Test @@ -545,7 +545,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string6() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string6() { var test = @" public class Test @@ -566,7 +566,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string7() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string7() { var test = @" public class Test @@ -588,7 +588,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string8() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string8() { var test = @" public class Test @@ -605,11 +605,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); } [Fact] - public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string9() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string9() { var test = @" public class Test @@ -626,11 +626,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); } [Fact] - public void CS9000ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string10() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string10() { var test = @" public class Test @@ -647,143 +647,166 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,30): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { $@" { @" - Diagnostic(ErrorCode.ERR_Multiline_verbatim_string_literal_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 30)); + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 30)); } [Fact] - public void CS8077ERR_SingleLineCommentInExpressionHole1() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string11() { var test = @" public class Test { public static int Main() { - string s = $""x { // comment - } y""; + string s = $""x { /* comment */ } y""; } } "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS1733: Expected expression - // string s = $"x { // comment - Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), - // (6,24): error CS8077: A single-line comment may not be used in an interpolated string. - // string s = $"x { // comment - Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 24)); + // (6,38): error CS1733: Expected expression + // string s = $"x { /* comment */ } y"; + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 38)); } [Fact] - public void CS8077ERR_SingleLineCommentInExpressionHole2() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string12() { var test = @" public class Test { public static int Main() { - string s = $@""x { // comment - } y""; + string s = $""x { /* comment } y""; } } "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,24): error CS1733: Expected expression - // string s = $@"x { // comment - Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 24)); + // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. + // string s = $"x { /* comment } y"; + Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), + // (6,24): error CS1035: End-of-file found, '*/' expected + // string s = $"x { /* comment } y"; + Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(6, 24), + // (9,1): error CS1733: Expected expression + // + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(9, 1), + // (9,1): error CS1002: ; expected + // + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(9, 1), + // (9,1): error CS1513: } expected + // + Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(9, 1), + // (9,1): error CS1513: } expected + // + Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(9, 1)); } [Fact] - public void CS8077ERR_SingleLineCommentInExpressionHole3() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string13() { var test = @" public class Test { public static int Main() { - string s = $""x { $@"" { // comment - } "" } y""; + string s = $""x { /* comment + } y""; } } "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,29): error CS1733: Expected expression - // string s = $"x { $@" { // comment - Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29), - // (6,30): error CS8077: A single-line comment may not be used in an interpolated string. - // string s = $"x { $@" { // comment - Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 30)); + // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. + // string s = $"x { /* comment + Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), + // (6,24): error CS1035: End-of-file found, '*/' expected + // string s = $"x { /* comment + Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(6, 24), + // (10,1): error CS1733: Expected expression + // + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(10, 1), + // (10,1): error CS1002: ; expected + // + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(10, 1), + // (10,1): error CS1513: } expected + // + Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(10, 1), + // (10,1): error CS1513: } expected + // + Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(10, 1)); } + [Fact] - public void CS8077ERR_SingleLineCommentInExpressionHole4() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string14() { var test = @" public class Test { public static int Main() { - string s = $""x { // comment - 0 - } y""; + string s = $""x { /* comment */ 0 } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,24): error CS8077: A single-line comment may not be used in an interpolated string. - // string s = $"x { // comment - Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 24)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] - public void CS8077ERR_SingleLineCommentInExpressionHole5() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string15() { var test = @" public class Test { public static int Main() { - string s = $@""x { // comment - 0 - } y""; + string s = $""x { /* comment */ + 0 } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,37): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { /* comment */ + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); } [Fact] - public void CS8077ERR_SingleLineCommentInExpressionHole6() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string16() { var test = @" public class Test { public static int Main() { - string s = $""x { $@"" { // comment - 0 - } "" } y""; + string s = $""x { /* + * comment + */ } y""; } } "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,30): error CS8077: A single-line comment may not be used in an interpolated string. - // string s = $"x { $@" { // comment - Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 30)); + // (6,26): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { /* + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26), + // (8,29): error CS1733: Expected expression + // */ } y"; + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string1() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string17() { var test = @" public class Test { public static int Main() { - string s = $""x { /* comment */ } y""; + string s = $""x { /* comment */ 0 } y""; } } "; @@ -792,56 +815,70 @@ public static int Main() } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string2() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string18() { var test = @" public class Test { public static int Main() { - string s = $""x { /* comment } y""; + string s = $""x { /* comment */ + 0 } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,37): error CS9001: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { /* comment */ + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string3() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string19() { var test = @" public class Test { public static int Main() { - string s = $""x { /* comment - } y""; + string s = $""x { /* comment */ + } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS1733: Expected expression + // string s = $"x { /* comment */ + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), + // (6,37): error CS9001: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { /* comment */ + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string4() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string20() { var test = @" public class Test { public static int Main() { - string s = $""x { /* comment */ 0 } y""; + string s = $""x { /* comment */ 0 + } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,39): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { /* comment */ 0 + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 39)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string5() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string21() { var test = @" public class Test @@ -854,11 +891,14 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,37): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { /* comment */ + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string6() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string22() { var test = @" public class Test @@ -867,154 +907,188 @@ public static int Main() { string s = $""x { /* * comment - */ } y""; + */ + } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS1733: Expected expression + // string s = $"x { /* + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), + // (6,26): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { /* + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string7() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string23() { var test = @" public class Test { public static int Main() { - string s = $""x { /* comment */ 0 } y""; + string s = $""x { /* + * comment + */ 0 + } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,26): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { /* + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string8() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string24() { var test = @" public class Test { public static int Main() { - string s = $""x { /* comment */ + string s = $""x { /* + * comment + */ 0 } y""; } } "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,37): error CS9001: Newline is not allowed inside a non-verbatim interpolated string - // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); + // (6,26): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { /* + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string9() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string25() { var test = @" public class Test { public static int Main() { - string s = $""x { /* comment */ + string s = $""x { /* + * comment + */ + 0 } y""; } } "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS1733: Expected expression - // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), - // (6,37): error CS9001: Newline is not allowed inside a non-verbatim interpolated string - // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); + // (6,26): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { /* + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string10() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string26() { var test = @" public class Test { public static int Main() { - string s = $""x { /* comment */ 0 - } y""; + string s = $""x { + /* comment */ } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), + // (6,23): error CS1733: Expected expression + // string s = $"x { + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string11() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string27() { var test = @" public class Test { public static int Main() { - string s = $""x { /* comment */ - 0 } y""; + string s = $""x { + /* comment */ 0 } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string12() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string28() { var test = @" public class Test { public static int Main() { - string s = $""x { /* + string s = $""x { + /* * comment - */ - } y""; + */ } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), + // (6,23): error CS1733: Expected expression + // string s = $"x { + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string13() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string29() { var test = @" public class Test { public static int Main() { - string s = $""x { /* + string s = $""x { + /* * comment - */ 0 - } y""; + */ 0 } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string14() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string30() { var test = @" public class Test { public static int Main() { - string s = $""x { /* + string s = $""x { + /* * comment */ 0 } y""; @@ -1022,31 +1096,40 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string15() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string31() { var test = @" public class Test { public static int Main() { - string s = $""x { /* + string s = $""x { + /* * comment */ - 0 } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), + // (6,23): error CS1733: Expected expression + // string s = $"x { + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string16() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string32() { var test = @" public class Test @@ -1054,16 +1137,22 @@ public class Test public static int Main() { string s = $""x { - /* comment */ } y""; + /* + * comment + */ 0 + } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string17() + public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string33() { var test = @" public class Test @@ -1071,105 +1160,119 @@ public class Test public static int Main() { string s = $""x { - /* comment */ 0 } y""; + /* + *comment + */ + 0 + } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // string s = $"x { + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string18() + public void CS8077ERR_SingleLineCommentInExpressionHole1() { var test = @" public class Test { public static int Main() { - string s = $""x { - /* - * comment - */ } y""; + string s = $""x { // comment + } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,23): error CS1733: Expected expression + // string s = $"x { // comment + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), + // (6,24): error CS8077: A single-line comment may not be used in an interpolated string. + // string s = $"x { // comment + Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 24)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string19() + public void CS8077ERR_SingleLineCommentInExpressionHole2() { var test = @" public class Test { public static int Main() { - string s = $""x { - /* - * comment - */ 0 } y""; + string s = $@""x { // comment + } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,24): error CS1733: Expected expression + // string s = $@"x { // comment + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 24)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string20() + public void CS8077ERR_SingleLineCommentInExpressionHole3() { var test = @" public class Test { public static int Main() { - string s = $""x { - /* - * comment - */ - 0 } y""; + string s = $""x { $@"" { // comment + } "" } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,29): error CS1733: Expected expression + // string s = $"x { $@" { // comment + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29), + // (6,30): error CS8077: A single-line comment may not be used in an interpolated string. + // string s = $"x { $@" { // comment + Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 30)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string21() + public void CS8077ERR_SingleLineCommentInExpressionHole4() { var test = @" public class Test { public static int Main() { - string s = $""x { - /* - * comment - */ + string s = $""x { // comment + 0 } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,24): error CS8077: A single-line comment may not be used in an interpolated string. + // string s = $"x { // comment + Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 24)); } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string22() + public void CS8077ERR_SingleLineCommentInExpressionHole5() { var test = @" public class Test { public static int Main() { - string s = $""x { - /* - * comment - */ 0 - } y""; + string s = $@""x { // comment + 0 + } y""; } } "; @@ -1178,24 +1281,24 @@ public static int Main() } [Fact] - public void CS9002ERR_Multiline_comment_is_not_allowed_inside_a_non_verbatim_interpolated_string23() + public void CS8077ERR_SingleLineCommentInExpressionHole6() { var test = @" public class Test { public static int Main() { - string s = $""x { - /* - *comment - */ - 0 - } y""; + string s = $""x { $@"" { // comment + 0 + } "" } y""; } } "; - ParserErrorMessageTests.ParseAndValidate(test); + ParserErrorMessageTests.ParseAndValidate(test, + // (6,30): error CS8077: A single-line comment may not be used in an interpolated string. + // string s = $"x { $@" { // comment + Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 30)); } #endregion From a0d79d52e9a0dea0d4dec0872b0c88ed2031eea5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 14:13:25 -0700 Subject: [PATCH 11/45] Simplify --- src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 67acb9473ecb2..f017aeb9d824e 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -185,15 +185,15 @@ private char ScanEscapeSequence(out char surrogateCharacter) { // Reached the end of the source without finding the end-quote. Give an error back at the // starting point. And finish lexing this string. - error = ErrorCode.ERR_UnterminatedStringLit; + error ??= ErrorCode.ERR_UnterminatedStringLit; break; } // If we hit a new line when it's not allowed. Give an error at that new line, but keep on consuming // the verbatim literal to the end to avoid the contents of the string being lexed as C# (which will // cause a ton of cascaded errors). Only need to do this on the first newline we hit. - if (!allowNewlines && SyntaxFacts.IsNewLine(ch) && error == null) - error = ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string; + if (!allowNewlines && SyntaxFacts.IsNewLine(ch)) + error ??= ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string; TextWindow.AdvanceChar(); _builder.Append(ch); From 1a26596ce94650387a1cbf6c2acce996c620ba0d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 15:00:43 -0700 Subject: [PATCH 12/45] Fixup --- .../Semantic/Semantics/InterpolationTests.cs | 78 +++++++++++-------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index 1d37a8c5c1083..4e19b77b61231 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -131,19 +131,21 @@ public static void Main(string[] args) }"; // too many diagnostics perhaps, but it starts the right way. CreateCompilationWithMscorlib45(source).VerifyDiagnostics( - // (5,60): error CS8076: Missing close delimiter '}' for interpolated expression started with {. - // Console.WriteLine($"Jenny don\'t change your number { "); - Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(5, 60), // (5,63): error CS1010: Newline in constant // Console.WriteLine($"Jenny don\'t change your number { "); Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(5, 63), - // (5,66): error CS1026: ) expected + // (5,66): error CS9000: Newline is not allowed inside a non-verbatim interpolated string // Console.WriteLine($"Jenny don\'t change your number { "); - Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(5, 66), - // (5,66): error CS1002: ; expected - // Console.WriteLine($"Jenny don\'t change your number { "); - Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(5, 66) - ); + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(5, 66), + // (6,6): error CS1026: ) expected + // } + Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(6, 6), + // (6,6): error CS1002: ; expected + // } + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(6, 6), + // (7,2): error CS1513: } expected + // } + Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(7, 2)); } [Fact] @@ -161,8 +163,16 @@ public static void Main(string[] args) CreateCompilationWithMscorlib45(source).VerifyDiagnostics( // (5,71): error CS8077: A single-line comment may not be used in an interpolated string. // Console.WriteLine($"Jenny don\'t change your number { 8675309 // "); - Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(5, 71) - ); + Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(5, 71), + // (6,6): error CS1026: ) expected + // } + Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(6, 6), + // (6,6): error CS1002: ; expected + // } + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(6, 6), + // (7,2): error CS1513: } expected + // } + Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(7, 2)); } [Fact] @@ -178,19 +188,24 @@ public static void Main(string[] args) }"; // too many diagnostics perhaps, but it starts the right way. CreateCompilationWithMscorlib45(source).VerifyDiagnostics( - // (5,60): error CS8076: Missing close delimiter '}' for interpolated expression started with {. + // (5,60): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. // Console.WriteLine($"Jenny don\'t change your number { 8675309 /* "); Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(5, 60), // (5,71): error CS1035: End-of-file found, '*/' expected // Console.WriteLine($"Jenny don\'t change your number { 8675309 /* "); Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(5, 71), - // (5,77): error CS1026: ) expected - // Console.WriteLine($"Jenny don\'t change your number { 8675309 /* "); - Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(5, 77), - // (5,77): error CS1002: ; expected - // Console.WriteLine($"Jenny don\'t change your number { 8675309 /* "); - Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(5, 77) - ); + // (7,2): error CS1026: ) expected + // } + Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(7, 2), + // (7,2): error CS1002: ; expected + // } + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(7, 2), + // (7,2): error CS1513: } expected + // } + Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(7, 2), + // (7,2): error CS1513: } expected + // } + Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(7, 2)); } [Fact] @@ -345,20 +360,21 @@ static void Main(string[] args) Console.WriteLine( $""{"" ); } }"; - CreateCompilationWithMscorlib45(source).VerifyDiagnostics( - // (6,29): error CS8076: Missing close delimiter '}' for interpolated expression started with {. - // Console.WriteLine( $"{" ); - Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, @"""{").WithLocation(6, 29), - // (6,31): error CS1010: Newline in constant - // Console.WriteLine( $"{" ); + CreateCompilationWithMscorlib45(source).VerifyDiagnostics( // (6,31): error CS1010: Newline in constant + // Console.WriteLine( $"{" ); Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(6, 31), - // (6,35): error CS1026: ) expected - // Console.WriteLine( $"{" ); - Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(6, 35), - // (6,35): error CS1002: ; expected + // (6,35): error CS9000: Newline is not allowed inside a non-verbatim interpolated string // Console.WriteLine( $"{" ); - Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(6, 35) - ); + Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 35), + // (7,6): error CS1026: ) expected + // } + Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(7, 6), + // (7,6): error CS1002: ; expected + // } + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(7, 6), + // (8,2): error CS1513: } expected + // } + Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(8, 2)); } [Fact] From f789b07b30f40e33bf1d0fd9709222bec261c70d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 15:39:25 -0700 Subject: [PATCH 13/45] Temp --- ...sionInInterpolatedStringCodeFixProvider.cs | 63 ++++++++++++++++--- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs b/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs index 6208665ed0dce..883e409b147d0 100644 --- a/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs @@ -64,18 +64,67 @@ private static async Task GetChangedDocumentAsync(Document document, i var openParenthesisPosition = conditionalExpressionSyntaxStartPosition; var textWithOpenParenthesis = text.Replace(openParenthesisPosition, 0, "("); var documentWithOpenParenthesis = document.WithText(textWithOpenParenthesis); + var syntaxRoot = await documentWithOpenParenthesis.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var nodeAtInsertPosition = syntaxRoot.FindNode(new TextSpan(openParenthesisPosition, 0)); - if (nodeAtInsertPosition is ParenthesizedExpressionSyntax parenthesizedExpression && - parenthesizedExpression.CloseParenToken.IsMissing) + + if (nodeAtInsertPosition is not ParenthesizedExpressionSyntax parenthesizedExpression || + !parenthesizedExpression.CloseParenToken.IsMissing) + { + return documentWithOpenParenthesis; + } + + return await InsertCloseParenthesisAsync( + documentWithOpenParenthesis, parenthesizedExpression, cancellationToken).ConfigureAwait(false); + } + + private static async Task InsertCloseParenthesisAsync( + Document document, + ParenthesizedExpressionSyntax parenthesizedExpression, + CancellationToken cancellationToken) + { + var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); + if (parenthesizedExpression.Expression is ConditionalExpressionSyntax conditional && + parenthesizedExpression.GetAncestor()?.StringStartToken.Kind() == SyntaxKind.InterpolatedStringStartToken) { - var newCloseParen = SyntaxFactory.Token(SyntaxKind.CloseParenToken).WithTriviaFrom(parenthesizedExpression.CloseParenToken); - var parenthesizedExpressionWithClosingParen = parenthesizedExpression.WithCloseParenToken(newCloseParen); - syntaxRoot = syntaxRoot.ReplaceNode(parenthesizedExpression, parenthesizedExpressionWithClosingParen); - return documentWithOpenParenthesis.WithSyntaxRoot(syntaxRoot); + var closeParenPosition = GetCloseParenPosition(sourceText, conditional); + var textWithCloseParenthesis = sourceText.Replace(closeParenPosition, 0, ")"); + return document.WithText(textWithCloseParenthesis); } - return documentWithOpenParenthesis; + var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); + var newCloseParen = SyntaxFactory.Token(SyntaxKind.CloseParenToken).WithTriviaFrom(parenthesizedExpression.CloseParenToken); + var parenthesizedExpressionWithClosingParen = parenthesizedExpression.WithCloseParenToken(newCloseParen); + var newRoot = root.ReplaceNode(parenthesizedExpression, parenthesizedExpressionWithClosingParen); + return document.WithSyntaxRoot(newRoot); + + static int GetCloseParenPosition(SourceText sourceText, ConditionalExpressionSyntax conditional) + { + // If they have something like: + // + // PreviousLineOfCode(); + // var s3 = $""Text1 { true ? ""Text2""[|:|] + // NextLineOfCode(); + // + // Then they likely did not intend the code on the next line to be part of the conditional. + // So instead find the colon and place the close paren after that. + + var endToken = sourceText.AreOnSameLine(conditional.ColonToken, conditional.WhenFalse.GetFirstToken()) + ? conditional.WhenFalse.GetLastToken() + : conditional.ColonToken; + + // Place the paren after any + var endPosition = endToken.Span.End; + foreach (var trivia in endToken.TrailingTrivia) + { + if (trivia.Kind() is SyntaxKind.EndOfLineTrivia or SyntaxKind.SingleLineCommentTrivia) + break; + + endPosition = trivia.Span.End; + } + + return endPosition; + } } private class MyCodeAction : CodeAction.DocumentChangeAction From 0ab8e6d229c3dd3c8759656ef8dc1656298cb7d8 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 16 Jul 2021 15:45:02 -0700 Subject: [PATCH 14/45] Feature fallout --- ...nInterpolatedStringCodeFixProviderTests.cs | 26 +++++++-------- ...sionInInterpolatedStringCodeFixProvider.cs | 33 +++++-------------- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs index d47f0070ed64a..726f124376402 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs @@ -88,7 +88,7 @@ public async Task TestAddParenthesesWithTrivia() { await TestInMethodAsync( @"var s = $""{ /* Leading1 */ true /* Leading2 */ ? /* TruePart1 */ 1 /* TruePart2 */[|:|] /* FalsePart1 */ 2 /* FalsePart2 */ }"";", - @"var s = $""{ /* Leading1 */ (true /* Leading2 */ ? /* TruePart1 */ 1 /* TruePart2 */: /* FalsePart1 */ 2 /* FalsePart2 */ )}"";"); + @"var s = $""{ /* Leading1 */ (true /* Leading2 */ ? /* TruePart1 */ 1 /* TruePart2 */: /* FalsePart1 */ 2) /* FalsePart2 */ }"";"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] @@ -96,7 +96,7 @@ public async Task TestAddParenthesesClosingBracketInFalseCondition() { await TestInMethodAsync( @"var s = $""{ true ? new int[0] [|:|] new int[] {} }"";", - @"var s = $""{ (true ? new int[0] : new int[] {} )}"";"); + @"var s = $""{ (true ? new int[0] : new int[] {}) }"";"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] @@ -104,7 +104,7 @@ public async Task TestAddParenthesesStringLiteralInFalseCondition() { await TestInMethodAsync( @"var s = $""{ true ? ""1"" [|:|] ""2"" }"";", - @"var s = $""{ (true ? ""1"" : ""2"" )}"";"); + @"var s = $""{ (true ? ""1"" : ""2"") }"";"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] @@ -112,7 +112,7 @@ public async Task TestAddParenthesesVerbatimStringLiteralInFalseCondition() { await TestInMethodAsync( @"var s = $""{ true ? ""1"" [|:|] @""""""2"""""" }"";", - @"var s = $""{ (true ? ""1"" : @""""""2"""""" )}"";"); + @"var s = $""{ (true ? ""1"" : @""""""2"""""") }"";"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] @@ -120,7 +120,7 @@ public async Task TestAddParenthesesStringLiteralInFalseConditionWithClosingPare { await TestInMethodAsync( @"var s = $""{ true ? ""1"" [|:|] ""2)"" }"";", - @"var s = $""{ (true ? ""1"" : ""2)"" )}"";"); + @"var s = $""{ (true ? ""1"" : ""2)"") }"";"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] @@ -128,7 +128,7 @@ public async Task TestAddParenthesesStringLiteralInFalseConditionWithEscapedDoub { await TestInMethodAsync( @"var s = $""{ true ? ""1"" [|:|] ""2\"""" }"";", - @"var s = $""{ (true ? ""1"" : ""2\"""" )}"";"); + @"var s = $""{ (true ? ""1"" : ""2\"""") }"";"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] @@ -136,7 +136,7 @@ public async Task TestAddParenthesesStringLiteralInFalseConditionWithCodeLikeCon { await TestInMethodAsync( @"var s = $""{ true ? ""1"" [|:|] ""M(new int[] {}, \""Parameter\"");"" }"";", - @"var s = $""{ (true ? ""1"" : ""M(new int[] {}, \""Parameter\"");"" )}"";"); + @"var s = $""{ (true ? ""1"" : ""M(new int[] {}, \""Parameter\"");"") }"";"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] @@ -144,7 +144,7 @@ public async Task TestAddParenthesesNestedConditionalExpression1() { await TestInMethodAsync( @"var s2 = $""{ true ? ""1"" [|:|] (false ? ""2"" : ""3"") };", - @"var s2 = $""{ (true ? ""1"" : (false ? ""2"" : ""3"") )};"); + @"var s2 = $""{ (true ? ""1"" : (false ? ""2"" : ""3"")) };"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] @@ -152,7 +152,7 @@ public async Task TestAddParenthesesNestedConditionalExpression2() { await TestInMethodAsync( @"var s2 = $""{ true ? ""1"" [|:|] false ? ""2"" : ""3"" };", - @"var s2 = $""{ (true ? ""1"" : false ? ""2"" : ""3"" )};"); + @"var s2 = $""{ (true ? ""1"" : false ? ""2"" : ""3"") };"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsAddParenthesesAroundConditionalExpressionInInterpolatedString)] @@ -253,7 +253,7 @@ await TestInMethodAsync( NextLineOfCode();", @" PreviousLineOfCode(); - var s3 = $""Text1 { (true ? ""Text2"" : ""Text3"" )} + var s3 = $""Text1 { (true ? ""Text2"" : ""Text3"") } NextLineOfCode();"); } @@ -267,7 +267,7 @@ await TestInMethodAsync( NextLineOfCode();", @" ( - var s3 = $""Text1 { (true ? ""Text2"" : ""Text3"" )} + var s3 = $""Text1 { (true ? ""Text2"" : ""Text3"") } NextLineOfCode();"); } @@ -281,7 +281,7 @@ await TestInMethodAsync( NextLineOfCode(", @" PreviousLineOfCode(); - var s3 = $""Text1 { (true ? ""Text2"" : ""Text3"" )} + var s3 = $""Text1 { (true ? ""Text2"" : ""Text3"") } NextLineOfCode("); } @@ -295,7 +295,7 @@ await TestInMethodAsync( NextLineOfCode();", @" PreviousLineOfCode(); - var s3 = ($""Text1 { (true ? ""Text2"" : ""Text3"" )} + var s3 = ($""Text1 { (true ? ""Text2"" : ""Text3"") } NextLineOfCode();"); } diff --git a/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs b/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs index 883e409b147d0..6cdb0dbf13a09 100644 --- a/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs @@ -86,19 +86,6 @@ private static async Task InsertCloseParenthesisAsync( var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false); if (parenthesizedExpression.Expression is ConditionalExpressionSyntax conditional && parenthesizedExpression.GetAncestor()?.StringStartToken.Kind() == SyntaxKind.InterpolatedStringStartToken) - { - var closeParenPosition = GetCloseParenPosition(sourceText, conditional); - var textWithCloseParenthesis = sourceText.Replace(closeParenPosition, 0, ")"); - return document.WithText(textWithCloseParenthesis); - } - - var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); - var newCloseParen = SyntaxFactory.Token(SyntaxKind.CloseParenToken).WithTriviaFrom(parenthesizedExpression.CloseParenToken); - var parenthesizedExpressionWithClosingParen = parenthesizedExpression.WithCloseParenToken(newCloseParen); - var newRoot = root.ReplaceNode(parenthesizedExpression, parenthesizedExpressionWithClosingParen); - return document.WithSyntaxRoot(newRoot); - - static int GetCloseParenPosition(SourceText sourceText, ConditionalExpressionSyntax conditional) { // If they have something like: // @@ -113,18 +100,16 @@ static int GetCloseParenPosition(SourceText sourceText, ConditionalExpressionSyn ? conditional.WhenFalse.GetLastToken() : conditional.ColonToken; - // Place the paren after any - var endPosition = endToken.Span.End; - foreach (var trivia in endToken.TrailingTrivia) - { - if (trivia.Kind() is SyntaxKind.EndOfLineTrivia or SyntaxKind.SingleLineCommentTrivia) - break; - - endPosition = trivia.Span.End; - } - - return endPosition; + var closeParenPosition = endToken.Span.End; + var textWithCloseParenthesis = sourceText.Replace(closeParenPosition, 0, ")"); + return document.WithText(textWithCloseParenthesis); } + + var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); + var newCloseParen = SyntaxFactory.Token(SyntaxKind.CloseParenToken).WithTriviaFrom(parenthesizedExpression.CloseParenToken); + var parenthesizedExpressionWithClosingParen = parenthesizedExpression.WithCloseParenToken(newCloseParen); + var newRoot = root.ReplaceNode(parenthesizedExpression, parenthesizedExpressionWithClosingParen); + return document.WithSyntaxRoot(newRoot); } private class MyCodeAction : CodeAction.DocumentChangeAction From 7bb1203b104d06e27c4f7918340c13b04b0ec21f Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 09:10:29 -0700 Subject: [PATCH 15/45] Spelling --- src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index f017aeb9d824e..c2ae90ba46e7c 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -171,7 +171,7 @@ private char ScanEscapeSequence(out char surrogateCharacter) TextWindow.AdvanceChar(); if (TextWindow.PeekChar() == '"') { - // Doubled quote -- skip & put the single quote in the string and keep goign. + // Doubled quote -- skip & put the single quote in the string and keep going. TextWindow.AdvanceChar(); _builder.Append(ch); continue; From db131e6c0156813a6d0f30e99165bc248d551271 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 09:10:59 -0700 Subject: [PATCH 16/45] Update error code --- src/Compilers/CSharp/Portable/Errors/ErrorCode.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 58070c3e6e21e..a80e312c44381 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1981,8 +1981,7 @@ internal enum ErrorCode ERR_FileScopedAndNormalNamespace = 8955, ERR_FileScopedNamespaceNotBeforeAllMembers = 8956, ERR_NoImplicitConvTargetTypedConditional = 8957, - - ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string = 9000, + ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string = 8958, #endregion From 4d9b0497af5c23eff4dd3f161f9d7be56ace6864 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 09:11:26 -0700 Subject: [PATCH 17/45] spelling --- src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index c2ae90ba46e7c..edaf323ae1b7f 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -295,7 +295,7 @@ private class InterpolatedStringScanner private bool _allowNewlines; /// - /// There are two types of errors we can encounter when trying to scan out an interpolated string (and it's + /// There are two types of errors we can encounter when trying to scan out an interpolated string (and its /// interpolations). The first are true syntax errors where we do not know what it is going on and have no /// good strategy to get back on track. This happens when we see things in the interpolation we truly do /// not know what to do with, or when we find we've gotten into an unbalanced state with the bracket pairs From 929bb6894a15e6227bffda22a21e8972e1acfef1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 09:13:58 -0700 Subject: [PATCH 18/45] nrt --- .../Portable/Parser/Lexer_StringLiteral.cs | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index edaf323ae1b7f..6133ba1c29031 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -2,16 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - -using Microsoft.CodeAnalysis.Collections; -using Microsoft.CodeAnalysis.PooledObjects; -using System; -using System.Collections.Generic; using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Microsoft.CodeAnalysis.PooledObjects; namespace Microsoft.CodeAnalysis.CSharp.Syntax.InternalSyntax { @@ -224,13 +216,14 @@ private void ScanInterpolatedStringLiteral(bool isVerbatim, ref TokenInfo info) // /**/ comments, ' characters quotes, () parens // [] brackets, and "" strings, including interpolated holes in the latter. - SyntaxDiagnosticInfo error = null; + SyntaxDiagnosticInfo? error = null; bool closeQuoteMissing; ScanInterpolatedStringLiteralTop(null, isVerbatim, ref info, ref error, out closeQuoteMissing); this.AddError(error); } - internal void ScanInterpolatedStringLiteralTop(ArrayBuilder interpolations, bool isVerbatim, ref TokenInfo info, ref SyntaxDiagnosticInfo error, out bool closeQuoteMissing) + internal void ScanInterpolatedStringLiteralTop( + ArrayBuilder? interpolations, bool isVerbatim, ref TokenInfo info, ref SyntaxDiagnosticInfo? error, out bool closeQuoteMissing) { var subScanner = new InterpolatedStringScanner(this, isVerbatim); subScanner.ScanInterpolatedStringLiteralTop(interpolations, ref info, out closeQuoteMissing); @@ -303,18 +296,18 @@ private class InterpolatedStringScanner /// things worse. The second (), still indicates that the user code is wrong, /// however we don't need to stop processing. /// - public SyntaxDiagnosticInfo UnrecoverableError; + public SyntaxDiagnosticInfo? UnrecoverableError; /// - public SyntaxDiagnosticInfo RecoverableError; + public SyntaxDiagnosticInfo? RecoverableError; public InterpolatedStringScanner( Lexer lexer, bool isVerbatim) { - this._lexer = lexer; - this._isVerbatim = isVerbatim; - this._allowNewlines = isVerbatim; + _lexer = lexer; + _isVerbatim = isVerbatim; + _allowNewlines = isVerbatim; } private bool IsAtEnd() @@ -330,7 +323,7 @@ private bool IsAtEnd(bool allowNewline) (ch == SlidingTextWindow.InvalidCharacter && _lexer.TextWindow.IsReallyAtEnd()); } - internal void ScanInterpolatedStringLiteralTop(ArrayBuilder interpolations, ref TokenInfo info, out bool closeQuoteMissing) + internal void ScanInterpolatedStringLiteralTop(ArrayBuilder? interpolations, ref TokenInfo info, out bool closeQuoteMissing) { if (_isVerbatim) { @@ -372,7 +365,7 @@ internal void ScanInterpolatedStringLiteralTop(ArrayBuilder inter info.Kind = SyntaxKind.InterpolatedStringToken; } - private void ScanInterpolatedStringLiteralContents(ArrayBuilder interpolations) + private void ScanInterpolatedStringLiteralContents(ArrayBuilder? interpolations) { while (true) { @@ -569,7 +562,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool if (_lexer.TextWindow.PeekChar(1) == '"' || _lexer.TextWindow.PeekChar(1) == '@' && _lexer.TextWindow.PeekChar(2) == '"') { bool isVerbatimSubstring = _lexer.TextWindow.PeekChar(1) == '@'; - var interpolations = (ArrayBuilder)null; + var interpolations = (ArrayBuilder?)null; var info = default(TokenInfo); bool wasVerbatim = this._isVerbatim; bool wasAllowNewlines = this._allowNewlines; @@ -646,7 +639,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool else if (_lexer.TextWindow.PeekChar(1) == '$' && _lexer.TextWindow.PeekChar(2) == '"') { _lexer.CheckFeatureAvailability(MessageID.IDS_FeatureAltInterpolatedVerbatimStrings); - var interpolations = (ArrayBuilder)null; + var interpolations = (ArrayBuilder?)null; var info = default(TokenInfo); bool wasVerbatim = this._isVerbatim; bool wasAllowNewlines = this._allowNewlines; From 8e1dbdcb712cb4d4a9553d788663c507dd9177ce Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 09:15:47 -0700 Subject: [PATCH 19/45] Be consistent with brace placement --- .../Portable/Parser/Lexer_StringLiteral.cs | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 6133ba1c29031..770b6b200626f 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -28,9 +28,7 @@ private void ScanStringLiteral(ref TokenInfo info, bool inDirective) ch = this.ScanEscapeSequence(out c2); _builder.Append(ch); if (c2 != SlidingTextWindow.InvalidCharacter) - { _builder.Append(c2); - } } else if (ch == quoteCharacter) { @@ -59,9 +57,7 @@ private void ScanStringLiteral(ref TokenInfo info, bool inDirective) { info.Kind = SyntaxKind.CharacterLiteralToken; if (_builder.Length != 1) - { this.AddError((_builder.Length != 0) ? ErrorCode.ERR_TooManyCharsInConst : ErrorCode.ERR_EmptyCharConst); - } if (_builder.Length > 0) { @@ -427,9 +423,7 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder? { closeBraceMissing = true; if (UnrecoverableError == null) - { UnrecoverableError = _lexer.MakeError(openBracePosition - 1, 2, ErrorCode.ERR_UnclosedExpressionHole); - } } interpolations?.Add(new Interpolation(openBracePosition, colonPosition, closeBracePosition, closeBraceMissing)); @@ -437,17 +431,13 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder? continue; case '\\': if (_isVerbatim) - { goto default; - } var escapeStart = _lexer.TextWindow.Position; char c2; char ch = _lexer.ScanEscapeSequence(out c2); if ((ch == '{' || ch == '}') && UnrecoverableError == null) - { UnrecoverableError = _lexer.MakeError(escapeStart, _lexer.TextWindow.Position - escapeStart, ErrorCode.ERR_EscapedCurly, ch); - } continue; default: @@ -472,9 +462,7 @@ private void ScanFormatSpecifier() char c2; ch = _lexer.ScanEscapeSequence(out c2); if ((ch == '{' || ch == '}') && UnrecoverableError == null) - { UnrecoverableError = _lexer.MakeError(pos, 1, ErrorCode.ERR_EscapedCurly, ch); - } } else if (ch == '"') { @@ -552,9 +540,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool case '#': // preprocessor directives not allowed. if (UnrecoverableError == null) - { UnrecoverableError = _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); - } _lexer.TextWindow.AdvanceChar(); continue; @@ -597,14 +583,10 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool case ')': case ']': if (ch == endingChar) - { return; - } if (UnrecoverableError == null) - { UnrecoverableError = _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); - } goto default; case '"' when RecoveringFromRunawayLexing(): @@ -729,9 +711,7 @@ private void ScanInterpolatedStringLiteralNestedComment() RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string); if (IsAtEnd(allowNewline: true)) - { return; // let the caller complain about the unterminated quote - } _lexer.TextWindow.AdvanceChar(); if (ch == '*' && _lexer.TextWindow.PeekChar() == '/') From 17888b07f09d40c50f81217a501eae580280fabb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 09:19:58 -0700 Subject: [PATCH 20/45] Use ??= --- .../Portable/Parser/Lexer_StringLiteral.cs | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 770b6b200626f..67a1635f41a51 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -396,9 +396,9 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder? { _lexer.TextWindow.AdvanceChar(); // } } - else if (UnrecoverableError == null) + else { - UnrecoverableError = _lexer.MakeError(pos, 1, ErrorCode.ERR_UnescapedCurly, "}"); + UnrecoverableError ??= _lexer.MakeError(pos, 1, ErrorCode.ERR_UnescapedCurly, "}"); } continue; case '{': @@ -422,8 +422,7 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder? else { closeBraceMissing = true; - if (UnrecoverableError == null) - UnrecoverableError = _lexer.MakeError(openBracePosition - 1, 2, ErrorCode.ERR_UnclosedExpressionHole); + UnrecoverableError ??= _lexer.MakeError(openBracePosition - 1, 2, ErrorCode.ERR_UnclosedExpressionHole); } interpolations?.Add(new Interpolation(openBracePosition, colonPosition, closeBracePosition, closeBraceMissing)); @@ -434,10 +433,9 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder? goto default; var escapeStart = _lexer.TextWindow.Position; - char c2; - char ch = _lexer.ScanEscapeSequence(out c2); - if ((ch == '{' || ch == '}') && UnrecoverableError == null) - UnrecoverableError = _lexer.MakeError(escapeStart, _lexer.TextWindow.Position - escapeStart, ErrorCode.ERR_EscapedCurly, ch); + char ch = _lexer.ScanEscapeSequence(out _); + if (ch == '{' || ch == '}') + UnrecoverableError ??= _lexer.MakeError(escapeStart, _lexer.TextWindow.Position - escapeStart, ErrorCode.ERR_EscapedCurly, ch); continue; default: @@ -459,10 +457,9 @@ private void ScanFormatSpecifier() { // normal string & char constants can have escapes var pos = _lexer.TextWindow.Position; - char c2; - ch = _lexer.ScanEscapeSequence(out c2); - if ((ch == '{' || ch == '}') && UnrecoverableError == null) - UnrecoverableError = _lexer.MakeError(pos, 1, ErrorCode.ERR_EscapedCurly, ch); + ch = _lexer.ScanEscapeSequence(out _); + if (ch == '{' || ch == '}') + UnrecoverableError ??= _lexer.MakeError(pos, 1, ErrorCode.ERR_EscapedCurly, ch); } else if (ch == '"') { @@ -485,9 +482,9 @@ private void ScanFormatSpecifier() { _lexer.TextWindow.AdvanceChar(); // { } - else if (UnrecoverableError == null) + else { - UnrecoverableError = _lexer.MakeError(pos, 1, ErrorCode.ERR_UnescapedCurly, "{"); + UnrecoverableError ??= _lexer.MakeError(pos, 1, ErrorCode.ERR_UnescapedCurly, "{"); } } else if (ch == '}') @@ -539,9 +536,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { case '#': // preprocessor directives not allowed. - if (UnrecoverableError == null) - UnrecoverableError = _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); - + UnrecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); _lexer.TextWindow.AdvanceChar(); continue; case '$': @@ -585,9 +580,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool if (ch == endingChar) return; - if (UnrecoverableError == null) - UnrecoverableError = _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); - + UnrecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); goto default; case '"' when RecoveringFromRunawayLexing(): // When recovering from mismatched delimiters, we consume the next From e213d0c796652631c7d64bd8575992f42b45aae9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 09:21:21 -0700 Subject: [PATCH 21/45] Use discards --- .../CSharp/Portable/Parser/Lexer_StringLiteral.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 67a1635f41a51..3cbdb6372a570 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -24,8 +24,7 @@ private void ScanStringLiteral(ref TokenInfo info, bool inDirective) // Normal string & char constants can have escapes. Strings in directives cannot. if (ch == '\\' && !inDirective) { - char c2; - ch = this.ScanEscapeSequence(out c2); + ch = this.ScanEscapeSequence(out var c2); _builder.Append(ch); if (c2 != SlidingTextWindow.InvalidCharacter) _builder.Append(c2); @@ -213,8 +212,7 @@ private void ScanInterpolatedStringLiteral(bool isVerbatim, ref TokenInfo info) // [] brackets, and "" strings, including interpolated holes in the latter. SyntaxDiagnosticInfo? error = null; - bool closeQuoteMissing; - ScanInterpolatedStringLiteralTop(null, isVerbatim, ref info, ref error, out closeQuoteMissing); + ScanInterpolatedStringLiteralTop(null, isVerbatim, ref info, ref error, out _); this.AddError(error); } @@ -551,8 +549,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { this._isVerbatim = isVerbatimSubstring; this._allowNewlines &= _isVerbatim; - bool closeQuoteMissing; - ScanInterpolatedStringLiteralTop(interpolations, ref info, out closeQuoteMissing); + ScanInterpolatedStringLiteralTop(interpolations, ref info, out _); } finally { @@ -622,8 +619,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { this._isVerbatim = true; this._allowNewlines = true; - bool closeQuoteMissing; - ScanInterpolatedStringLiteralTop(interpolations, ref info, out closeQuoteMissing); + ScanInterpolatedStringLiteralTop(interpolations, ref info, out _); } finally { From 0e7a7836530f7315a9143b15cf4783447c2bdbbc Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 09:22:00 -0700 Subject: [PATCH 22/45] use pattern matching --- src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 3cbdb6372a570..4b4810b9e428d 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -603,8 +603,8 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool // outer interpolated string properly. var discarded = default(TokenInfo); var errorCode = _lexer.ScanVerbatimStringLiteral(ref discarded, _allowNewlines); - if (errorCode != null) - RecoverableError ??= _lexer.MakeError(nestedStringPosition, width: 2, errorCode.Value); + if (errorCode is ErrorCode code) + RecoverableError ??= _lexer.MakeError(nestedStringPosition, width: 2, code); continue; } From 6663af92d57a582d136896543e0e6f85088c6453 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 09:23:20 -0700 Subject: [PATCH 23/45] improve error test --- src/Compilers/CSharp/Portable/CSharpResources.resx | 4 ++-- src/Compilers/CSharp/Portable/Errors/ErrorCode.cs | 2 +- src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs | 6 +++--- src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf | 6 +++--- src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf | 6 +++--- src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf | 6 +++--- src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf | 6 +++--- src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf | 6 +++--- src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf | 6 +++--- src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf | 6 +++--- src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf | 6 +++--- src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf | 6 +++--- src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf | 6 +++--- src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf | 6 +++--- .../CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf | 6 +++--- .../CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf | 6 +++--- 16 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index d1e9cb2bae3bb..f920644f7c0ef 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6794,7 +6794,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ At least one top-level statement must be non-empty. - - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index a80e312c44381..f3ba965b8dfad 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1981,7 +1981,7 @@ internal enum ErrorCode ERR_FileScopedAndNormalNamespace = 8955, ERR_FileScopedNamespaceNotBeforeAllMembers = 8956, ERR_NoImplicitConvTargetTypedConditional = 8957, - ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string = 8958, + ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string = 8958, #endregion diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 4b4810b9e428d..2b80a3d54c85e 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -180,7 +180,7 @@ private char ScanEscapeSequence(out char surrogateCharacter) // the verbatim literal to the end to avoid the contents of the string being lexed as C# (which will // cause a ton of cascaded errors). Only need to do this on the first newline we hit. if (!allowNewlines && SyntaxFacts.IsNewLine(ch)) - error ??= ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string; + error ??= ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string; TextWindow.AdvanceChar(); _builder.Append(ch); @@ -522,7 +522,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool // of the interpolated string that comes on the following lines. var allowNewLines = _isVerbatim && _allowNewlines; if (!allowNewLines && SyntaxFacts.IsNewLine(ch)) - RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string); + RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string); if (IsAtEnd(allowNewline: true)) { @@ -697,7 +697,7 @@ private void ScanInterpolatedStringLiteralNestedComment() // of the interpolated string that comes on the following lines. var allowNewLines = _isVerbatim && _allowNewlines; if (!allowNewLines && SyntaxFacts.IsNewLine(ch)) - RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string); + RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string); if (IsAtEnd(allowNewline: true)) return; // let the caller complain about the unterminated quote diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index b935253bc216a..116e558f6de25 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -807,9 +807,9 @@ Omezení new() nejde používat s omezením unmanaged. - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 72f5e07b39b34..6ffb07b1d41df 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -807,9 +807,9 @@ Die new()-Einschränkung kann nicht mit der unmanaged-Einschränkung verwendet werden. - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 866e2d5bfd62d..8ed61543df36e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -807,9 +807,9 @@ La restricción "new()" no se puede utilizar con la restricción "unmanaged" - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 729ced96b4f02..05082b301de68 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -807,9 +807,9 @@ La contrainte 'new()' ne peut pas être utilisée avec la contrainte 'unmanaged' - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 55fdc9acabb8e..e2942374777a6 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -807,9 +807,9 @@ Non è possibile usare il vincolo 'new()' con il vincolo 'unmanaged' - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index ca7c769c2c522..61942f6c3798a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -807,9 +807,9 @@ new()' 制約は 'unmanaged' 制約と一緒には使用できません - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 99d7b717d47ff..1b00fa9f130ba 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -807,9 +807,9 @@ new()' 제약 조건은 'unmanaged' 제약 조건과 함께 사용할 수 없습니다. - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 63c67c9f1dd8b..c6161212f9072 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -807,9 +807,9 @@ Ograniczenie „new()” nie może być używane z ograniczeniem „unmanaged” - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 91cd42c175b78..931871f284efa 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -807,9 +807,9 @@ A restrição 'new()' não pode ser usada com a restrição 'unmanaged' - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 7bf593ed0b51c..7682d2c7eb4cb 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -807,9 +807,9 @@ Ограничение "new()" невозможно использовать вместе с ограничением "unmanaged" - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index df51790f7c679..22b1b796b5dff 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -807,9 +807,9 @@ 'new()' kısıtlaması, 'unmanaged' kısıtlamasıyla kullanılamaz - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 331ab9fc5806d..06fed5c15e09c 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -807,9 +807,9 @@ "new()" 约束不能与 "unmanaged" 约束一起使用 - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index b792188c475a1..081eed5769ac7 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -807,9 +807,9 @@ new()' 條件約束不能和 'unmanaged' 條件約束一起使用 - - Newline is not allowed inside a non-verbatim interpolated string - Newline is not allowed inside a non-verbatim interpolated string + + Newlines are not allowed inside a non-verbatim interpolated string + Newlines are not allowed inside a non-verbatim interpolated string From 50782d015faff5791cce8256492fd3f531b8e006 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 09:30:14 -0700 Subject: [PATCH 24/45] Pattern matching --- src/Compilers/CSharp/Portable/Parser/Lexer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer.cs b/src/Compilers/CSharp/Portable/Parser/Lexer.cs index 0f9c353d6841c..25b34610e5786 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer.cs @@ -765,8 +765,8 @@ private void ScanSyntaxToken(ref TokenInfo info) if (TextWindow.PeekChar(1) == '"') { var errorCode = this.ScanVerbatimStringLiteral(ref info, allowNewlines: true); - if (errorCode != null) - this.AddError(errorCode.Value); + if (errorCode is ErrorCode code) + this.AddError(code); } else if (TextWindow.PeekChar(1) == '$' && TextWindow.PeekChar(2) == '"') { From 1ef5ae1fcd35dd90ca56395a86fc7742893297d3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 09:35:28 -0700 Subject: [PATCH 25/45] Named parameters for clarity --- .../Portable/Parser/Lexer_StringLiteral.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 2b80a3d54c85e..fc9355ea5280d 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -51,7 +51,7 @@ private void ScanStringLiteral(ref TokenInfo info, bool inDirective) } } - info.Text = TextWindow.GetText(true); + info.Text = TextWindow.GetText(intern: true); if (quoteCharacter == '\'') { info.Kind = SyntaxKind.CharacterLiteralToken; @@ -187,7 +187,7 @@ private char ScanEscapeSequence(out char surrogateCharacter) } info.Kind = SyntaxKind.StringLiteralToken; - info.Text = TextWindow.GetText(false); + info.Text = TextWindow.GetText(intern: false); info.StringValue = _builder.ToString(); return error; @@ -212,7 +212,7 @@ private void ScanInterpolatedStringLiteral(bool isVerbatim, ref TokenInfo info) // [] brackets, and "" strings, including interpolated holes in the latter. SyntaxDiagnosticInfo? error = null; - ScanInterpolatedStringLiteralTop(null, isVerbatim, ref info, ref error, out _); + ScanInterpolatedStringLiteralTop(interpolations: null, isVerbatim, ref info, ref error, out _); this.AddError(error); } @@ -235,7 +235,7 @@ internal void ScanInterpolatedStringLiteralTop( error = subScanner.UnrecoverableError ?? subScanner.RecoverableError; } - info.Text = TextWindow.GetText(false); + info.Text = TextWindow.GetText(intern: false); } internal struct Interpolation @@ -313,7 +313,7 @@ private bool IsAtEnd(bool allowNewline) { char ch = _lexer.TextWindow.PeekChar(); return - !allowNewline && SyntaxFacts.IsNewLine(ch) || + (!allowNewline && SyntaxFacts.IsNewLine(ch)) || (ch == SlidingTextWindow.InvalidCharacter && _lexer.TextWindow.IsReallyAtEnd()); } @@ -343,7 +343,7 @@ internal void ScanInterpolatedStringLiteralTop(ArrayBuilder? inte Debug.Assert(IsAtEnd()); if (UnrecoverableError == null) { - int position = IsAtEnd(true) ? _lexer.TextWindow.Position - 1 : _lexer.TextWindow.Position; + int position = IsAtEnd(allowNewline: true) ? _lexer.TextWindow.Position - 1 : _lexer.TextWindow.Position; UnrecoverableError = _lexer.MakeError(position, 1, _isVerbatim ? ErrorCode.ERR_UnterminatedStringLit : ErrorCode.ERR_NewlineInConst); } @@ -410,7 +410,7 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder? int openBracePosition = _lexer.TextWindow.Position; _lexer.TextWindow.AdvanceChar(); int colonPosition = 0; - ScanInterpolatedStringLiteralHoleBalancedText('}', true, ref colonPosition); + ScanInterpolatedStringLiteralHoleBalancedText('}', isHole: true, ref colonPosition); int closeBracePosition = _lexer.TextWindow.Position; bool closeBraceMissing = false; if (_lexer.TextWindow.PeekChar() == '}') @@ -722,7 +722,7 @@ private void ScanInterpolatedStringLiteralHoleBracketed(char start, char end) Debug.Assert(start == _lexer.TextWindow.PeekChar()); _lexer.TextWindow.AdvanceChar(); int colon = 0; - ScanInterpolatedStringLiteralHoleBalancedText(end, false, ref colon); + ScanInterpolatedStringLiteralHoleBalancedText(end, isHole: false, ref colon); if (_lexer.TextWindow.PeekChar() == end) { _lexer.TextWindow.AdvanceChar(); From 31c520f3f530b65e29b2bb11e4afc35de25cf15b Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 09:36:23 -0700 Subject: [PATCH 26/45] no need for 'this._' --- .../Portable/Parser/Lexer_StringLiteral.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index fc9355ea5280d..9a8cf23b0e0ce 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -543,18 +543,18 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool bool isVerbatimSubstring = _lexer.TextWindow.PeekChar(1) == '@'; var interpolations = (ArrayBuilder?)null; var info = default(TokenInfo); - bool wasVerbatim = this._isVerbatim; - bool wasAllowNewlines = this._allowNewlines; + bool wasVerbatim = _isVerbatim; + bool wasAllowNewlines = _allowNewlines; try { - this._isVerbatim = isVerbatimSubstring; - this._allowNewlines &= _isVerbatim; + _isVerbatim = isVerbatimSubstring; + _allowNewlines &= _isVerbatim; ScanInterpolatedStringLiteralTop(interpolations, ref info, out _); } finally { - this._isVerbatim = wasVerbatim; - this._allowNewlines = wasAllowNewlines; + _isVerbatim = wasVerbatim; + _allowNewlines = wasAllowNewlines; } continue; } @@ -613,18 +613,18 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool _lexer.CheckFeatureAvailability(MessageID.IDS_FeatureAltInterpolatedVerbatimStrings); var interpolations = (ArrayBuilder?)null; var info = default(TokenInfo); - bool wasVerbatim = this._isVerbatim; - bool wasAllowNewlines = this._allowNewlines; + bool wasVerbatim = _isVerbatim; + bool wasAllowNewlines = _allowNewlines; try { - this._isVerbatim = true; - this._allowNewlines = true; + _isVerbatim = true; + _allowNewlines = true; ScanInterpolatedStringLiteralTop(interpolations, ref info, out _); } finally { - this._isVerbatim = wasVerbatim; - this._allowNewlines = wasAllowNewlines; + _isVerbatim = wasVerbatim; + _allowNewlines = wasAllowNewlines; } continue; } From 54edb98c38dbbb3a34ca6c5ee336553b5d754b3d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 10:10:15 -0700 Subject: [PATCH 27/45] Fix spelling --- .../CSharp/Portable/Parser/Lexer_StringLiteral.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 9a8cf23b0e0ce..0d9dfecc242d5 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -517,9 +517,9 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { char ch = _lexer.TextWindow.PeekChar(); - // See if we ran into an disallowed new line. If so, this is recoverable, so just skip past it but - // give a good message about the issue. This will prevent a lot of cascading issues with the remainder - // of the interpolated string that comes on the following lines. + // See if we ran into a disallowed new line. If so, this is recoverable, so just skip past it but + // give a good message about the issue. This will prevent a lot of cascading issues with the + // remainder of the interpolated string that comes on the following lines. var allowNewLines = _isVerbatim && _allowNewlines; if (!allowNewLines && SyntaxFacts.IsNewLine(ch)) RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string); @@ -692,7 +692,7 @@ private void ScanInterpolatedStringLiteralNestedComment() { var ch = _lexer.TextWindow.PeekChar(); - // See if we ran into an disallowed new line. If so, this is recoverable, so just skip past it but + // See if we ran into a disallowed new line. If so, this is recoverable, so just skip past it but // give a good message about the issue. This will prevent a lot of cascading issues with the remainder // of the interpolated string that comes on the following lines. var allowNewLines = _isVerbatim && _allowNewlines; From 3ce748585001fbb69891d15513cb6c0843d0c1e6 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 10:13:09 -0700 Subject: [PATCH 28/45] Fix tests --- .../Semantic/Semantics/InterpolationTests.cs | 4 +- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 152 +++++++++--------- 2 files changed, 78 insertions(+), 78 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index 4e19b77b61231..9dce25b3b9a4d 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -134,9 +134,9 @@ public static void Main(string[] args) // (5,63): error CS1010: Newline in constant // Console.WriteLine($"Jenny don\'t change your number { "); Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(5, 63), - // (5,66): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (5,66): error CS9000: Newlines are not allowed inside a non-verbatim interpolated string // Console.WriteLine($"Jenny don\'t change your number { "); - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(5, 66), + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(5, 66), // (6,6): error CS1026: ) expected // } Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(6, 6), diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 15932c4bae4f8..79c9b563b8019 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -448,7 +448,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string1() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string1() { var test = @" public class Test @@ -464,7 +464,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string2() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string2() { var test = @" public class Test @@ -480,11 +480,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,28): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { @" " - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 28)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 28)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string3() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string3() { var test = @" public class Test @@ -500,11 +500,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string4() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string4() { var test = @" public class Test @@ -521,11 +521,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string5() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string5() { var test = @" public class Test @@ -541,11 +541,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string6() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string6() { var test = @" public class Test @@ -562,11 +562,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string7() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string7() { var test = @" public class Test @@ -584,11 +584,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string8() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string8() { var test = @" public class Test @@ -605,11 +605,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string9() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string9() { var test = @" public class Test @@ -626,11 +626,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string10() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string10() { var test = @" public class Test @@ -647,11 +647,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,30): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { $@" { @" - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 30)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 30)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string11() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string11() { var test = @" public class Test @@ -670,7 +670,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string12() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string12() { var test = @" public class Test @@ -704,7 +704,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string13() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string13() { var test = @" public class Test @@ -739,7 +739,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string14() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string14() { var test = @" public class Test @@ -755,7 +755,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string15() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string15() { var test = @" public class Test @@ -769,13 +769,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,37): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,37): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string16() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string16() { var test = @" public class Test @@ -790,16 +790,16 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,26): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26), + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26), // (8,29): error CS1733: Expected expression // */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string17() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string17() { var test = @" public class Test @@ -815,7 +815,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string18() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string18() { var test = @" public class Test @@ -831,11 +831,11 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,37): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string19() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string19() { var test = @" public class Test @@ -854,11 +854,11 @@ public static int Main() Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), // (6,37): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string20() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string20() { var test = @" public class Test @@ -872,13 +872,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,39): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,39): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ 0 - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 39)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 39)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string21() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string21() { var test = @" public class Test @@ -892,13 +892,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,37): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,37): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string22() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string22() { var test = @" public class Test @@ -917,13 +917,13 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { /* Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), - // (6,26): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string23() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string23() { var test = @" public class Test @@ -939,13 +939,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,26): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string24() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string24() { var test = @" public class Test @@ -961,13 +961,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,26): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string25() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string25() { var test = @" public class Test @@ -984,13 +984,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,26): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string26() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string26() { var test = @" public class Test @@ -1004,16 +1004,16 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string27() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string27() { var test = @" public class Test @@ -1027,13 +1027,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string28() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string28() { var test = @" public class Test @@ -1049,16 +1049,16 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string29() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string29() { var test = @" public class Test @@ -1074,13 +1074,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string30() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string30() { var test = @" public class Test @@ -1097,13 +1097,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string31() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string31() { var test = @" public class Test @@ -1120,16 +1120,16 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string32() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string32() { var test = @" public class Test @@ -1146,13 +1146,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] - public void CS9000ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string33() + public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string33() { var test = @" public class Test @@ -1170,9 +1170,9 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); } [Fact] From b58beedf9ed05e28a3880dc8d8efc5d00a9a6ba3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 15:06:26 -0700 Subject: [PATCH 29/45] Update test --- .../CSharp/Test/Semantic/Semantics/InterpolationTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index 9dce25b3b9a4d..ca22d6383523a 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -363,9 +363,9 @@ static void Main(string[] args) CreateCompilationWithMscorlib45(source).VerifyDiagnostics( // (6,31): error CS1010: Newline in constant // Console.WriteLine( $"{" ); Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(6, 31), - // (6,35): error CS9000: Newline is not allowed inside a non-verbatim interpolated string + // (6,35): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // Console.WriteLine( $"{" ); - Diagnostic(ErrorCode.ERR_Newline_is_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 35), + Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 35), // (7,6): error CS1026: ) expected // } Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(7, 6), From 2cf9b05b1dc67eacb8d117a8e9754152469852de Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 19:37:31 -0700 Subject: [PATCH 30/45] Rename error code --- .../CSharp/Portable/Errors/ErrorCode.cs | 2 +- .../Portable/Parser/Lexer_StringLiteral.cs | 6 +-- .../Semantic/Semantics/InterpolationTests.cs | 4 +- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 54 +++++++++---------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index f3ba965b8dfad..fe07b639a0c04 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1981,7 +1981,7 @@ internal enum ErrorCode ERR_FileScopedAndNormalNamespace = 8955, ERR_FileScopedNamespaceNotBeforeAllMembers = 8956, ERR_NoImplicitConvTargetTypedConditional = 8957, - ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string = 8958, + ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString = 8958, #endregion diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 0d9dfecc242d5..23de544f36d15 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -180,7 +180,7 @@ private char ScanEscapeSequence(out char surrogateCharacter) // the verbatim literal to the end to avoid the contents of the string being lexed as C# (which will // cause a ton of cascaded errors). Only need to do this on the first newline we hit. if (!allowNewlines && SyntaxFacts.IsNewLine(ch)) - error ??= ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string; + error ??= ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString; TextWindow.AdvanceChar(); _builder.Append(ch); @@ -522,7 +522,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool // remainder of the interpolated string that comes on the following lines. var allowNewLines = _isVerbatim && _allowNewlines; if (!allowNewLines && SyntaxFacts.IsNewLine(ch)) - RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string); + RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString); if (IsAtEnd(allowNewline: true)) { @@ -697,7 +697,7 @@ private void ScanInterpolatedStringLiteralNestedComment() // of the interpolated string that comes on the following lines. var allowNewLines = _isVerbatim && _allowNewlines; if (!allowNewLines && SyntaxFacts.IsNewLine(ch)) - RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string); + RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString); if (IsAtEnd(allowNewline: true)) return; // let the caller complain about the unterminated quote diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index ca22d6383523a..bb4816b347636 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -136,7 +136,7 @@ public static void Main(string[] args) Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(5, 63), // (5,66): error CS9000: Newlines are not allowed inside a non-verbatim interpolated string // Console.WriteLine($"Jenny don\'t change your number { "); - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(5, 66), + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(5, 66), // (6,6): error CS1026: ) expected // } Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(6, 6), @@ -365,7 +365,7 @@ static void Main(string[] args) Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(6, 31), // (6,35): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // Console.WriteLine( $"{" ); - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 35), + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 35), // (7,6): error CS1026: ) expected // } Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(7, 6), diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 79c9b563b8019..5ac9e96535deb 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -480,7 +480,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,28): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { @" " - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 28)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 28)); } [Fact] @@ -500,7 +500,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, @"@""").WithLocation(6, 24)); } [Fact] @@ -521,7 +521,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multiline verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, @"@""").WithLocation(6, 24)); } [Fact] @@ -541,7 +541,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] @@ -562,7 +562,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] @@ -584,7 +584,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] @@ -605,7 +605,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, @"@""").WithLocation(6, 24)); } [Fact] @@ -626,7 +626,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,24): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { @" - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 24)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, @"@""").WithLocation(6, 24)); } [Fact] @@ -647,7 +647,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,30): error CS9000: Multi-line verbatim string literal is not allowed inside a non-verbatim interpolated string // string s = $"x { $@" { @" - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, @"@""").WithLocation(6, 30)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, @"@""").WithLocation(6, 30)); } [Fact] @@ -771,7 +771,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,37): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); } [Fact] @@ -792,7 +792,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26), + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26), // (8,29): error CS1733: Expected expression // */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29)); @@ -831,7 +831,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,37): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); } [Fact] @@ -854,7 +854,7 @@ public static int Main() Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), // (6,37): error CS9001: Newline is not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); } [Fact] @@ -874,7 +874,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,39): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ 0 - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 39)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 39)); } [Fact] @@ -894,7 +894,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,37): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 37)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); } [Fact] @@ -919,7 +919,7 @@ public static int Main() Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26)); } [Fact] @@ -941,7 +941,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26)); } [Fact] @@ -963,7 +963,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26)); } [Fact] @@ -986,7 +986,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 26)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26)); } [Fact] @@ -1006,7 +1006,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23), // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); @@ -1029,7 +1029,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] @@ -1051,7 +1051,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23), // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); @@ -1076,7 +1076,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] @@ -1099,7 +1099,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] @@ -1122,7 +1122,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23), + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23), // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); @@ -1148,7 +1148,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] @@ -1172,7 +1172,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { - Diagnostic(ErrorCode.ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string, "").WithLocation(6, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] From e6eca49d3719f8ead02832aa97f3a4f8ca1bd79d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 20 Jul 2021 23:06:47 -0700 Subject: [PATCH 31/45] update resource --- src/Compilers/CSharp/Portable/CSharpResources.resx | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index f920644f7c0ef..2e5401440d4ed 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6794,7 +6794,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ At least one top-level statement must be non-empty. - + Newlines are not allowed inside a non-verbatim interpolated string \ No newline at end of file diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 116e558f6de25..72bab67188883 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -807,7 +807,7 @@ Omezení new() nejde používat s omezením unmanaged. - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 6ffb07b1d41df..7b9c63d223284 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -807,7 +807,7 @@ Die new()-Einschränkung kann nicht mit der unmanaged-Einschränkung verwendet werden. - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 8ed61543df36e..f06b96560fc49 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -807,7 +807,7 @@ La restricción "new()" no se puede utilizar con la restricción "unmanaged" - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 05082b301de68..be2cfbecf9541 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -807,7 +807,7 @@ La contrainte 'new()' ne peut pas être utilisée avec la contrainte 'unmanaged' - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index e2942374777a6..1d7ddab27c5b7 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -807,7 +807,7 @@ Non è possibile usare il vincolo 'new()' con il vincolo 'unmanaged' - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 61942f6c3798a..2e45d65f09cf3 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -807,7 +807,7 @@ new()' 制約は 'unmanaged' 制約と一緒には使用できません - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 1b00fa9f130ba..30597ba719869 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -807,7 +807,7 @@ new()' 제약 조건은 'unmanaged' 제약 조건과 함께 사용할 수 없습니다. - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index c6161212f9072..ba0d50131701c 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -807,7 +807,7 @@ Ograniczenie „new()” nie może być używane z ograniczeniem „unmanaged” - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 931871f284efa..2b29cfbcfb85b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -807,7 +807,7 @@ A restrição 'new()' não pode ser usada com a restrição 'unmanaged' - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 7682d2c7eb4cb..419170b5bfe8a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -807,7 +807,7 @@ Ограничение "new()" невозможно использовать вместе с ограничением "unmanaged" - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 22b1b796b5dff..aa2383d96d7f0 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -807,7 +807,7 @@ 'new()' kısıtlaması, 'unmanaged' kısıtlamasıyla kullanılamaz - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 06fed5c15e09c..16939e9e7f571 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -807,7 +807,7 @@ "new()" 约束不能与 "unmanaged" 约束一起使用 - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 081eed5769ac7..eb22b852edce5 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -807,7 +807,7 @@ new()' 條件約束不能和 'unmanaged' 條件約束一起使用 - + Newlines are not allowed inside a non-verbatim interpolated string Newlines are not allowed inside a non-verbatim interpolated string From 50075eb5379a6ec69b03cd5faa630bdd3d00a901 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 21 Jul 2021 23:20:42 -0700 Subject: [PATCH 32/45] Add braces --- .../Portable/Parser/Lexer_StringLiteral.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 23de544f36d15..ec168dba1c07f 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -27,7 +27,9 @@ private void ScanStringLiteral(ref TokenInfo info, bool inDirective) ch = this.ScanEscapeSequence(out var c2); _builder.Append(ch); if (c2 != SlidingTextWindow.InvalidCharacter) + { _builder.Append(c2); + } } else if (ch == quoteCharacter) { @@ -56,7 +58,9 @@ private void ScanStringLiteral(ref TokenInfo info, bool inDirective) { info.Kind = SyntaxKind.CharacterLiteralToken; if (_builder.Length != 1) + { this.AddError((_builder.Length != 0) ? ErrorCode.ERR_TooManyCharsInConst : ErrorCode.ERR_EmptyCharConst); + } if (_builder.Length > 0) { @@ -180,7 +184,9 @@ private char ScanEscapeSequence(out char surrogateCharacter) // the verbatim literal to the end to avoid the contents of the string being lexed as C# (which will // cause a ton of cascaded errors). Only need to do this on the first newline we hit. if (!allowNewlines && SyntaxFacts.IsNewLine(ch)) + { error ??= ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString; + } TextWindow.AdvanceChar(); _builder.Append(ch); @@ -428,12 +434,16 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder? continue; case '\\': if (_isVerbatim) + { goto default; + } var escapeStart = _lexer.TextWindow.Position; char ch = _lexer.ScanEscapeSequence(out _); if (ch == '{' || ch == '}') + { UnrecoverableError ??= _lexer.MakeError(escapeStart, _lexer.TextWindow.Position - escapeStart, ErrorCode.ERR_EscapedCurly, ch); + } continue; default: @@ -457,7 +467,9 @@ private void ScanFormatSpecifier() var pos = _lexer.TextWindow.Position; ch = _lexer.ScanEscapeSequence(out _); if (ch == '{' || ch == '}') + { UnrecoverableError ??= _lexer.MakeError(pos, 1, ErrorCode.ERR_EscapedCurly, ch); + } } else if (ch == '"') { @@ -522,7 +534,9 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool // remainder of the interpolated string that comes on the following lines. var allowNewLines = _isVerbatim && _allowNewlines; if (!allowNewLines && SyntaxFacts.IsNewLine(ch)) + { RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString); + } if (IsAtEnd(allowNewline: true)) { @@ -575,7 +589,9 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool case ')': case ']': if (ch == endingChar) + { return; + } UnrecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); goto default; @@ -604,7 +620,9 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool var discarded = default(TokenInfo); var errorCode = _lexer.ScanVerbatimStringLiteral(ref discarded, _allowNewlines); if (errorCode is ErrorCode code) + { RecoverableError ??= _lexer.MakeError(nestedStringPosition, width: 2, code); + } continue; } @@ -644,7 +662,9 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool _lexer.TextWindow.AdvanceChar(); // skip / _lexer.TextWindow.AdvanceChar(); // skip / while (!IsAtEnd(allowNewline: false)) + { _lexer.TextWindow.AdvanceChar(); // skip // comment character + } continue; case '*': @@ -697,10 +717,14 @@ private void ScanInterpolatedStringLiteralNestedComment() // of the interpolated string that comes on the following lines. var allowNewLines = _isVerbatim && _allowNewlines; if (!allowNewLines && SyntaxFacts.IsNewLine(ch)) + { RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString); + } if (IsAtEnd(allowNewline: true)) + { return; // let the caller complain about the unterminated quote + } _lexer.TextWindow.AdvanceChar(); if (ch == '*' && _lexer.TextWindow.PeekChar() == '/') From 3397aec4033621b4856c434339f843e50590d49e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 21 Jul 2021 23:24:43 -0700 Subject: [PATCH 33/45] add named args --- .../CSharp/Portable/Parser/Lexer_StringLiteral.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index ec168dba1c07f..1978afd463a1a 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -218,7 +218,7 @@ private void ScanInterpolatedStringLiteral(bool isVerbatim, ref TokenInfo info) // [] brackets, and "" strings, including interpolated holes in the latter. SyntaxDiagnosticInfo? error = null; - ScanInterpolatedStringLiteralTop(interpolations: null, isVerbatim, ref info, ref error, out _); + ScanInterpolatedStringLiteralTop(interpolations: null, isVerbatim, ref info, ref error, closeQuoteMissing: out _); this.AddError(error); } @@ -439,7 +439,7 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder? } var escapeStart = _lexer.TextWindow.Position; - char ch = _lexer.ScanEscapeSequence(out _); + char ch = _lexer.ScanEscapeSequence(surrogateCharacter: out _); if (ch == '{' || ch == '}') { UnrecoverableError ??= _lexer.MakeError(escapeStart, _lexer.TextWindow.Position - escapeStart, ErrorCode.ERR_EscapedCurly, ch); @@ -465,7 +465,7 @@ private void ScanFormatSpecifier() { // normal string & char constants can have escapes var pos = _lexer.TextWindow.Position; - ch = _lexer.ScanEscapeSequence(out _); + ch = _lexer.ScanEscapeSequence(surrogateCharacter: out _); if (ch == '{' || ch == '}') { UnrecoverableError ??= _lexer.MakeError(pos, 1, ErrorCode.ERR_EscapedCurly, ch); @@ -563,7 +563,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { _isVerbatim = isVerbatimSubstring; _allowNewlines &= _isVerbatim; - ScanInterpolatedStringLiteralTop(interpolations, ref info, out _); + ScanInterpolatedStringLiteralTop(interpolations, ref info, closeQuoteMissing: out _); } finally { @@ -637,7 +637,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { _isVerbatim = true; _allowNewlines = true; - ScanInterpolatedStringLiteralTop(interpolations, ref info, out _); + ScanInterpolatedStringLiteralTop(interpolations, ref info, closeQuoteMissing: out _); } finally { From a4b6282a47c0bd82790061038170d40fdf216301 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 21 Jul 2021 23:27:38 -0700 Subject: [PATCH 34/45] Update comment --- ...essionInInterpolatedStringCodeFixProvider.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs b/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs index 6cdb0dbf13a09..2477f7b27e3ed 100644 --- a/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs +++ b/src/Features/CSharp/Portable/CodeFixes/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider.cs @@ -89,12 +89,23 @@ private static async Task InsertCloseParenthesisAsync( { // If they have something like: // - // PreviousLineOfCode(); // var s3 = $""Text1 { true ? ""Text2""[|:|] // NextLineOfCode(); // - // Then they likely did not intend the code on the next line to be part of the conditional. - // So instead find the colon and place the close paren after that. + // We will update this initially to: + // + // var s3 = $""Text1 { (true ? ""Text2""[|:|] + // NextLineOfCode(); + // + // And we have to decide where the close paren should go. Based on the parse tree, the + // 'NextLineOfCode()' expression will be pulled into the WhenFalse portion of the conditional. + // So placing the close paren after the conditional woudl result in: 'NextLineOfCode())'. + // + // However, the user intent is likely that NextLineOfCode is not part of the conditional + // So instead find the colon and place the close paren after that, producing: + // + // var s3 = $""Text1 { (true ? ""Text2"":) + // NextLineOfCode(); var endToken = sourceText.AreOnSameLine(conditional.ColonToken, conditional.WhenFalse.GetFirstToken()) ? conditional.WhenFalse.GetLastToken() From 88943118198a3a3b20bcf497ccdce1b7751b8619 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 21 Jul 2021 23:33:22 -0700 Subject: [PATCH 35/45] Update tests --- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 69 +++++++++---------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 5ac9e96535deb..3423153a377f7 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -4,10 +4,7 @@ #nullable disable -using Microsoft.CodeAnalysis.CSharp.Symbols; -using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; -using Microsoft.CodeAnalysis.Text; using Roslyn.Test.Utilities; using Xunit; @@ -448,7 +445,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string1() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1() { var test = @" public class Test @@ -464,7 +461,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string2() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2() { var test = @" public class Test @@ -484,7 +481,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string3() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3() { var test = @" public class Test @@ -504,7 +501,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string4() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString4() { var test = @" public class Test @@ -525,7 +522,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string5() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString5() { var test = @" public class Test @@ -545,7 +542,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string6() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString6() { var test = @" public class Test @@ -566,7 +563,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string7() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString7() { var test = @" public class Test @@ -588,7 +585,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string8() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString8() { var test = @" public class Test @@ -609,7 +606,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string9() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString9() { var test = @" public class Test @@ -630,7 +627,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string10() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString10() { var test = @" public class Test @@ -651,7 +648,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string11() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString11() { var test = @" public class Test @@ -670,7 +667,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string12() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString12() { var test = @" public class Test @@ -704,7 +701,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string13() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString13() { var test = @" public class Test @@ -739,7 +736,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string14() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString14() { var test = @" public class Test @@ -755,7 +752,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string15() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString15() { var test = @" public class Test @@ -775,7 +772,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string16() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString16() { var test = @" public class Test @@ -799,7 +796,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string17() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString17() { var test = @" public class Test @@ -815,7 +812,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string18() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString18() { var test = @" public class Test @@ -835,7 +832,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string19() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString19() { var test = @" public class Test @@ -858,7 +855,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string20() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString20() { var test = @" public class Test @@ -878,7 +875,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string21() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString21() { var test = @" public class Test @@ -898,7 +895,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string22() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString22() { var test = @" public class Test @@ -923,7 +920,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string23() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString23() { var test = @" public class Test @@ -945,7 +942,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string24() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString24() { var test = @" public class Test @@ -967,7 +964,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string25() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString25() { var test = @" public class Test @@ -990,7 +987,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string26() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString26() { var test = @" public class Test @@ -1013,7 +1010,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string27() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString27() { var test = @" public class Test @@ -1033,7 +1030,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string28() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString28() { var test = @" public class Test @@ -1058,7 +1055,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string29() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString29() { var test = @" public class Test @@ -1080,7 +1077,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string30() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString30() { var test = @" public class Test @@ -1103,7 +1100,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string31() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString31() { var test = @" public class Test @@ -1129,7 +1126,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string32() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString32() { var test = @" public class Test @@ -1152,7 +1149,7 @@ public static int Main() } [Fact] - public void CS9000ERR_Newlines_are_not_allowed_inside_a_non_verbatim_interpolated_string33() + public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString33() { var test = @" public class Test From d2b4a319852cad6b08b2fae34c030f933ae5d826 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 21 Jul 2021 23:34:07 -0700 Subject: [PATCH 36/45] Update tests --- .../Test/Syntax/LexicalAndXml/LexicalErrorTests.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 3423153a377f7..1d27c834607d4 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -475,7 +475,7 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,28): error CS9001: Newline is not allowed inside a non-verbatim interpolated string + // (6,28): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { @" " Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 28)); } @@ -536,7 +536,7 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string + // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } @@ -557,7 +557,7 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string + // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } @@ -579,7 +579,7 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS9001: Newline is not allowed inside a non-verbatim interpolated string + // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } @@ -826,7 +826,7 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,37): error CS9001: Newline is not allowed inside a non-verbatim interpolated string + // (6,37): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); } @@ -849,7 +849,7 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), - // (6,37): error CS9001: Newline is not allowed inside a non-verbatim interpolated string + // (6,37): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); } From 90e87cac4e4b24c02ae24114e9486b0512b6c9e0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 21 Jul 2021 23:39:32 -0700 Subject: [PATCH 37/45] NRTenable --- ...itionalExpressionInInterpolatedStringCodeFixProviderTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs index 726f124376402..bf9524ba2e24a 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.Threading.Tasks; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.CSharp.CodeFixes.ConditionalExpressionInStringInterpolation; From 59e158d6cbd4b92917e4f433d4c82b36e798dbef Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 21 Jul 2021 23:59:14 -0700 Subject: [PATCH 38/45] Tweak how we do errors. --- .../Portable/Parser/Lexer_StringLiteral.cs | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 1978afd463a1a..68248b8ba6f15 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -227,20 +227,7 @@ internal void ScanInterpolatedStringLiteralTop( { var subScanner = new InterpolatedStringScanner(this, isVerbatim); subScanner.ScanInterpolatedStringLiteralTop(interpolations, ref info, out closeQuoteMissing); - - // if there are two syntax errors reported, then notify the user of the one earliest in the file. - if (subScanner.UnrecoverableError != null && subScanner.RecoverableError != null) - { - error = subScanner.UnrecoverableError.Offset <= subScanner.RecoverableError.Offset - ? subScanner.UnrecoverableError - : subScanner.RecoverableError; - } - else - { - // otherwise, just return any syntax error we might have. - error = subScanner.UnrecoverableError ?? subScanner.RecoverableError; - } - + error = subScanner.Error; info.Text = TextWindow.GetText(intern: false); } @@ -293,13 +280,10 @@ private class InterpolatedStringScanner /// good strategy to get back on track. This happens when we see things in the interpolation we truly do /// not know what to do with, or when we find we've gotten into an unbalanced state with the bracket pairs /// we're consuming. In this case, we will often choose to bail out rather than go on and potentially make - /// things worse. The second (), still indicates that the user code is wrong, - /// however we don't need to stop processing. + /// things worse. /// - public SyntaxDiagnosticInfo? UnrecoverableError; - - /// - public SyntaxDiagnosticInfo? RecoverableError; + public SyntaxDiagnosticInfo? Error; + private bool EncounteredUnrecoverableError; public InterpolatedStringScanner( Lexer lexer, @@ -323,6 +307,25 @@ private bool IsAtEnd(bool allowNewline) (ch == SlidingTextWindow.InvalidCharacter && _lexer.TextWindow.IsReallyAtEnd()); } + private void TrySetUnrecoverableError(SyntaxDiagnosticInfo error) + { + // only need to record the first error we hit + Error ??= error; + + // No matter what, ensure that we know we hit an error we can't recover from. + EncounteredUnrecoverableError = true; + } + + private void TrySetRecoverableError(SyntaxDiagnosticInfo error) + { + // only need to record the first error we hit + Error ??= error; + + // Do not touch 'EncounteredUnrecoverableError'. If we already encountered something unrecoverable, + // that doesn't change. And if we haven't hit something unrecoverable then we stay in that mode as this + // is a recoverable error. + } + internal void ScanInterpolatedStringLiteralTop(ArrayBuilder? interpolations, ref TokenInfo info, out bool closeQuoteMissing) { if (_isVerbatim) @@ -347,11 +350,8 @@ internal void ScanInterpolatedStringLiteralTop(ArrayBuilder? inte if (_lexer.TextWindow.PeekChar() != '"') { Debug.Assert(IsAtEnd()); - if (UnrecoverableError == null) - { - int position = IsAtEnd(allowNewline: true) ? _lexer.TextWindow.Position - 1 : _lexer.TextWindow.Position; - UnrecoverableError = _lexer.MakeError(position, 1, _isVerbatim ? ErrorCode.ERR_UnterminatedStringLit : ErrorCode.ERR_NewlineInConst); - } + int position = IsAtEnd(allowNewline: true) ? _lexer.TextWindow.Position - 1 : _lexer.TextWindow.Position; + TrySetUnrecoverableError(_lexer.MakeError(position, 1, _isVerbatim ? ErrorCode.ERR_UnterminatedStringLit : ErrorCode.ERR_NewlineInConst)); closeQuoteMissing = true; } @@ -402,7 +402,7 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder? } else { - UnrecoverableError ??= _lexer.MakeError(pos, 1, ErrorCode.ERR_UnescapedCurly, "}"); + TrySetUnrecoverableError(_lexer.MakeError(pos, 1, ErrorCode.ERR_UnescapedCurly, "}")); } continue; case '{': @@ -426,7 +426,7 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder? else { closeBraceMissing = true; - UnrecoverableError ??= _lexer.MakeError(openBracePosition - 1, 2, ErrorCode.ERR_UnclosedExpressionHole); + TrySetUnrecoverableError(_lexer.MakeError(openBracePosition - 1, 2, ErrorCode.ERR_UnclosedExpressionHole)); } interpolations?.Add(new Interpolation(openBracePosition, colonPosition, closeBracePosition, closeBraceMissing)); @@ -442,7 +442,7 @@ private void ScanInterpolatedStringLiteralContents(ArrayBuilder? char ch = _lexer.ScanEscapeSequence(surrogateCharacter: out _); if (ch == '{' || ch == '}') { - UnrecoverableError ??= _lexer.MakeError(escapeStart, _lexer.TextWindow.Position - escapeStart, ErrorCode.ERR_EscapedCurly, ch); + TrySetUnrecoverableError(_lexer.MakeError(escapeStart, _lexer.TextWindow.Position - escapeStart, ErrorCode.ERR_EscapedCurly, ch)); } continue; @@ -468,7 +468,7 @@ private void ScanFormatSpecifier() ch = _lexer.ScanEscapeSequence(surrogateCharacter: out _); if (ch == '{' || ch == '}') { - UnrecoverableError ??= _lexer.MakeError(pos, 1, ErrorCode.ERR_EscapedCurly, ch); + TrySetUnrecoverableError(_lexer.MakeError(pos, 1, ErrorCode.ERR_EscapedCurly, ch)); } } else if (ch == '"') @@ -494,7 +494,7 @@ private void ScanFormatSpecifier() } else { - UnrecoverableError ??= _lexer.MakeError(pos, 1, ErrorCode.ERR_UnescapedCurly, "{"); + TrySetUnrecoverableError(_lexer.MakeError(pos, 1, ErrorCode.ERR_UnescapedCurly, "{")); } } else if (ch == '}') @@ -535,7 +535,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool var allowNewLines = _isVerbatim && _allowNewlines; if (!allowNewLines && SyntaxFacts.IsNewLine(ch)) { - RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString); + TrySetRecoverableError(_lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString)); } if (IsAtEnd(allowNewline: true)) @@ -548,7 +548,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { case '#': // preprocessor directives not allowed. - UnrecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); + TrySetUnrecoverableError(_lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString())); _lexer.TextWindow.AdvanceChar(); continue; case '$': @@ -593,7 +593,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool return; } - UnrecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString()); + TrySetUnrecoverableError(_lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_SyntaxError, endingChar.ToString())); goto default; case '"' when RecoveringFromRunawayLexing(): // When recovering from mismatched delimiters, we consume the next @@ -621,7 +621,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool var errorCode = _lexer.ScanVerbatimStringLiteral(ref discarded, _allowNewlines); if (errorCode is ErrorCode code) { - RecoverableError ??= _lexer.MakeError(nestedStringPosition, width: 2, code); + TrySetRecoverableError(_lexer.MakeError(nestedStringPosition, width: 2, code)); } continue; @@ -656,7 +656,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { // error: single-line comment not allowed in an interpolated string. // report the error but keep going for good error recovery. - RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, 2, ErrorCode.ERR_SingleLineCommentInExpressionHole); + TrySetRecoverableError(_lexer.MakeError(_lexer.TextWindow.Position, 2, ErrorCode.ERR_SingleLineCommentInExpressionHole)); } _lexer.TextWindow.AdvanceChar(); // skip / @@ -698,9 +698,9 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool /// /// The lexer can run away consuming the rest of the input when delimiters are mismatched. This is a test /// for when we are attempting to recover from that situation. Note that just running into new lines will - /// not make us thing we're in runaway lexing (which is why we ignore here). + /// not make us think we're in runaway lexing. /// - private bool RecoveringFromRunawayLexing() => this.UnrecoverableError != null; + private bool RecoveringFromRunawayLexing() => this.EncounteredUnrecoverableError; private void ScanInterpolatedStringLiteralNestedComment() { @@ -718,7 +718,7 @@ private void ScanInterpolatedStringLiteralNestedComment() var allowNewLines = _isVerbatim && _allowNewlines; if (!allowNewLines && SyntaxFacts.IsNewLine(ch)) { - RecoverableError ??= _lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString); + TrySetRecoverableError(_lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString)); } if (IsAtEnd(allowNewline: true)) From 7429a218977733c04ce1eeb4e4859ffbf41429b7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 22 Jul 2021 01:11:30 -0700 Subject: [PATCH 39/45] nrt --- ...itionalExpressionInInterpolatedStringCodeFixProviderTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs index bf9524ba2e24a..e68b9754aa7f8 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/ConditionalExpressionInStringInterpolation/CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProviderTests.cs @@ -19,7 +19,7 @@ public CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFi { } - internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace) + internal override (DiagnosticAnalyzer?, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace) => (null, new CSharpAddParenthesesAroundConditionalExpressionInInterpolatedStringCodeFixProvider()); private async Task TestInMethodAsync(string initialMethodBody, string expectedMethodBody) From 73886488b0748e96fc8c84a0b8308fbd6c453481 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 22 Jul 2021 09:47:41 -0700 Subject: [PATCH 40/45] Always pick the earliest error --- .../CSharp/Portable/Parser/Lexer_StringLiteral.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 68248b8ba6f15..34fd6f4c56a82 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -309,8 +309,9 @@ private bool IsAtEnd(bool allowNewline) private void TrySetUnrecoverableError(SyntaxDiagnosticInfo error) { - // only need to record the first error we hit - Error ??= error; + // only need to record the earliest error we hit + if (Error == null || error.Offset < Error.Offset) + Error = error; // No matter what, ensure that we know we hit an error we can't recover from. EncounteredUnrecoverableError = true; @@ -318,8 +319,9 @@ private void TrySetUnrecoverableError(SyntaxDiagnosticInfo error) private void TrySetRecoverableError(SyntaxDiagnosticInfo error) { - // only need to record the first error we hit - Error ??= error; + // only need to record the earliest error we hit + if (Error == null || error.Offset < Error.Offset) + Error = error; // Do not touch 'EncounteredUnrecoverableError'. If we already encountered something unrecoverable, // that doesn't change. And if we haven't hit something unrecoverable then we stay in that mode as this From e8364d0a0a8fc01b67620fc8408cf650c9e702eb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 22 Jul 2021 10:11:24 -0700 Subject: [PATCH 41/45] Change code --- .../CSharp/Portable/Errors/ErrorCode.cs | 2 +- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 110 +++++++++--------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index fe07b639a0c04..bef1a70fd0ee3 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1981,7 +1981,7 @@ internal enum ErrorCode ERR_FileScopedAndNormalNamespace = 8955, ERR_FileScopedNamespaceNotBeforeAllMembers = 8956, ERR_NoImplicitConvTargetTypedConditional = 8957, - ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString = 8958, + ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString = 8959, #endregion diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 1d27c834607d4..310248c42e22d 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -445,7 +445,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1() { var test = @" public class Test @@ -461,7 +461,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2() { var test = @" public class Test @@ -475,13 +475,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,28): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,28): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { @" " Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 28)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3() { var test = @" public class Test @@ -501,7 +501,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString4() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString4() { var test = @" public class Test @@ -522,7 +522,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString5() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString5() { var test = @" public class Test @@ -536,13 +536,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,23): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString6() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString6() { var test = @" public class Test @@ -557,13 +557,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,23): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString7() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString7() { var test = @" public class Test @@ -579,13 +579,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,23): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString8() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString8() { var test = @" public class Test @@ -606,7 +606,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString9() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString9() { var test = @" public class Test @@ -627,7 +627,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString10() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString10() { var test = @" public class Test @@ -648,7 +648,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString11() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString11() { var test = @" public class Test @@ -667,7 +667,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString12() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString12() { var test = @" public class Test @@ -701,7 +701,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString13() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString13() { var test = @" public class Test @@ -736,7 +736,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString14() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString14() { var test = @" public class Test @@ -752,7 +752,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString15() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString15() { var test = @" public class Test @@ -766,13 +766,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,37): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,37): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString16() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString16() { var test = @" public class Test @@ -787,7 +787,7 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,26): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26), // (8,29): error CS1733: Expected expression @@ -796,7 +796,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString17() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString17() { var test = @" public class Test @@ -812,7 +812,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString18() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString18() { var test = @" public class Test @@ -826,13 +826,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,37): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,37): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString19() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString19() { var test = @" public class Test @@ -849,13 +849,13 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), - // (6,37): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,37): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString20() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString20() { var test = @" public class Test @@ -869,13 +869,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,39): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,39): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ 0 Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 39)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString21() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString21() { var test = @" public class Test @@ -889,13 +889,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,37): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,37): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString22() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString22() { var test = @" public class Test @@ -914,13 +914,13 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { /* Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), - // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,26): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString23() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString23() { var test = @" public class Test @@ -936,13 +936,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,26): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString24() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString24() { var test = @" public class Test @@ -958,13 +958,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,26): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString25() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString25() { var test = @" public class Test @@ -981,13 +981,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,26): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,26): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { /* Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString26() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString26() { var test = @" public class Test @@ -1001,7 +1001,7 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,23): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23), // (6,23): error CS1733: Expected expression @@ -1010,7 +1010,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString27() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString27() { var test = @" public class Test @@ -1024,13 +1024,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,23): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString28() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString28() { var test = @" public class Test @@ -1046,7 +1046,7 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,23): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23), // (6,23): error CS1733: Expected expression @@ -1055,7 +1055,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString29() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString29() { var test = @" public class Test @@ -1071,13 +1071,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,23): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString30() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString30() { var test = @" public class Test @@ -1094,13 +1094,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,23): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString31() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString31() { var test = @" public class Test @@ -1117,7 +1117,7 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,23): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23), // (6,23): error CS1733: Expected expression @@ -1126,7 +1126,7 @@ public static int Main() } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString32() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString32() { var test = @" public class Test @@ -1143,13 +1143,13 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,23): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } [Fact] - public void CS8958ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString33() + public void CS8959ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString33() { var test = @" public class Test @@ -1167,7 +1167,7 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + // (6,23): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string // string s = $"x { Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); } From 7e3d7fb4d677dbfafe6508b45016b5f3d3a556f4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 22 Jul 2021 11:10:19 -0700 Subject: [PATCH 42/45] Go back to old behavior --- .../CSharp/Portable/Parser/Lexer_StringLiteral.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 34fd6f4c56a82..68248b8ba6f15 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -309,9 +309,8 @@ private bool IsAtEnd(bool allowNewline) private void TrySetUnrecoverableError(SyntaxDiagnosticInfo error) { - // only need to record the earliest error we hit - if (Error == null || error.Offset < Error.Offset) - Error = error; + // only need to record the first error we hit + Error ??= error; // No matter what, ensure that we know we hit an error we can't recover from. EncounteredUnrecoverableError = true; @@ -319,9 +318,8 @@ private void TrySetUnrecoverableError(SyntaxDiagnosticInfo error) private void TrySetRecoverableError(SyntaxDiagnosticInfo error) { - // only need to record the earliest error we hit - if (Error == null || error.Offset < Error.Offset) - Error = error; + // only need to record the first error we hit + Error ??= error; // Do not touch 'EncounteredUnrecoverableError'. If we already encountered something unrecoverable, // that doesn't change. And if we haven't hit something unrecoverable then we stay in that mode as this From 04886a5b4706d61e22e793ba72c04165aa6e2346 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 22 Jul 2021 11:12:07 -0700 Subject: [PATCH 43/45] Update tests --- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 310248c42e22d..6eaf42874fb5b 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -680,12 +680,12 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. - // string s = $"x { /* comment } y"; - Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), // (6,24): error CS1035: End-of-file found, '*/' expected // string s = $"x { /* comment } y"; Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(6, 24), + // (6,40): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string + // string s = $"x { /* comment } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 40), // (9,1): error CS1733: Expected expression // Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(9, 1), @@ -715,24 +715,24 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. - // string s = $"x { /* comment - Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), - // (6,24): error CS1035: End-of-file found, '*/' expected - // string s = $"x { /* comment - Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(6, 24), - // (10,1): error CS1733: Expected expression - // - Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(10, 1), - // (10,1): error CS1002: ; expected - // - Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(10, 1), - // (10,1): error CS1513: } expected - // - Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(10, 1), - // (10,1): error CS1513: } expected - // - Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(10, 1)); + // (6,24): error CS1035: End-of-file found, '*/' expected + // string s = $"x { /* comment + Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(6, 24), + // (6,34): error CS8959: Newlines are not allowed inside a non-verbatim interpolated string + // string s = $"x { /* comment + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 34), + // (10,1): error CS1733: Expected expression + // + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(10, 1), + // (10,1): error CS1002: ; expected + // + Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(10, 1), + // (10,1): error CS1513: } expected + // + Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(10, 1), + // (10,1): error CS1513: } expected + // + Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(10, 1)); } [Fact] From 27be66d041b4d81cf2bb3f34305270dae1ffdf39 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sat, 24 Jul 2021 20:52:50 -0700 Subject: [PATCH 44/45] Fix test --- .../CSharp/Test/Semantic/Semantics/InterpolationTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index 98e818f0637a8..a0dd998871212 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -188,12 +188,12 @@ public static void Main(string[] args) }"; // too many diagnostics perhaps, but it starts the right way. CreateCompilationWithMscorlib45(source).VerifyDiagnostics( - // (5,60): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. - // Console.WriteLine($"Jenny don\'t change your number { 8675309 /* "); - Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(5, 60), // (5,71): error CS1035: End-of-file found, '*/' expected // Console.WriteLine($"Jenny don\'t change your number { 8675309 /* "); Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(5, 71), + // (5,77): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string + // Console.WriteLine($"Jenny don\'t change your number { 8675309 /* "); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(5, 77), // (7,2): error CS1026: ) expected // } Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(7, 2), From a0e35ea51ebe287704c3973d20643629a94139fb Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sat, 24 Jul 2021 21:45:39 -0700 Subject: [PATCH 45/45] Adjust test baseline for `CSharpAddMissingUsingsOnPaste.VerifyDisabledWithNull` --- .../IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs index c989728db5b4d..375446a46d1f5 100644 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs +++ b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpAddMissingUsingsOnPaste.cs @@ -85,6 +85,7 @@ static void Main(string[] args) VisualStudio.Editor.Verify.TextContains(@" using System; +using System.Threading.Tasks; class Program {