diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs b/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs
index 634cd6a1ddc66..3245d5537afd5 100644
--- a/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs
+++ b/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs
@@ -29,6 +29,9 @@ private BoundExpression BindInterpolatedString(InterpolatedStringExpressionSynta
}
else
{
+ var isNonVerbatimInterpolatedString = node.StringStartToken.Kind() != SyntaxKind.InterpolatedVerbatimStringStartToken;
+ var newLinesInInterpolationsAllowed = this.Compilation.IsFeatureEnabled(MessageID.IDS_FeatureNewLinesInInterpolations);
+
var intType = GetSpecialType(SpecialType.System_Int32, diagnostics, node);
foreach (var content in node.Contents)
{
@@ -37,6 +40,33 @@ 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) &&
+ !newLinesInInterpolationsAllowed &&
+ !interpolation.OpenBraceToken.IsMissing &&
+ !interpolation.CloseBraceToken.IsMissing)
+ {
+ 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,
+ interpolation.CloseBraceToken.GetLocation(),
+ this.Compilation.LanguageVersion.ToDisplayString(),
+ 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,
diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx
index d3cdb466a752d..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.
- Newlines are not allowed 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
@@ -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)
-
+
+ newlines 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 21d55131f01bf..f5a0e285a97b0 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,
+ // This is now handled by the single ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString error.
+ // ERR_SingleLineCommentInExpressionHole = 8077,
ERR_InsufficientStack = 8078,
ERR_UseDefViolationProperty = 8079,
ERR_AutoPropertyMustOverrideSet = 8080,
diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs
index 9534bbb4f0721..b686afcf09272 100644
--- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs
+++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs
@@ -236,6 +236,8 @@ internal enum MessageID
IDS_FeatureParameterlessStructConstructors = MessageBase + 12810,
IDS_FeatureStructFieldInitializers = MessageBase + 12811,
IDS_FeatureGenericAttributes = MessageBase + 12812,
+
+ IDS_FeatureNewLinesInInterpolations = MessageBase + 12813,
}
// Message IDs may refer to strings that need to be localized.
@@ -345,6 +347,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/Portable/Parser/LanguageParser_InterpolatedString.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser_InterpolatedString.cs
index ed046c1072696..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);
@@ -171,29 +171,26 @@ 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)
{
- 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);
}
}
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..371e69133390e 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 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))
{
// 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,19 @@ 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));
- }
-
+ // 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 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.
if (IsAtEnd(allowNewline: true))
- {
- return; // let the caller complain about the unterminated quote
- }
+ return;
+ var ch = _lexer.TextWindow.PeekChar();
_lexer.TextWindow.AdvanceChar();
if (ch == '*' && _lexer.TextWindow.PeekChar() == '/')
{
- _lexer.TextWindow.AdvanceChar(); // skip */
+ _lexer.TextWindow.AdvanceChar();
return;
}
}
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
index 17c68a35f6f32..4506740b4d268 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í.
+ 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.
@@ -1287,6 +1287,11 @@
direktiva line span
+
+ newlines in interpolations
+ newlines in interpolations
+
+ parameterless struct constructorskonstruktory 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..4ee6d22be3f26 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.
+ 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.
@@ -1287,6 +1287,11 @@
Zeilenabstand-Anweisung
+
+ newlines in interpolations
+ newlines in interpolations
+
+ parameterless struct constructorsParameterlose Strukturkonstruktoren
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
index 1cf5621c54202..af2d9a34f8c37 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
+ 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.
@@ -1287,6 +1287,11 @@
directiva de intervalo de línea
+
+ newlines in interpolations
+ newlines in interpolations
+
+ parameterless struct constructorsconstructores 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..b7f66e240a5e7 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
+ 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.
@@ -1287,6 +1287,11 @@
directive de l’étendue de ligne
+
+ newlines in interpolations
+ newlines in interpolations
+
+ parameterless struct constructorsconstructeurs 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..6afef77d36a04 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
+ 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.
@@ -1287,6 +1287,11 @@
direttiva per intervallo di riga
+
+ newlines in interpolations
+ newlines in interpolations
+
+ parameterless struct constructorscostruttori 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..9f3347e842f34 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
- 改行は、非逐語的に補間された文字列内では使用できません
+ 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.
@@ -1287,6 +1287,11 @@
line span ディレクティブ
+
+ newlines in interpolations
+ newlines 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..bb42a5b4f2146 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
- 비언어적 보간된 문자열 내부에는 개행이 허용되지 않습니다.
+ 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.
@@ -1287,6 +1287,11 @@
라인 범위 지시문
+
+ newlines in interpolations
+ newlines 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..1db21f4c7e235 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
+ 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.
@@ -1287,6 +1287,11 @@
dyrektywa zakresu wierszy
+
+ newlines in interpolations
+ newlines in interpolations
+
+ parameterless struct constructorsKonstruktory 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..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 @@
- 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
+ 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.
@@ -1287,6 +1287,11 @@
diretiva de extensão de linha
+
+ newlines in interpolations
+ newlines in interpolations
+
+ parameterless struct constructorsconstrutores 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..f0f2279f3f30d 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
- Символы новой строки не разрешены в строках, которые интерполируются не буквально
+ 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.
@@ -1287,6 +1287,11 @@
директива line span
+
+ newlines in interpolations
+ newlines 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..f395b5b203d0e 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
+ 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.
@@ -1287,6 +1287,11 @@
satır aralığı yönergesi
+
+ newlines in interpolations
+ newlines in interpolations
+
+ parameterless struct constructorsparametresiz 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..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 @@
- Newlines are not allowed 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.
@@ -1287,6 +1287,11 @@
行跨度指令
+
+ newlines in interpolations
+ newlines 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..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 @@
- Newlines are not allowed 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.
@@ -1287,6 +1287,11 @@
line span 指示詞
+
+ newlines in interpolations
+ newlines in interpolations
+
+ parameterless struct constructors無參數結構建構函式
diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs
index 22f04c9785150..2a14a7d188208 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),
@@ -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),
- // (5,77): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string
- // Console.WriteLine($"Jenny don\'t change your number { 8675309 /* ");
- Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(5, 77),
// (7,2): error CS1026: ) expected
// }
Diagnostic(ErrorCode.ERR_CloseParenExpected, "").WithLocation(7, 2),
@@ -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),
diff --git a/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs b/src/Compilers/CSharp/Test/Syntax/LexicalAndXml/LexicalErrorTests.cs
index 938b22eb194e6..9683790c58787 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"";
}
@@ -458,6 +458,8 @@ public static int Main()
";
ParserErrorMessageTests.ParseAndValidate(test);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics();
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -466,7 +468,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x { @"" ""
} y"";
@@ -474,10 +476,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(7, 23));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -486,7 +490,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x { @""
"" } y"";
@@ -494,10 +498,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(7, 28));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -506,7 +512,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString4
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x { @""
""
@@ -515,10 +521,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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();
}
[Fact]
@@ -527,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,10 +543,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(7, 30));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -547,7 +557,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString6
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x {
@""
@@ -556,10 +566,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(8, 28));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -568,7 +580,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString7
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x {
@""
@@ -578,10 +590,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(9, 23));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -590,7 +604,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString8
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x { @""
@@ -599,10 +613,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(8, 28));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -611,7 +627,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString9
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x { @""
@@ -620,10 +636,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(8, 28));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -632,7 +650,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString1
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x { $@"" { @""
@@ -641,10 +659,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(8, 39));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -653,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"";
}
@@ -664,6 +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: TestOptions.Regular10).VerifyDiagnostics(
+ // (6,38): error CS1733: Expected expression
+ // string s = $"x { /* comment */ } y";
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 38));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(
+ // (6,38): error CS1733: Expected expression
+ // string s = $"x { /* comment */ } y";
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 38));
}
[Fact]
@@ -672,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"";
}
@@ -680,12 +708,50 @@ 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 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: 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),
// (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
+ // (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: TestOptions.RegularNext).VerifyDiagnostics(
+ // (6,21): error CS8076: Missing close delimiter '}' for interpolated expression started with '{'.
// string s = $"x { /* comment } y";
- Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 40),
+ 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),
@@ -706,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"";
@@ -715,24 +781,62 @@ 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,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: 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),
+ // (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: 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),
+ // (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]
@@ -741,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"";
}
@@ -749,6 +853,8 @@ public static int Main()
";
ParserErrorMessageTests.ParseAndValidate(test);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics();
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -757,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"";
@@ -765,10 +871,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(7, 27));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -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
@@ -787,9 +895,14 @@ 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));
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (8,29): error CS1733: Expected expression
+ // */ } y";
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(
// (8,29): error CS1733: Expected expression
// */ } y";
Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(8, 29));
@@ -801,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"";
}
@@ -809,6 +922,8 @@ public static int Main()
";
ParserErrorMessageTests.ParseAndValidate(test);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics();
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -817,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"";
@@ -825,10 +940,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(7, 27));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -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"";
@@ -848,10 +965,15 @@ 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
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
+ 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: TestOptions.RegularNext).VerifyDiagnostics(
+ // (6,23): error CS1733: Expected expression
// string s = $"x { /* comment */
- Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 37));
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
}
[Fact]
@@ -860,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,10 +990,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(7, 23));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -880,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"";
@@ -888,10 +1012,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(7, 27));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -900,7 +1026,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x { /*
* comment
@@ -913,10 +1039,15 @@ 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
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
+ 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: TestOptions.RegularNext).VerifyDiagnostics(
+ // (6,23): error CS1733: Expected expression
// string s = $"x { /*
- Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 26));
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
}
[Fact]
@@ -925,7 +1056,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x { /*
* comment
@@ -935,10 +1066,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(9, 23));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -947,7 +1080,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x { /*
* comment
@@ -957,10 +1090,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(9, 27));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -969,7 +1104,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x { /*
* comment
@@ -980,10 +1115,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(10, 23));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -992,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"";
@@ -1001,9 +1138,14 @@ public static int Main()
";
ParserErrorMessageTests.ParseAndValidate(test,
- // (6,23): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string
+ // (6,23): error CS1733: Expected expression
+ // string s = $"x {
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (6,23): error CS1733: Expected expression
// string s = $"x {
- Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23),
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(
// (6,23): error CS1733: Expected expression
// string s = $"x {
Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
@@ -1015,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"";
@@ -1023,10 +1165,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(7, 41));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -1035,7 +1179,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x {
/*
@@ -1046,9 +1190,14 @@ public static int Main()
";
ParserErrorMessageTests.ParseAndValidate(test,
- // (6,23): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string
+ // (6,23): error CS1733: Expected expression
// string s = $"x {
- Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23),
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
+ 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: TestOptions.RegularNext).VerifyDiagnostics(
// (6,23): error CS1733: Expected expression
// string s = $"x {
Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
@@ -1060,7 +1209,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString2
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x {
/*
@@ -1070,10 +1219,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(9, 31));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -1082,7 +1233,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x {
/*
@@ -1093,10 +1244,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(10, 27));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -1105,7 +1258,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x {
/*
@@ -1117,9 +1270,14 @@ public static int Main()
";
ParserErrorMessageTests.ParseAndValidate(test,
- // (6,23): error CS8967: Newlines are not allowed inside a non-verbatim interpolated string
+ // (6,23): error CS1733: Expected expression
// string s = $"x {
- Diagnostic(ErrorCode.ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString, "").WithLocation(6, 23),
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
+ 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: TestOptions.RegularNext).VerifyDiagnostics(
// (6,23): error CS1733: Expected expression
// string s = $"x {
Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
@@ -1131,7 +1289,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x {
/*
@@ -1142,10 +1300,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(10, 23));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -1154,7 +1314,7 @@ public void CS8967ERR_NewlinesAreNotAllowedInsideANonVerbatimInterpolatedString3
var test = @"
public class Test
{
- public static int Main()
+ public static void Main()
{
string s = $""x {
/*
@@ -1166,10 +1326,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(11, 23));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -1178,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"";
@@ -1189,10 +1351,15 @@ 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.
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
+ 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: TestOptions.RegularNext).VerifyDiagnostics(
+ // (6,23): error CS1733: Expected expression
// string s = $"x { // comment
- Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 24));
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 23));
}
[Fact]
@@ -1201,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"";
@@ -1213,6 +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: TestOptions.Regular10).VerifyDiagnostics(
+ // (6,24): error CS1733: Expected expression
+ // string s = $@"x { // comment
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 24));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics(
+ // (6,24): error CS1733: Expected expression
+ // string s = $@"x { // comment
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 24));
}
[Fact]
@@ -1221,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"";
@@ -1232,10 +1407,15 @@ 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.
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29));
+ 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: TestOptions.RegularNext).VerifyDiagnostics(
+ // (6,29): error CS1733: Expected expression
// string s = $"x { $@" { // comment
- Diagnostic(ErrorCode.ERR_SingleLineCommentInExpressionHole, "//").WithLocation(6, 30));
+ Diagnostic(ErrorCode.ERR_ExpressionExpected, "").WithLocation(6, 29));
}
[Fact]
@@ -1244,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
@@ -1253,10 +1433,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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();
}
[Fact]
@@ -1265,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
@@ -1275,6 +1457,8 @@ public static int Main()
";
ParserErrorMessageTests.ParseAndValidate(test);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics();
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
[Fact]
@@ -1283,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
@@ -1292,10 +1476,12 @@ 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);
+ CreateCompilation(test, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
+ // (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("10.0", "preview").WithLocation(8, 34));
+ CreateCompilation(test, parseOptions: TestOptions.RegularNext).VerifyDiagnostics();
}
#endregion