You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implicit capture fails with nullable value and @ symbol #2573
privatestaticvoidMyFunction<T>(Tcallback)whereT:delegate void(){}publicstaticvoidMain(){letnullableInt=(int?)123;if(let int1 = nullableInt){// This call compiles successfully.MyFunction(()=>Console.WriteLine(int1));}if(let@int2=nullableInt){// Error: "Failed to lookup implicit capture `int2`"MyFunction(()=>Console.WriteLine(@int2));}let@int3=123;// This call also compiles successfully.MyFunction(()=>Console.WriteLine(@int3));}
Tested on 10/15/2026. As shown, implicit capture fails in the second example, where the nullable integer is cast to a plain integer (within the if statement), but only when the variable is prefixed with @. The third example demonstrates that not all@ variables fail to capture.
If you're wondering why I'd bother using @ in the first place, I discovered this issue when using a nullable enum value and attempting a similar setup with a variable named @enum. I first assumed that the issue was because enum is a reserved keyword, but the code above demonstrates that that assumption was wrong.
Activity