4 Replies
cathei
cathei2d ago
From my understanding compiler is complaining because it is worried about entry escaping outside of its valid context. You may add scoped keyword to entry (scoped ReadOnlySpan<char> entry) to make it scoped local to make compiler happy. It should also work if MemoryExtensions.TrimEnd took scoped trimChars, but seems like that is not what we have today. This can be a good reading: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-11.0/low-level-struct-improvements#scoped-locals Some language folks might chime in and add some details too :catcomf:
jborean
jboreanOP2d ago
Thanks I appreciate, I'll have to read through that post as I don't understand how it could be used outside of its valid context but maybe that's just my misunderstanding of spans really
cathei
cathei2d ago
For example you might return entry; that ends up exposing invalid value outside of the method. scoped local introduced to ensure that the variable will not escape current scope. I believe it is also partially backward-compatibility reason involved that we need to explicitly put keyword for it.
jborean
jboreanOP2d ago
ah ok, that makes more sense as I was wracking my brain to figure out how it could have escaped it. Putting scope ... entry did the trick though so thank you very much
Want results from more Discord servers?
Add your server