What Is ref-safe-context in C#, and How Does the Compiler Decide It for ref Locals?
ref-safe-context is the scope in which a reference to a variable stays valid. Here are the four contexts, the rule that fixes a ref local's context at its initializer, why ref reassignment can never widen or narrow it, and the CS8157, CS8168, CS8374 and CS9079 errors that fall out of it, with compiler output from C# 14 on .NET 10 and .NET 11 RC1.