Open tats-u opened 5 months ago
In contrast to this, the string concatenation operator (C#: +
/ VB: &
) handles these types of constants well.
This is one of the ways in which interpolated strings is inferior to the concatenation operator.
Marking for compiler team to assign a buddy for the PR contribution.
@333fred pretty sure this is "By Design" but want to let you confirm.
No, this is not by design. We could adjust this behavior as an optimization.
const string = $"foo {'b'}ar";
in C# 12 or only future versions?
It's about expression trees. And yes, expression trees need to reflect the code as written.
I managed to consider them in my PR but it looks like some code is not sufficient quality.
This would not be a language feature and should not be tied to language version. It should be entirely invisible to compiled code; it should just get marginally faster with no observable side effects.
We will not have to wait for the next version of .NET in the fix for C#. This change will be appreciated in VB too because of the existences of vbLf
, ChrW
(especially e.g. ChrW(&H201C)
& ChrW(&H201D)
), and NameOf
, but it can be postponed to the next version of .NET to be tested more thoroughly in preview versions.
vblang's issue: https://github.com/dotnet/vblang/issues/369
but it looks like some code is not sufficient quality.
Fixed. I do not think that I have to make additional changes except for appending additional tests now.
My current PR for C# only aims at only interpolated strings that return string values (not other types of handlers or formattables).
If the code satisfies one of the following condition, I think it should be as is:
System.
or IFormattable
other than FormattableString
IFormatProvider
(2nd one) of BCL handlers is a class implementing ICustomFormatter
FormattableString
other than an argument of FormattableString.Invariant
(or .CurrentCulture
)
.GetArgument(s)
Should we add a new attribute to mark handlers as those that treat string and character variables in the same way as string literals?
I've forgotten to paste the link to an alive PR here: https://github.com/dotnet/roslyn/pull/72308
Version Used:
main (10 Jan 2024) in sharplab
Steps to Reproduce:
.NET: https://sharplab.io/#v2:EYLgtghglgdgNAExAagD4AEBMBGAsAKHQGYACLEgYRIG8CT6zT1sAGEgWQAoBKGuhgQGMA9jADOAFzKsSEEgF4SAIgDKSgNz8B9EeKmwpwBSWyb82hrsklBACwgAnG8YDkFF2Yv10AdhIASJQAzYWFqCABfYEdqQQjqYAiNLRIIggigA
.NET Framework: https://sharplab.io/#v2:EYLgHgbALANAJiA1AHwAICYCMBYAUKgZgAIMiBhIgbzyNpONUwAYiBZACgEoqa6+BjAPYA7AM4AXEsyIBDIgF4iAIgDKSgNy8+tIWMkBLYZOAKimTbm11dEovwAWMgE53TAcjJuLV2qgDsRAAkSgBmgoKUMgC+wM6U/FGUwFEaWkRReFFAA=
https://sharplab.io/#v2:EYLgtghglgdgNAGxAN2HAJiA1AHwJJgAOA9gE4AuAzgAQDKAnpeQKZgCwAUAAoCuwCUAMbUAwggiUaI6p2pzqvfkOoAxHjEHkoxGNQCyACgCUcgII0mpWAHNZ8+4J1NqEagF5qAIlqe79uY4wzsDu1ACMfv6BzsIeniKegpH2pMzkPKS6ACSeAGbExADeEAC+wBCkhYIlhcAlvhz2AKIw6KrqmtownC1tYhKUnEA
Diagnostic Id:
N/A
Expected Behavior:
.NET:
.NET Framework:
VB:
Actual Behavior:
.NET:
.NET Framework:
VB: