dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.92k stars 4.02k forks source link

Debugger support for discards #18202

Open miloush opened 7 years ago

miloush commented 7 years ago

First I want to commend the decision that the _ is not a discard when declared as a variable. I haven't been using _ as standalone variables before, but I started using this "variable feature" for the purpose of debugging discards. It allows me to hover over the _ during debugging and see the "discarded" value, without any modifications to that code.

I wonder whether people would find it useful to have the discarded values in the Auto window just like we have it now for (also often discarded) return values of the methods, or perhaps even the debug tips on hover, without the need to declare the variable?

jnm2 commented 7 years ago

Could you work around collisions?

_ = Foo(); // I think debugger expressions are evaluated as text,
_ = Bar(); // so how does it tell apart "_" and "_" when you hover?
miloush commented 7 years ago

Well, one option is to remember the last one, effectively the same behavior as if object _; had been declared above your lines.

The watch/auto window could probably be supplied with more information from the call site, but I agree that if the debugger only uses the symbol name and that gets to be "_" in this case, the hovering part might not be feasible.

miloush commented 7 years ago

Also the debug tip for var displays the actual type on hover, so I guess there si more than just a string being passed around?

miloush commented 7 years ago

@jnm2 yes, I agree, but that wasn't my point. My point was that if you do

var a = 4;
var b = "";

then you can hover over var and they will show different types (even in the same stack frame). To be fair though, that's probably a different mechanism than debug time tips. Either way, discussing this sounds more like an implementation detail of the proposed feature.

jnm2 commented 7 years ago

Ah, gotcha. Never noticed that before.

jrmoreno1 commented 3 years ago

Just came here to make this suggestion, but found this when checking to see if it had already been made. Either that or a way to make the pragma to disable the warning for an unused variable only apply to the next line.

I need the value when debugging, the program doesn't need it to execute.