-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse-Error: new-line in string interpolation expressions #50742
Comments
You need to use Normal |
The new line does not appear in the string itself! It is inside a normal expression. @ would dissallow escaping / change escaping rules. Of course we could use verbatim interpolated strings here, string.operator+, local variables or simply string.Format. |
Yes. I understand that :-) This is how we designed the language to work. The string literal start/end is discovered first, then internally parsed. Fur these strings, the end can't be found as they are supposed to be in a single line, but a new line is encountered before the end is reached.
Yes. That is true.
Yes. |
Is it defined in the spec that expressions with newline trivia are dissallowed here? A resulting bug is a call to What's about comments, those are "real trivia" - but a multiline comment would break interpolated strings, too. |
That is a bug. |
Please see the conversation in dotnet/csharplang#1409 for a better understanding of what's going on here. In particular: dotnet/csharplang#1409 (comment) |
I understand the problem with the colon handling. But I think the issue with new lines is easy. Coudn't we change the call at: Lexer-Source To New lines are generally allowed in those "holes". |
I fixed the code but it is still over-complicated and bug-prone. One example. using System;
Console.WriteLine($"Test { @$"
12"}"); But it rejected: using System;
Console.WriteLine($"Test { $@"
12"}"); |
yes. this is as expected. |
Implemented via #56853 |
Version Used: 16.9.0 Preview 3
Sample Code:
Link
Expected Behavior:
According to csharplang every expression is allowed in an interpolation. So expressions with New-Line trivia should compile.
Actual Behavior:
Code does not compile, just with removing the new lines.
The text was updated successfully, but these errors were encountered: