[Proposal]: Remove restriction that interpolations within a non-verbatim interpolated string cannot contain new-lines. #8648
Replies: 9 comments
This comment has been hidden.
This comment has been hidden.
-
from LDM:
Does the same reasoning apply to allowing ternaries in interpolation holes? I think there's already a proposal to follow TS design to accomplish that. |
Beta Was this translation helpful? Give feedback.
-
ternaries are harder without a substantial amount of effort here. |
Beta Was this translation helpful? Give feedback.
This comment was marked as off-topic.
This comment was marked as off-topic.
-
Would it be possible to tell the compiler which line endings to use since right now it is very hard to use multiline strings except if you add additional code to transform newlines. |
Beta Was this translation helpful? Give feedback.
-
@davhdavh Maybe open a new discussion on this? This thread is only talking about newlines inside interpolation holes, not inside the string contents, e.g.: var x = $@"a{
null
}b"; which results in the string |
Beta Was this translation helpful? Give feedback.
-
Ahh, my mistake. I totally miss-read the spec, and thought this would also allow newlines in the interpolated string itself. |
Beta Was this translation helpful? Give feedback.
-
@davhdavh One cool thing with this change is that you can do this:
There's also Raw string literal which is available with Maybe a combination, at least it'll take care of the indention.
|
Beta Was this translation helpful? Give feedback.
-
Allow new-lines in all interpolations
Summary
The language today non-verbatim and verbatim interpolated strings (
$""
and$@""
respectively). The primary sensible difference for these is that a non-verbatim interpolated string works like a normal string and cannot contain newlines in its text segments, and must instead use escapes (like\r\n
). Conversely, a verbatim interpolated string can contain newlines in its text segments (like a verbatim string), and doesn't escape newlines or other character (except for""
to escape a quote itself).This is all reasonable and will not change with this proposal.
What is unreasonable today is that we extend the restriction on 'no newlines' in a non-verbatim interpolated string beyond its text segments into the interpolations themselves. This means, for example, that you cannot write the following:
Ultimately, the 'interpolation must be on a single line itself' rule is just a restriction of the current implementation. That restriction really isn't necessary, and can be annoying, and would be fairly trivial to remove (see work dotnet/roslyn#54875 to show how). In the end, all it does is force the dev to place things on a single line, or force them into a verbatim interpolated string (both of which may be unpalatable).
The interpolation expressions themselves are not text, and shouldn't be beholden to any escaping/newline rules therin.
Specification change
LDM Discussions
https://github.com/dotnet/csharplang/blob/main/meetings/2021/LDM-2021-09-20.md
Beta Was this translation helpful? Give feedback.
All reactions