From 8ed75ec8dd7984bfa3b46b1b52972536715b9113 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 29 Sep 2021 11:08:52 -0700 Subject: [PATCH 01/21] Allow newlines in the holes inside interpolated strings --- .../CSharp/Portable/Errors/ErrorCode.cs | 6 +- src/Compilers/CSharp/Portable/Parser/Lexer.cs | 2 +- .../Portable/Parser/Lexer_StringLiteral.cs | 63 ++++--------------- 3 files changed, 17 insertions(+), 54 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 21d55131f01bf..1e1211c7f729f 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1308,7 +1308,8 @@ internal enum ErrorCode ERR_DictionaryInitializerInExpressionTree = 8074, ERR_ExtensionCollectionElementInitializerInExpressionTree = 8075, ERR_UnclosedExpressionHole = 8076, - ERR_SingleLineCommentInExpressionHole = 8077, + // It is now legal to have single line comments in expression holes. + // ERR_SingleLineCommentInExpressionHole = 8077, ERR_InsufficientStack = 8078, ERR_UseDefViolationProperty = 8079, ERR_AutoPropertyMustOverrideSet = 8080, @@ -1990,7 +1991,8 @@ internal enum ErrorCode ERR_BadCallerArgumentExpressionParamWithoutDefaultValue = 8964, WRN_CallerArgumentExpressionAttributeSelfReferential = 8965, WRN_CallerArgumentExpressionParamForUnconsumedLocation = 8966, - ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString = 8967, + // It is now legal to have newlines in expression holes. + // ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString = 8967, ERR_AttrTypeArgCannotBeTypeVar = 8968, // WRN_AttrDependentTypeNotAllowed = 8969, // Backed out of of warning wave 6, may be reintroduced later ERR_AttrDependentTypeNotAllowed = 8970, diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer.cs b/src/Compilers/CSharp/Portable/Parser/Lexer.cs index 25b34610e5786..14e41b0771db9 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer.cs @@ -764,7 +764,7 @@ private void ScanSyntaxToken(ref TokenInfo info) case '@': if (TextWindow.PeekChar(1) == '"') { - var errorCode = this.ScanVerbatimStringLiteral(ref info, allowNewlines: true); + var errorCode = this.ScanVerbatimStringLiteral(ref info); if (errorCode is ErrorCode code) this.AddError(code); } diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 68248b8ba6f15..87e1ec9ab299d 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -146,7 +146,7 @@ private char ScanEscapeSequence(out char surrogateCharacter) /// /// Returns an appropriate error code if scanning this verbatim literal ran into an error. /// - private ErrorCode? ScanVerbatimStringLiteral(ref TokenInfo info, bool allowNewlines) + private ErrorCode? ScanVerbatimStringLiteral(ref TokenInfo info) { _builder.Length = 0; @@ -180,14 +180,6 @@ private char ScanEscapeSequence(out char surrogateCharacter) 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 ??= ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString; - } - TextWindow.AdvanceChar(); _builder.Append(ch); } @@ -272,7 +264,6 @@ private class InterpolatedStringScanner { private readonly Lexer _lexer; private bool _isVerbatim; - private bool _allowNewlines; /// /// There are two types of errors we can encounter when trying to scan out an interpolated string (and its @@ -285,18 +276,15 @@ private class InterpolatedStringScanner public SyntaxDiagnosticInfo? Error; private bool EncounteredUnrecoverableError; - public InterpolatedStringScanner( - Lexer lexer, - bool isVerbatim) + public InterpolatedStringScanner(Lexer lexer, bool isVerbatim) { _lexer = lexer; _isVerbatim = isVerbatim; - _allowNewlines = isVerbatim; } private bool IsAtEnd() { - return IsAtEnd(_isVerbatim && _allowNewlines); + return IsAtEnd(_isVerbatim); } private bool IsAtEnd(bool allowNewline) @@ -529,15 +517,8 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { char ch = _lexer.TextWindow.PeekChar(); - // 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)) - { - TrySetRecoverableError(_lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString)); - } - + // Note: within a hole new-lines are always allowed. The retriction on if new-lines are allowed or not + // is only within a text-portion of the interpolated stirng. if (IsAtEnd(allowNewline: true)) { // the caller will complain @@ -558,17 +539,14 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool var interpolations = (ArrayBuilder?)null; var info = default(TokenInfo); bool wasVerbatim = _isVerbatim; - bool wasAllowNewlines = _allowNewlines; try { _isVerbatim = isVerbatimSubstring; - _allowNewlines &= _isVerbatim; ScanInterpolatedStringLiteralTop(interpolations, ref info, closeQuoteMissing: out _); } finally { _isVerbatim = wasVerbatim; - _allowNewlines = wasAllowNewlines; } continue; } @@ -618,7 +596,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool // 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); + var errorCode = _lexer.ScanVerbatimStringLiteral(ref discarded); if (errorCode is ErrorCode code) { TrySetRecoverableError(_lexer.MakeError(nestedStringPosition, width: 2, code)); @@ -632,17 +610,14 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool var interpolations = (ArrayBuilder?)null; var info = default(TokenInfo); bool wasVerbatim = _isVerbatim; - bool wasAllowNewlines = _allowNewlines; try { _isVerbatim = true; - _allowNewlines = true; ScanInterpolatedStringLiteralTop(interpolations, ref info, closeQuoteMissing: out _); } finally { _isVerbatim = wasVerbatim; - _allowNewlines = wasAllowNewlines; } continue; } @@ -652,15 +627,10 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool switch (_lexer.TextWindow.PeekChar(1)) { case '/': - if (!_isVerbatim || !_allowNewlines) - { - // error: single-line comment not allowed in an interpolated string. - // report the error but keep going for good error recovery. - TrySetRecoverableError(_lexer.MakeError(_lexer.TextWindow.Position, 2, ErrorCode.ERR_SingleLineCommentInExpressionHole)); - } - _lexer.TextWindow.AdvanceChar(); // skip / _lexer.TextWindow.AdvanceChar(); // skip / + + // read up to the end of the line. while (!IsAtEnd(allowNewline: false)) { _lexer.TextWindow.AdvanceChar(); // skip // comment character @@ -710,26 +680,17 @@ private void ScanInterpolatedStringLiteralNestedComment() _lexer.TextWindow.AdvanceChar(); while (true) { - var ch = _lexer.TextWindow.PeekChar(); - - // 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)) - { - TrySetRecoverableError(_lexer.MakeError(_lexer.TextWindow.Position, width: 0, ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString)); - } - if (IsAtEnd(allowNewline: true)) { - return; // let the caller complain about the unterminated quote + this.TrySetUnrecoverableError(_lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_OpenEndedComment)); + return; } + var ch = _lexer.TextWindow.PeekChar(); _lexer.TextWindow.AdvanceChar(); if (ch == '*' && _lexer.TextWindow.PeekChar() == '/') { - _lexer.TextWindow.AdvanceChar(); // skip */ + _lexer.TextWindow.AdvanceChar(); return; } } From fe7c2d9f1559e893c46d722ab8fd474e6f84e42a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 29 Sep 2021 11:25:34 -0700 Subject: [PATCH 02/21] Update tests --- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 189 +++++------------- 1 file changed, 48 insertions(+), 141 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 938b22eb194e6..f117d3fc28a1e 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -474,10 +474,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,28): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { @" " - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 28)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -494,10 +491,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_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, @"@""").WithLocation(6, 24)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -515,10 +509,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_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, @"@""").WithLocation(6, 24)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -535,10 +526,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -556,10 +544,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -578,10 +563,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -599,10 +581,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_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, @"@""").WithLocation(6, 24)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -620,10 +599,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_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, @"@""").WithLocation(6, 24)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -641,10 +617,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_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, @"@""").WithLocation(6, 30)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -683,9 +656,9 @@ public static int Main() // (6,24): error CS1035: End-of-file found, '*/' expected // string s = $"x { /* comment } y"; Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(6, 24), - // (6,40): error CS8967: 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 CS1035: End-of-file found, '*/' expected + // + Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(9, 1), // (9,1): error CS1733: Expected expression // Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(9, 1), @@ -715,24 +688,24 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,24): error CS1035: End-of-file found, '*/' expected - // string s = $"x { /* comment - Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(6, 24), - // (6,34): error CS8967: 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)); + // (6,24): error CS1035: End-of-file found, '*/' expected + // string s = $"x { /* comment + Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(6, 24), + // (10,1): error CS1035: End-of-file found, '*/' expected + // + Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(10, 1), + // (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] @@ -765,10 +738,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,37): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -787,9 +757,6 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,26): error CS8967: 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 // */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29)); @@ -825,10 +792,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,37): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -848,10 +812,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS1733: Expected expression // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), - // (6,37): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] @@ -868,10 +829,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,39): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { /* comment */ 0 - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 39)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -888,10 +846,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,37): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { /* comment */ - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -913,10 +868,7 @@ public static int Main() ParserErrorMessageTests.ParseAndValidate(test, // (6,23): error CS1733: Expected expression // string s = $"x { /* - Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23), - // (6,26): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { /* - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26)); + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] @@ -935,10 +887,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,26): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { /* - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -957,10 +906,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,26): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { /* - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -980,10 +926,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,26): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { /* - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -1001,9 +944,6 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8967: 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 // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); @@ -1023,10 +963,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -1046,9 +983,6 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8967: 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 // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); @@ -1070,10 +1004,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -1093,10 +1024,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -1117,9 +1045,6 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8967: 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 // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); @@ -1142,10 +1067,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -1166,10 +1088,7 @@ public static int Main() } "; - ParserErrorMessageTests.ParseAndValidate(test, - // (6,23): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // string s = $"x { - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23)); + ParserErrorMessageTests.ParseAndValidate(test); } [Fact] @@ -1189,10 +1108,7 @@ public static int Main() 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)); + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] @@ -1232,10 +1148,7 @@ public static int Main() 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)); + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29)); } [Fact] @@ -1253,10 +1166,7 @@ public static int Main() } "; - 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] @@ -1292,10 +1202,7 @@ public static int Main() } "; - 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)); + ParserErrorMessageTests.ParseAndValidate(test); } #endregion From 10a0fb5e000734e5bb1e37facbc6b816de318dd0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 29 Sep 2021 11:30:46 -0700 Subject: [PATCH 03/21] Update tests --- .../Semantic/Semantics/InterpolationTests.cs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index 22f04c9785150..b8b044f1b2dee 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -132,9 +132,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 CS8967: Newlines are not allowed inside a non-verbatim interpolated string - // Console.WriteLine($"Jenny don\'t change your number { "); - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(5, 66), + // (6,5): error CS1010: Newline in constant + // } + Diagnostic(ErrorCode.ERR_NewlineInConst, "}").WithLocation(6, 5), // (6,6): error CS1026: ) expected // } Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(6, 6), @@ -159,9 +159,9 @@ public static void Main(string[] args) }"; // too many diagnostics perhaps, but it starts the right way. 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), + // (6,5): error CS1010: Newline in constant + // } + Diagnostic(ErrorCode.ERR_NewlineInConst, "}").WithLocation(6, 5), // (6,6): error CS1026: ) expected // } Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(6, 6), @@ -189,9 +189,9 @@ public static void Main(string[] args) // (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 CS1035: End-of-file found, '*/' expected + // } + Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(7, 2), // (7,2): error CS1026: ) expected // } Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(7, 2), @@ -358,12 +358,13 @@ static void Main(string[] args) Console.WriteLine( $""{"" ); } }"; - CreateCompilationWithMscorlib45(source).VerifyDiagnostics( // (6,31): error CS1010: Newline in constant - // Console.WriteLine( $"{" ); - Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(6, 31), - // (6,35): error CS8958: Newlines are not allowed inside a non-verbatim interpolated string + CreateCompilationWithMscorlib45(source).VerifyDiagnostics( + // (6,31): error CS1010: Newline in constant // Console.WriteLine( $"{" ); - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 35), + Diagnostic(ErrorCode.ERR_NewlineInConst, "").WithLocation(6, 31), + // (7,5): error CS1010: Newline in constant + // } + Diagnostic(ErrorCode.ERR_NewlineInConst, "}").WithLocation(7, 5), // (7,6): error CS1026: ) expected // } Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(7, 6), From 06afc0b667be2157605da7f1aa4cd6527c8206dd Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 29 Sep 2021 11:48:39 -0700 Subject: [PATCH 04/21] Remove unnecessary extra error --- .../CSharp/Portable/Parser/Lexer_StringLiteral.cs | 9 ++++++--- .../Test/Semantic/Semantics/InterpolationTests.cs | 6 +++--- .../Test/Syntax/LexicalAndXml/LexicalErrorTests.cs | 12 ++++++------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 87e1ec9ab299d..1bf776f903fa9 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -674,17 +674,20 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool private void ScanInterpolatedStringLiteralNestedComment() { + var start = _lexer.TextWindow.Position; Debug.Assert(_lexer.TextWindow.PeekChar() == '/'); _lexer.TextWindow.AdvanceChar(); Debug.Assert(_lexer.TextWindow.PeekChar() == '*'); _lexer.TextWindow.AdvanceChar(); while (true) { + // Note: if we reach the end of the file without hitting */ just bail out. It's not necessary for + // us to report any issues, as this code is just being used to find the end of teh interpolation hole. + // When the full parse happens, the lexer will grab the string inside the interpolation hole and + // pass it to the regular parser. This parser will then see the unterminated /* and will report the + // error for it. if (IsAtEnd(allowNewline: true)) - { - this.TrySetUnrecoverableError(_lexer.MakeError(_lexer.TextWindow.Position, 1, ErrorCode.ERR_OpenEndedComment)); return; - } var ch = _lexer.TextWindow.PeekChar(); _lexer.TextWindow.AdvanceChar(); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index b8b044f1b2dee..2a14a7d188208 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -186,12 +186,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), - // (7,2): error CS1035: End-of-file found, '*/' expected - // } - Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(7, 2), // (7,2): error CS1026: ) expected // } Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(7, 2), diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index f117d3fc28a1e..652759b775413 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -653,12 +653,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), - // (9,1): error CS1035: End-of-file found, '*/' expected - // - Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(9, 1), // (9,1): error CS1733: Expected expression // Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(9, 1), @@ -688,12 +688,12 @@ 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 CS1035: End-of-file found, '*/' expected - // - Diagnostic(ErrorCode.ERR_OpenEndedComment, "").WithLocation(10, 1), // (10,1): error CS1733: Expected expression // Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(10, 1), From 3a8f99b588f801c5bedb171b423977339dac5291 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 29 Sep 2021 11:49:02 -0700 Subject: [PATCH 05/21] Use simple using --- .../LanguageParser_InterpolatedString.cs | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs index ed046c1072696..ad60f7d1563da 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs @@ -171,29 +171,28 @@ private InterpolationSyntax ParseInterpolation(string text, Lexer.Interpolation using (var tempLexer = new Lexer(Text.SourceText.From(parsedText), this.Options, allowPreprocessorDirectives: false, interpolationFollowedByColon: interpolation.HasColon)) { // TODO: some of the trivia in the interpolation maybe should be trailing trivia of the openBraceToken - using (var tempParser = new LanguageParser(tempLexer, null, null)) + using var tempParser = new LanguageParser(tempLexer, null, null); + + SyntaxToken commaToken = null; + ExpressionSyntax alignmentExpression = null; + tempParser.ParseInterpolationStart(out openBraceToken, out expression, out commaToken, out alignmentExpression); + if (alignmentExpression != null) { - SyntaxToken commaToken = null; - ExpressionSyntax alignmentExpression = null; - tempParser.ParseInterpolationStart(out openBraceToken, out expression, out commaToken, out alignmentExpression); - if (alignmentExpression != null) - { - alignment = SyntaxFactory.InterpolationAlignmentClause(commaToken, alignmentExpression); - } + alignment = SyntaxFactory.InterpolationAlignmentClause(commaToken, alignmentExpression); + } - var extraTrivia = tempParser.CurrentToken.GetLeadingTrivia(); - if (interpolation.HasColon) - { - var colonToken = SyntaxFactory.Token(SyntaxKind.ColonToken).TokenWithLeadingTrivia(extraTrivia); - var formatText = Substring(text, interpolation.ColonPosition + 1, interpolation.FormatEndPosition); - var formatString = MakeStringToken(formatText, formatText, isVerbatim, SyntaxKind.InterpolatedStringTextToken); - format = SyntaxFactory.InterpolationFormatClause(colonToken, formatString); - } - else - { - // Move the leading trivia from the insertion's EOF token to the following token. - closeBraceToken = closeBraceToken.TokenWithLeadingTrivia(extraTrivia); - } + var extraTrivia = tempParser.CurrentToken.GetLeadingTrivia(); + if (interpolation.HasColon) + { + var colonToken = SyntaxFactory.Token(SyntaxKind.ColonToken).TokenWithLeadingTrivia(extraTrivia); + var formatText = Substring(text, interpolation.ColonPosition + 1, interpolation.FormatEndPosition); + var formatString = MakeStringToken(formatText, formatText, isVerbatim, SyntaxKind.InterpolatedStringTextToken); + format = SyntaxFactory.InterpolationFormatClause(colonToken, formatString); + } + else + { + // Move the leading trivia from the insertion's EOF token to the following token. + closeBraceToken = closeBraceToken.TokenWithLeadingTrivia(extraTrivia); } } From 7dffb4b658ba6dcfad51fe9d73f2bad9bee610e3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 29 Sep 2021 11:49:36 -0700 Subject: [PATCH 06/21] Inline variables --- .../Portable/Parser/LanguageParser_InterpolatedString.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs index ad60f7d1563da..2cd6f7e098f6e 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs @@ -173,9 +173,7 @@ private InterpolationSyntax ParseInterpolation(string text, Lexer.Interpolation // TODO: some of the trivia in the interpolation maybe should be trailing trivia of the openBraceToken using var tempParser = new LanguageParser(tempLexer, null, null); - SyntaxToken commaToken = null; - ExpressionSyntax alignmentExpression = null; - tempParser.ParseInterpolationStart(out openBraceToken, out expression, out commaToken, out alignmentExpression); + tempParser.ParseInterpolationStart(out openBraceToken, out expression, out var commaToken, out var alignmentExpression); if (alignmentExpression != null) { alignment = SyntaxFactory.InterpolationAlignmentClause(commaToken, alignmentExpression); From dde9fdc77afa2cf3f343c2181f9dd8d6a96ef77a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 29 Sep 2021 11:50:13 -0700 Subject: [PATCH 07/21] Use named parameters --- .../CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs index 2cd6f7e098f6e..6fd656fa151c0 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs @@ -171,7 +171,7 @@ private InterpolationSyntax ParseInterpolation(string text, Lexer.Interpolation using (var tempLexer = new Lexer(Text.SourceText.From(parsedText), this.Options, allowPreprocessorDirectives: false, interpolationFollowedByColon: interpolation.HasColon)) { // TODO: some of the trivia in the interpolation maybe should be trailing trivia of the openBraceToken - using var tempParser = new LanguageParser(tempLexer, null, null); + using var tempParser = new LanguageParser(tempLexer, oldTree: null, changes: null); tempParser.ParseInterpolationStart(out openBraceToken, out expression, out var commaToken, out var alignmentExpression); if (alignmentExpression != null) From 61bcfbb1483f6ee4aaac9f694d579d2b147c2269 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 29 Sep 2021 12:06:09 -0700 Subject: [PATCH 08/21] Simplify --- .../CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs | 2 +- src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs index 6fd656fa151c0..ce09cb0c3b1d1 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs @@ -137,7 +137,7 @@ private ExpressionSyntax ParseInterpolatedStringToken() } // Add a token for text following the last interpolation - var lastText = Substring(originalText, interpolations[interpolations.Count - 1].CloseBracePosition + 1, closeQuoteIndex - 1); + var lastText = Substring(originalText, interpolations[^1].CloseBracePosition + 1, closeQuoteIndex - 1); if (lastText.Length > 0) { var token = MakeStringToken(lastText, lastText, isVerbatim, SyntaxKind.InterpolatedStringTextToken); diff --git a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs index 1bf776f903fa9..fa4a59f7cf355 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -674,7 +674,6 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool private void ScanInterpolatedStringLiteralNestedComment() { - var start = _lexer.TextWindow.Position; Debug.Assert(_lexer.TextWindow.PeekChar() == '/'); _lexer.TextWindow.AdvanceChar(); Debug.Assert(_lexer.TextWindow.PeekChar() == '*'); From bde11ad0a7583faa52d0c66575126c4226b0ddcb Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 14 Oct 2021 13:28:17 -0700 Subject: [PATCH 09/21] Move error to binding phase --- .../Binder/Binder_InterpolatedString.cs | 38 +++++++++ .../CSharp/Portable/CSharpResources.resx | 5 +- .../CSharp/Portable/Errors/ErrorCode.cs | 3 +- .../CSharp/Portable/Errors/MessageID.cs | 4 + .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 78 +++++++++++++++++++ 5 files changed, 125 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs b/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs index 634cd6a1ddc66..c132f502c9ef2 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs @@ -29,6 +29,10 @@ private BoundExpression BindInterpolatedString(InterpolatedStringExpressionSynta } else { + var isNonVerbatimInterpolatedString = node.StringStartToken.Kind() != SyntaxKind.InterpolatedVerbatimStringStartToken; + var newLinesInInterpolationsDiagnosticInfo = + MessageID.IDS_FeatureNewLinesInInterpolations.GetFeatureAvailabilityDiagnosticInfo((CSharpParseOptions)node.SyntaxTree.Options); + var intType = GetSpecialType(SpecialType.System_Int32, diagnostics, node); foreach (var content in node.Contents) { @@ -37,6 +41,18 @@ private BoundExpression BindInterpolatedString(InterpolatedStringExpressionSynta case SyntaxKind.Interpolation: { var interpolation = (InterpolationSyntax)content; + if (isNonVerbatimInterpolatedString && newLinesInInterpolationsDiagnosticInfo != null) + { + if (ContainsTrailingEndOflineTrivia(interpolation.OpenBraceToken) || + ContainsTrailingEndOflineTrivia(interpolation.Expression)) + { + diagnostics.Add( + ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, + interpolation.CloseBraceToken.GetLocation(), + new CSharpRequiredLanguageVersion(MessageID.IDS_FeatureNewLinesInInterpolations.RequiredVersion())); + } + } + var value = BindValue(interpolation.Expression, diagnostics, BindValueKind.RValue); // We need to ensure the argument is not a lambda, method group, etc. It isn't nice to wait until lowering, @@ -129,6 +145,28 @@ private BoundExpression BindInterpolatedString(InterpolatedStringExpressionSynta return new BoundUnconvertedInterpolatedString(node, builder.ToImmutableAndFree(), resultConstant, stringType); } + private static bool ContainsTrailingEndOflineTrivia(SyntaxNodeOrToken nodeOrToken) + { + if (nodeOrToken.IsNode) + { + foreach (var child in nodeOrToken.AsNode()!.ChildNodesAndTokens()) + { + if (ContainsTrailingEndOflineTrivia(child)) + return true; + } + } + else if (nodeOrToken.IsToken) + { + foreach (var trivia in nodeOrToken.AsToken().TrailingTrivia) + { + if (trivia.Kind() == SyntaxKind.EndOfLineTrivia) + return true; + } + } + + return false; + } + private BoundInterpolatedString BindUnconvertedInterpolatedStringToString(BoundUnconvertedInterpolatedString unconvertedInterpolatedString, BindingDiagnosticBag diagnostics) { // We have 4 possible lowering strategies, dependent on the contents of the string, in this order: diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index d3cdb466a752d..54fc4980411ed 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6872,4 +6872,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ The operation may overflow at runtime (use 'unchecked' syntax to override) - + + new-lines in interpolations + + \ 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 1e1211c7f729f..a0dcbb21359c6 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1991,8 +1991,7 @@ internal enum ErrorCode ERR_BadCallerArgumentExpressionParamWithoutDefaultValue = 8964, WRN_CallerArgumentExpressionAttributeSelfReferential = 8965, WRN_CallerArgumentExpressionParamForUnconsumedLocation = 8966, - // It is now legal to have newlines in expression holes. - // ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString = 8967, + ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString = 8967, ERR_AttrTypeArgCannotBeTypeVar = 8968, // WRN_AttrDependentTypeNotAllowed = 8969, // Backed out of of warning wave 6, may be reintroduced later ERR_AttrDependentTypeNotAllowed = 8970, diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs index 9534bbb4f0721..eb7920dd7de62 100644 --- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs +++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs @@ -236,6 +236,9 @@ internal enum MessageID IDS_FeatureParameterlessStructConstructors = MessageBase + 12810, IDS_FeatureStructFieldInitializers = MessageBase + 12811, IDS_FeatureGenericAttributes = MessageBase + 12812, + + // PROTOTYPE: Update this number + IDS_FeatureNewLinesInInterpolations = MessageBase + 12813, } // Message IDs may refer to strings that need to be localized. @@ -345,6 +348,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature) // C# preview features. case MessageID.IDS_FeatureStaticAbstractMembersInInterfaces: // semantic check case MessageID.IDS_FeatureGenericAttributes: // semantic check + case MessageID.IDS_FeatureNewLinesInInterpolations: // semantic check return LanguageVersion.Preview; // C# 10.0 features. diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 652759b775413..789ec21618c84 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -458,6 +458,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -475,6 +477,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -492,6 +496,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -510,6 +516,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -527,6 +535,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -545,6 +555,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -564,6 +576,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -582,6 +596,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -600,6 +616,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -618,6 +636,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -637,6 +657,8 @@ public static int Main() // (6,38): error CS1733: Expected expression // string s = $"x { /* comment */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 38)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -671,6 +693,8 @@ public static int Main() // (9,1): error CS1513: } expected // Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(9, 1)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -706,6 +730,8 @@ public static int Main() // (10,1): error CS1513: } expected // Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(10, 1)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -722,6 +748,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -739,6 +767,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -760,6 +790,8 @@ public static int Main() // (8,29): error CS1733: Expected expression // */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -776,6 +808,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -793,6 +827,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -813,6 +849,8 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -830,6 +868,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -847,6 +887,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -869,6 +911,8 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { /* Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -888,6 +932,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -907,6 +953,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -927,6 +975,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -947,6 +997,8 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -964,6 +1016,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -986,6 +1040,8 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -1005,6 +1061,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -1025,6 +1083,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -1048,6 +1108,8 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -1068,6 +1130,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -1089,6 +1153,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -1109,6 +1175,8 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -1129,6 +1197,8 @@ public static int Main() // (6,24): error CS1733: Expected expression // string s = $@"x { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 24)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -1149,6 +1219,8 @@ public static int Main() // (6,29): error CS1733: Expected expression // string s = $"x { $@" { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -1167,6 +1239,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -1185,6 +1259,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } [Fact] @@ -1203,6 +1279,8 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } #endregion From 437fe7902f0a3c90a12910d108c44d35eed22d8d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 14 Oct 2021 13:57:21 -0700 Subject: [PATCH 10/21] Add tests --- .../Binder/Binder_InterpolatedString.cs | 11 +- .../CSharp/Portable/CSharpResources.resx | 2 +- .../Portable/xlf/CSharpResources.cs.xlf | 9 +- .../Portable/xlf/CSharpResources.de.xlf | 9 +- .../Portable/xlf/CSharpResources.es.xlf | 9 +- .../Portable/xlf/CSharpResources.fr.xlf | 9 +- .../Portable/xlf/CSharpResources.it.xlf | 9 +- .../Portable/xlf/CSharpResources.ja.xlf | 9 +- .../Portable/xlf/CSharpResources.ko.xlf | 9 +- .../Portable/xlf/CSharpResources.pl.xlf | 9 +- .../Portable/xlf/CSharpResources.pt-BR.xlf | 9 +- .../Portable/xlf/CSharpResources.ru.xlf | 9 +- .../Portable/xlf/CSharpResources.tr.xlf | 9 +- .../Portable/xlf/CSharpResources.zh-Hans.xlf | 9 +- .../Portable/xlf/CSharpResources.zh-Hant.xlf | 9 +- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 373 ++++++++++++++---- 16 files changed, 387 insertions(+), 116 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs b/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs index c132f502c9ef2..6bffe0e948fff 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs @@ -41,10 +41,15 @@ private BoundExpression BindInterpolatedString(InterpolatedStringExpressionSynta case SyntaxKind.Interpolation: { var interpolation = (InterpolationSyntax)content; - if (isNonVerbatimInterpolatedString && newLinesInInterpolationsDiagnosticInfo != null) + if (isNonVerbatimInterpolatedString && + !interpolation.GetDiagnostics().Any(d => d.Severity == DiagnosticSeverity.Error) && + newLinesInInterpolationsDiagnosticInfo != null && + !interpolation.OpenBraceToken.IsMissing && + !interpolation.CloseBraceToken.IsMissing) { - if (ContainsTrailingEndOflineTrivia(interpolation.OpenBraceToken) || - ContainsTrailingEndOflineTrivia(interpolation.Expression)) + var text = node.SyntaxTree.GetText(); + if (text.Lines.GetLineFromPosition(interpolation.OpenBraceToken.SpanStart).LineNumber != + text.Lines.GetLineFromPosition(interpolation.CloseBraceToken.SpanStart).LineNumber) { diagnostics.Add( ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 54fc4980411ed..9654c42c78eb0 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6852,7 +6852,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 + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string generic attributes diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 17c68a35f6f32..ced27d73de341 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - Nové řádky se uvnitř nedoslovného interpolovaného řetězce nepovolují. + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ direktiva line span + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors konstruktory struktury bez parametrů diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 42d4b2f97afb8..8c24bd2ca8505 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - Zeilenumbrüche sind in einer nicht wörtlichen interpolierten Zeichenfolge nicht zulässig. + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ Zeilenabstand-Anweisung + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors Parameterlose Strukturkonstruktoren diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 1cf5621c54202..2a04a7eb8c5a5 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - No se permiten nuevas líneas dentro de una cadena interpolada no textual + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ directiva de intervalo de línea + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors constructores de estructuras sin parámetros diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index d1dc40719e857..746b9cfd8ea73 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - Les sauts de ligne ne sont pas autorisés à l’intérieur d’une chaîne interpolée non textuelle + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ directive de l’étendue de ligne + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors constructeurs de struct sans paramètre diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 6565507384ca0..b18428e490a36 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - I caratteri di nuova riga non sono consentiti all'interno di una stringa interpolata non verbatim + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ direttiva per intervallo di riga + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors costruttori struct senza parametri diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 9ffd07633141f..c9d4fe2be4939 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - 改行は、非逐語的に補間された文字列内では使用できません + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ line span ディレクティブ + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors パラメーターのない構造体コンストラクター diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 534bdaf18458f..c4420547658c4 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - 비언어적 보간된 문자열 내부에는 개행이 허용되지 않습니다. + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ 라인 범위 지시문 + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors 매개 변수 없는 구조체 생성자 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 04fb087bb5cc7..e5d270a9d79e5 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - Wewnątrz niedosłownego ciągu interpolowanego nowe wiersze są niedozwolone + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ dyrektywa zakresu wierszy + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors Konstruktory struktury bez parametrów diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index ab7ed9b9af338..f0fd608b7936e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - Novas linhas não são permitidas dentro de uma cadeia de caracteres interpolada não textual + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ diretiva de extensão de linha + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors construtores struct sem parâmetros diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 153fe6c74979a..eac1c18703541 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - Символы новой строки не разрешены в строках, которые интерполируются не буквально + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ директива line span + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors конструкторы структуры без параметров diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 414c32b574241..e1a22013d22c2 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - Düz metin arasına kod eklenmiş dizeye yeni satırlar eklenmesine izin verilmez + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ satır aralığı yönergesi + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors parametresiz yapı oluşturucuları diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 58a8a5d2036de..d59ef72c3b2f3 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - 非逐字内插字符串中不允许使用换行符 + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ 行跨度指令 + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors 参数结构构造函数 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index ad23c36bbf882..874354c3df451 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -828,8 +828,8 @@ - Newlines are not allowed inside a non-verbatim interpolated string - 非逐字差補字串中不允許使用新行 + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Please use language version {0} or later to use newlines inside a non-verbatim interpolated string @@ -1287,6 +1287,11 @@ line span 指示詞 + + new-lines in interpolations + new-lines in interpolations + + parameterless struct constructors 無參數結構建構函式 diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 789ec21618c84..4d2a80d1c415f 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -450,7 +450,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { @"" "" } y""; } @@ -468,7 +468,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { @"" "" } y""; @@ -477,7 +477,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (7,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 23)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -487,7 +490,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { @"" "" } y""; @@ -496,7 +499,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (7,28): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // " } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 28)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -506,7 +512,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString4 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { @"" "" @@ -516,7 +522,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (8,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 23)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -526,7 +535,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString5 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { @"" "" } y""; @@ -535,7 +544,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (7,30): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // @" " } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 30)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -545,7 +557,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString6 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { @"" @@ -555,7 +567,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (8,28): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // " } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 28)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -565,7 +580,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString7 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { @"" @@ -576,7 +591,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (9,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(9, 23)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -586,7 +604,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString8 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { @"" @@ -596,7 +614,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (8,28): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // " } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 28)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -606,7 +627,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString9 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { @"" @@ -616,7 +637,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (8,28): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // " } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 28)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -626,7 +650,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { $@"" { @"" @@ -636,7 +660,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (8,39): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // " } " } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 39)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -646,7 +673,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* comment */ } y""; } @@ -657,8 +684,14 @@ public static int Main() // (6,38): error CS1733: Expected expression // string s = $"x { /* comment */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 38)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (6,38): error CS1733: Expected expression + // string s = $"x { /* comment */ } y"; + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 38)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + // (6,38): error CS1733: Expected expression + // string s = $"x { /* comment */ } y"; + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 38)); } [Fact] @@ -667,7 +700,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* comment } y""; } @@ -693,8 +726,44 @@ public static int Main() // (9,1): error CS1513: } expected // Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(9, 1)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (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)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + // (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] @@ -703,7 +772,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* comment } y""; @@ -730,8 +799,44 @@ public static int Main() // (10,1): error CS1513: } expected // Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(10, 1)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (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)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + // (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] @@ -740,7 +845,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* comment */ 0 } y""; } @@ -758,7 +863,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* comment */ 0 } y""; @@ -767,7 +872,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (7,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // 0 } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 27)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -777,7 +885,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* * comment @@ -790,8 +898,14 @@ public static int Main() // (8,29): error CS1733: Expected expression // */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (8,29): error CS1733: Expected expression + // */ } y"; + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + // (8,29): error CS1733: Expected expression + // */ } y"; + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29)); } [Fact] @@ -800,7 +914,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* comment */ 0 } y""; } @@ -818,7 +932,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* comment */ 0 } y""; @@ -827,7 +941,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (7,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // 0 } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 27)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -837,7 +954,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* comment */ } y""; @@ -849,8 +966,14 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (6,23): error CS1733: Expected expression + // string s = $"x { /* comment */ + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + // (6,23): error CS1733: Expected expression + // string s = $"x { /* comment */ + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] @@ -859,7 +982,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* comment */ 0 } y""; @@ -868,7 +991,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (7,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 23)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -878,7 +1004,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* comment */ 0 } y""; @@ -887,7 +1013,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (7,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // 0 } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 27)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -897,7 +1026,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* * comment @@ -911,8 +1040,14 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { /* Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (6,23): error CS1733: Expected expression + // string s = $"x { /* + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + // (6,23): error CS1733: Expected expression + // string s = $"x { /* + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] @@ -921,7 +1056,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* * comment @@ -932,7 +1067,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (9,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(9, 23)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -942,7 +1080,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* * comment @@ -953,7 +1091,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (9,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // 0 } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(9, 27)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -963,7 +1104,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* * comment @@ -975,7 +1116,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (10,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(10, 23)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -985,7 +1129,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* comment */ } y""; @@ -997,8 +1141,14 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (6,23): error CS1733: Expected expression + // string s = $"x { + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + // (6,23): error CS1733: Expected expression + // string s = $"x { + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] @@ -1007,7 +1157,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* comment */ 0 } y""; @@ -1016,7 +1166,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (7,41): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // /* comment */ 0 } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 41)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -1026,7 +1179,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* @@ -1040,8 +1193,14 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (6,23): error CS1733: Expected expression + // string s = $"x { + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + // (6,23): error CS1733: Expected expression + // string s = $"x { + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] @@ -1050,7 +1209,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* @@ -1061,7 +1220,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (9,31): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // */ 0 } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(9, 31)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -1071,7 +1233,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* @@ -1083,7 +1245,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (10,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // 0 } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(10, 27)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -1093,7 +1258,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* @@ -1108,8 +1273,14 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (6,23): error CS1733: Expected expression + // string s = $"x { + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + // (6,23): error CS1733: Expected expression + // string s = $"x { + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] @@ -1118,7 +1289,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* @@ -1130,7 +1301,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (10,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(10, 23)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -1140,7 +1314,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3 var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { /* @@ -1153,7 +1327,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (11,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(11, 23)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -1163,7 +1340,7 @@ public void CS8077ERR_SingleLineCommentInExpressionHole1() var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { // comment } y""; @@ -1175,8 +1352,14 @@ public static int Main() // (6,23): error CS1733: Expected expression // string s = $"x { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (6,23): error CS1733: Expected expression + // string s = $"x { // comment + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + // (6,23): error CS1733: Expected expression + // string s = $"x { // comment + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); } [Fact] @@ -1185,7 +1368,7 @@ public void CS8077ERR_SingleLineCommentInExpressionHole2() var test = @" public class Test { - public static int Main() + public static void Main() { string s = $@""x { // comment } y""; @@ -1197,8 +1380,14 @@ public static int Main() // (6,24): error CS1733: Expected expression // string s = $@"x { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 24)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (6,24): error CS1733: Expected expression + // string s = $@"x { // comment + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 24)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + // (6,24): error CS1733: Expected expression + // string s = $@"x { // comment + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 24)); } [Fact] @@ -1207,7 +1396,7 @@ public void CS8077ERR_SingleLineCommentInExpressionHole3() var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { $@"" { // comment } "" } y""; @@ -1219,8 +1408,14 @@ public static int Main() // (6,29): error CS1733: Expected expression // string s = $"x { $@" { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (6,29): error CS1733: Expected expression + // string s = $"x { $@" { // comment + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29)); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + // (6,29): error CS1733: Expected expression + // string s = $"x { $@" { // comment + Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29)); } [Fact] @@ -1229,7 +1424,7 @@ public void CS8077ERR_SingleLineCommentInExpressionHole4() var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { // comment 0 @@ -1239,7 +1434,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (8,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 23)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } @@ -1249,7 +1447,7 @@ public void CS8077ERR_SingleLineCommentInExpressionHole5() var test = @" public class Test { - public static int Main() + public static void Main() { string s = $@""x { // comment 0 @@ -1269,7 +1467,7 @@ public void CS8077ERR_SingleLineCommentInExpressionHole6() var test = @" public class Test { - public static int Main() + public static void Main() { string s = $""x { $@"" { // comment 0 @@ -1279,7 +1477,10 @@ public static int Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + // (8,34): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // } " } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 34)); CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); } From edd049754dc93c7376c314a0257c9cfe13fc74c5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 14 Oct 2021 13:58:44 -0700 Subject: [PATCH 11/21] Update optinos --- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 156 +++++++++--------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index 4d2a80d1c415f..a7ed619dc6f55 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -458,8 +458,8 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -477,11 +477,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (7,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -499,11 +499,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (7,28): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // " } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 28)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -522,11 +522,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (8,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -544,11 +544,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (7,30): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // @" " } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 30)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -567,11 +567,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (8,28): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // " } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 28)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -591,11 +591,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (9,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(9, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -614,11 +614,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (8,28): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // " } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 28)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -637,11 +637,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (8,28): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // " } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 28)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -660,11 +660,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (8,39): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // " } " } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 39)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -684,11 +684,11 @@ public static void Main() // (6,38): error CS1733: Expected expression // string s = $"x { /* comment */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 38)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (6,38): error CS1733: Expected expression // string s = $"x { /* comment */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 38)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( // (6,38): error CS1733: Expected expression // string s = $"x { /* comment */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 38)); @@ -726,7 +726,7 @@ public static void Main() // (9,1): error CS1513: } expected // Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(9, 1)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. // string s = $"x { /* comment } y"; Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), @@ -745,7 +745,7 @@ public static void Main() // (9,1): error CS1513: } expected // Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(9, 1)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. // string s = $"x { /* comment } y"; Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), @@ -799,7 +799,7 @@ public static void Main() // (10,1): error CS1513: } expected // Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(10, 1)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. // string s = $"x { /* comment Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), @@ -818,7 +818,7 @@ public static void Main() // (10,1): error CS1513: } expected // Diagnostic(ErrorCode.ERR_RbraceExpected, "").WithLocation(10, 1)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'. // string s = $"x { /* comment Diagnostic(ErrorCode.ERR_UnclosedExpressionHole, " {").WithLocation(6, 21), @@ -853,8 +853,8 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -872,11 +872,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (7,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // 0 } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 27)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -898,11 +898,11 @@ public static void Main() // (8,29): error CS1733: Expected expression // */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (8,29): error CS1733: Expected expression // */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( // (8,29): error CS1733: Expected expression // */ } y"; Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29)); @@ -922,8 +922,8 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -941,11 +941,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (7,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // 0 } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 27)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -966,11 +966,11 @@ public static void Main() // (6,23): error CS1733: Expected expression // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (6,23): error CS1733: Expected expression // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( // (6,23): error CS1733: Expected expression // string s = $"x { /* comment */ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); @@ -991,11 +991,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (7,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -1013,11 +1013,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (7,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // 0 } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 27)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -1040,11 +1040,11 @@ public static void Main() // (6,23): error CS1733: Expected expression // string s = $"x { /* Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (6,23): error CS1733: Expected expression // string s = $"x { /* Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( // (6,23): error CS1733: Expected expression // string s = $"x { /* Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); @@ -1067,11 +1067,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (9,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(9, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -1091,11 +1091,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (9,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // 0 } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(9, 27)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -1116,11 +1116,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (10,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(10, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -1141,11 +1141,11 @@ public static void Main() // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); @@ -1166,11 +1166,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (7,41): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // /* comment */ 0 } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 41)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -1193,11 +1193,11 @@ public static void Main() // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); @@ -1220,11 +1220,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (9,31): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // */ 0 } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(9, 31)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -1245,11 +1245,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (10,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // 0 } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(10, 27)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -1273,11 +1273,11 @@ public static void Main() // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( // (6,23): error CS1733: Expected expression // string s = $"x { Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); @@ -1301,11 +1301,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (10,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(10, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -1327,11 +1327,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (11,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(11, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -1352,11 +1352,11 @@ public static void Main() // (6,23): error CS1733: Expected expression // string s = $"x { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (6,23): error CS1733: Expected expression // string s = $"x { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( // (6,23): error CS1733: Expected expression // string s = $"x { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23)); @@ -1380,11 +1380,11 @@ public static void Main() // (6,24): error CS1733: Expected expression // string s = $@"x { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 24)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (6,24): error CS1733: Expected expression // string s = $@"x { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 24)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( // (6,24): error CS1733: Expected expression // string s = $@"x { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 24)); @@ -1408,11 +1408,11 @@ public static void Main() // (6,29): error CS1733: Expected expression // string s = $"x { $@" { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (6,29): error CS1733: Expected expression // string s = $"x { $@" { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics( // (6,29): error CS1733: Expected expression // string s = $"x { $@" { // comment Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29)); @@ -1434,11 +1434,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (8,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 23)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -1457,8 +1457,8 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics(); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } [Fact] @@ -1477,11 +1477,11 @@ public static void Main() "; ParserErrorMessageTests.ParseAndValidate(test); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp10)).VerifyDiagnostics( + CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( // (8,34): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string // } " } y"; Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 34)); - CreateCompilation(test, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview)).VerifyDiagnostics(); + CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } #endregion From da758817a5d66cff859ee30ec8e6c8ae2ba06b92 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 14 Oct 2021 13:59:24 -0700 Subject: [PATCH 12/21] remove --- .../Binder/Binder_InterpolatedString.cs | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs b/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs index 6bffe0e948fff..66cf32446ff4e 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs @@ -150,28 +150,6 @@ private BoundExpression BindInterpolatedString(InterpolatedStringExpressionSynta return new BoundUnconvertedInterpolatedString(node, builder.ToImmutableAndFree(), resultConstant, stringType); } - private static bool ContainsTrailingEndOflineTrivia(SyntaxNodeOrToken nodeOrToken) - { - if (nodeOrToken.IsNode) - { - foreach (var child in nodeOrToken.AsNode()!.ChildNodesAndTokens()) - { - if (ContainsTrailingEndOflineTrivia(child)) - return true; - } - } - else if (nodeOrToken.IsToken) - { - foreach (var trivia in nodeOrToken.AsToken().TrailingTrivia) - { - if (trivia.Kind() == SyntaxKind.EndOfLineTrivia) - return true; - } - } - - return false; - } - private BoundInterpolatedString BindUnconvertedInterpolatedStringToString(BoundUnconvertedInterpolatedString unconvertedInterpolatedString, BindingDiagnosticBag diagnostics) { // We have 4 possible lowering strategies, dependent on the contents of the string, in this order: From 9dd318916a144970fd9aaf7970908c4d691561c3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 14 Oct 2021 14:00:48 -0700 Subject: [PATCH 13/21] Update comment --- src/Compilers/CSharp/Portable/Errors/ErrorCode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index a0dcbb21359c6..f5a0e285a97b0 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1308,7 +1308,7 @@ internal enum ErrorCode ERR_DictionaryInitializerInExpressionTree = 8074, ERR_ExtensionCollectionElementInitializerInExpressionTree = 8075, ERR_UnclosedExpressionHole = 8076, - // It is now legal to have single line comments in expression holes. + // This is now handled by the single ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString error. // ERR_SingleLineCommentInExpressionHole = 8077, ERR_InsufficientStack = 8078, ERR_UseDefViolationProperty = 8079, From d5eb8f670ec931fa1cdd542981c8cf04c419f39e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 15 Oct 2021 10:40:15 -0700 Subject: [PATCH 14/21] Remove prototype --- src/Compilers/CSharp/Portable/Errors/MessageID.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs index eb7920dd7de62..b686afcf09272 100644 --- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs +++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs @@ -237,7 +237,6 @@ internal enum MessageID IDS_FeatureStructFieldInitializers = MessageBase + 12811, IDS_FeatureGenericAttributes = MessageBase + 12812, - // PROTOTYPE: Update this number IDS_FeatureNewLinesInInterpolations = MessageBase + 12813, } From 1b05285083623b72cdc40f13d6afb24903cf292a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 15 Oct 2021 10:48:36 -0700 Subject: [PATCH 15/21] PR feedback and comment --- .../Portable/Binder/Binder_InterpolatedString.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs b/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs index 66cf32446ff4e..8b5d4d62d3eca 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs @@ -30,8 +30,7 @@ private BoundExpression BindInterpolatedString(InterpolatedStringExpressionSynta else { var isNonVerbatimInterpolatedString = node.StringStartToken.Kind() != SyntaxKind.InterpolatedVerbatimStringStartToken; - var newLinesInInterpolationsDiagnosticInfo = - MessageID.IDS_FeatureNewLinesInInterpolations.GetFeatureAvailabilityDiagnosticInfo((CSharpParseOptions)node.SyntaxTree.Options); + var newLinesInInterpolationsAllowed = this.Compilation.IsFeatureEnabled(MessageID.IDS_FeatureNewLinesInInterpolations); var intType = GetSpecialType(SpecialType.System_Int32, diagnostics, node); foreach (var content in node.Contents) @@ -41,9 +40,18 @@ private BoundExpression BindInterpolatedString(InterpolatedStringExpressionSynta case SyntaxKind.Interpolation: { var interpolation = (InterpolationSyntax)content; + + // If we're prior to C# 11 then we don't allow newlines in the interpolations of + // non-verbatim interpolated strings. Check for that here and report an error + // if the interpolation spans multiple lines (and thus must have a newline). + // + // Note: don't bother doing this if the interpolation is otherwise malformed or + // we've already reported some other error within it. No need to spam the user + // with multiple errors (esp as a malformed interpolation may commonly span multiple + // lines due to error recovery). if (isNonVerbatimInterpolatedString && !interpolation.GetDiagnostics().Any(d => d.Severity == DiagnosticSeverity.Error) && - newLinesInInterpolationsDiagnosticInfo != null && + !newLinesInInterpolationsAllowed && !interpolation.OpenBraceToken.IsMissing && !interpolation.CloseBraceToken.IsMissing) { From f0b1cd8f2db2e078d55e13fcd81ef3480672abf3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 15 Oct 2021 12:09:45 -0700 Subject: [PATCH 16/21] fix loc strings --- src/Compilers/CSharp/Portable/CSharpResources.resx | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf | 4 ++-- 14 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 9654c42c78eb0..aaa6c06d47ca8 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6873,6 +6873,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ The operation may overflow at runtime (use 'unchecked' syntax to override) - new-lines in interpolations + newlines in interpolations \ 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 ced27d73de341..663cbf17461a8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 8c24bd2ca8505..db8864b222ab1 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 2a04a7eb8c5a5..8892c157db16e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 746b9cfd8ea73..71fab0cde9b8c 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index b18428e490a36..4bc9f62eb4e19 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index c9d4fe2be4939..1635c16c07f48 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index c4420547658c4..7c3dc994835f6 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index e5d270a9d79e5..ba735b3646bfc 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index f0fd608b7936e..1a5077f6618ad 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index eac1c18703541..703db16c564ea 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index e1a22013d22c2..9fbbbd662c0c3 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index d59ef72c3b2f3..1edcf03d7de13 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 874354c3df451..5010c30233521 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -1288,8 +1288,8 @@ - new-lines in interpolations - new-lines in interpolations + newlines in interpolations + newlines in interpolations From 3ec40dbf25729c305a0f7c6da194fcb7aecc09d4 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Mon, 25 Oct 2021 12:33:22 -0500 Subject: [PATCH 17/21] Update src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs Co-authored-by: Chris Sienkiewicz --- 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 fa4a59f7cf355..94bcd4feae389 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -517,7 +517,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { char ch = _lexer.TextWindow.PeekChar(); - // Note: within a hole new-lines are always allowed. The retriction on if new-lines are allowed or not + // Note: within a hole new-lines are always allowed. The restriction on if new-lines are allowed or not // is only within a text-portion of the interpolated stirng. if (IsAtEnd(allowNewline: true)) { From 2459df561291eb0469f6dd038ff932ce81116842 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Mon, 25 Oct 2021 12:33:33 -0500 Subject: [PATCH 18/21] Update src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs Co-authored-by: Chris Sienkiewicz --- 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 94bcd4feae389..27b97f219ae43 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -518,7 +518,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool char ch = _lexer.TextWindow.PeekChar(); // Note: within a hole new-lines are always allowed. The restriction on if new-lines are allowed or not - // is only within a text-portion of the interpolated stirng. + // is only within a text-portion of the interpolated string. if (IsAtEnd(allowNewline: true)) { // the caller will complain From 1e445cb8d5953d68a5a1e1bd8f17860955e8e804 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Mon, 25 Oct 2021 13:11:45 -0500 Subject: [PATCH 19/21] Update src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs Co-authored-by: Chris Sienkiewicz --- 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 27b97f219ae43..3d5a6cb5fc2f1 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -681,7 +681,7 @@ private void ScanInterpolatedStringLiteralNestedComment() while (true) { // Note: if we reach the end of the file without hitting */ just bail out. It's not necessary for - // us to report any issues, as this code is just being used to find the end of teh interpolation hole. + // us to report any issues, as this code is just being used to find the end of the interpolation hole. // When the full parse happens, the lexer will grab the string inside the interpolation hole and // pass it to the regular parser. This parser will then see the unterminated /* and will report the // error for it. From 65e91b2e4eb13b594a11ab4c361e0dd10e1fcbb1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 25 Oct 2021 11:40:33 -0700 Subject: [PATCH 20/21] Update language string --- .../Binder/Binder_InterpolatedString.cs | 1 + .../CSharp/Portable/CSharpResources.resx | 2 +- .../Portable/xlf/CSharpResources.cs.xlf | 4 +- .../Portable/xlf/CSharpResources.de.xlf | 4 +- .../Portable/xlf/CSharpResources.es.xlf | 4 +- .../Portable/xlf/CSharpResources.fr.xlf | 4 +- .../Portable/xlf/CSharpResources.it.xlf | 4 +- .../Portable/xlf/CSharpResources.ja.xlf | 4 +- .../Portable/xlf/CSharpResources.ko.xlf | 4 +- .../Portable/xlf/CSharpResources.pl.xlf | 4 +- .../Portable/xlf/CSharpResources.pt-BR.xlf | 4 +- .../Portable/xlf/CSharpResources.ru.xlf | 4 +- .../Portable/xlf/CSharpResources.tr.xlf | 4 +- .../Portable/xlf/CSharpResources.zh-Hans.xlf | 4 +- .../Portable/xlf/CSharpResources.zh-Hant.xlf | 4 +- .../Syntax/LexicalAndXml/LexicalErrorTests.cs | 94 +++++++++---------- 16 files changed, 75 insertions(+), 74 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs b/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs index 8b5d4d62d3eca..3245d5537afd5 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs @@ -62,6 +62,7 @@ private BoundExpression BindInterpolatedString(InterpolatedStringExpressionSynta diagnostics.Add( ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, interpolation.CloseBraceToken.GetLocation(), + this.Compilation.LanguageVersion.ToDisplayString(), new CSharpRequiredLanguageVersion(MessageID.IDS_FeatureNewLinesInInterpolations.RequiredVersion())); } } diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index aaa6c06d47ca8..23d66723d5384 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6852,7 +6852,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. - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. generic attributes diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 663cbf17461a8..4506740b4d268 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index db8864b222ab1..4ee6d22be3f26 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 8892c157db16e..af2d9a34f8c37 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 71fab0cde9b8c..b7f66e240a5e7 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 4bc9f62eb4e19..6afef77d36a04 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 1635c16c07f48..9f3347e842f34 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 7c3dc994835f6..bb42a5b4f2146 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index ba735b3646bfc..1db21f4c7e235 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 1a5077f6618ad..c71717f1b72f8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 703db16c564ea..f0f2279f3f30d 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 9fbbbd662c0c3..f395b5b203d0e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 1edcf03d7de13..cafc671f5b502 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 5010c30233521..4762f02207933 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -828,8 +828,8 @@ - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string - Please use language version {0} or later to use newlines inside a non-verbatim interpolated string + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. + Newlines inside a non-verbatim interpolated string are not supported in C# {0}. Please use language version {1} or greater. diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs index a7ed619dc6f55..9683790c58787 100644 --- a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs @@ -478,9 +478,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (7,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (7,23): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(7, 23)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -500,9 +500,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (7,28): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (7,28): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // " } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 28)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(7, 28)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -523,9 +523,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (8,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (8,23): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(8, 23)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -545,9 +545,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (7,30): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (7,30): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // @" " } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 30)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(7, 30)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -568,9 +568,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (8,28): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (8,28): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // " } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 28)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(8, 28)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -592,9 +592,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (9,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (9,23): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(9, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(9, 23)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -615,9 +615,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (8,28): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (8,28): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // " } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 28)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(8, 28)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -638,9 +638,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (8,28): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (8,28): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // " } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 28)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(8, 28)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -661,9 +661,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (8,39): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (8,39): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // " } " } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 39)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(8, 39)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -873,9 +873,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (7,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (7,27): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // 0 } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 27)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(7, 27)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -942,9 +942,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (7,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (7,27): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // 0 } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 27)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(7, 27)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -992,9 +992,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (7,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (7,23): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(7, 23)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -1014,9 +1014,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (7,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (7,27): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // 0 } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 27)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(7, 27)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -1068,9 +1068,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (9,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (9,23): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(9, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(9, 23)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -1092,9 +1092,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (9,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (9,27): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // 0 } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(9, 27)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(9, 27)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -1117,9 +1117,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (10,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (10,23): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(10, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(10, 23)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -1167,9 +1167,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (7,41): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (7,41): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // /* comment */ 0 } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(7, 41)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(7, 41)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -1221,9 +1221,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (9,31): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (9,31): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // */ 0 } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(9, 31)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(9, 31)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -1246,9 +1246,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (10,27): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (10,27): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // 0 } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(10, 27)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(10, 27)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -1302,9 +1302,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (10,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (10,23): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(10, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(10, 23)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -1328,9 +1328,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (11,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (11,23): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(11, 23)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(11, 23)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -1435,9 +1435,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (8,23): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string - // } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 23)); + // (8,23): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. + // } y"; + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(8, 23)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } @@ -1478,9 +1478,9 @@ public static void Main() ParserErrorMessageTests.ParseAndValidate(test); CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics( - // (8,34): error CS8967: Please use language version preview or later to use newlines inside a non-verbatim interpolated string + // (8,34): error CS8967: Newlines inside a non-verbatim interpolated string is not supported in C# 10.0. Please use language version preview or greater. // } " } y"; - Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("preview").WithLocation(8, 34)); + Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "}").WithArguments("10.0", "preview").WithLocation(8, 34)); CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(); } From 59e4649d7b9f87f6d32f31ec37c3dd27a4f7cb11 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Mon, 25 Oct 2021 14:03:00 -0500 Subject: [PATCH 21/21] Update src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs Co-authored-by: Julien Couvreur --- 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 3d5a6cb5fc2f1..371e69133390e 100644 --- a/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs +++ b/src/Compilers/CSharp/Portable/Parser/Lexer_StringLiteral.cs @@ -517,7 +517,7 @@ private void ScanInterpolatedStringLiteralHoleBalancedText(char endingChar, bool { char ch = _lexer.TextWindow.PeekChar(); - // Note: within a hole new-lines are always allowed. The restriction on if new-lines are allowed or not + // Note: within a hole newlines are always allowed. The restriction on if newlines are allowed or not // is only within a text-portion of the interpolated string. if (IsAtEnd(allowNewline: true)) {