roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Expression Evaluator Regression - Expression Evaluation in Watch seems to do not take usings into account

Open Swiftly1 opened this issue 3 years ago • 7 comments

Version Used:

PS C:\Roslyn\roslyn> git rev-parse HEAD
9f883da6e4d576cea93d7271f3e2a52d1f2d6570

obraz

Steps to Reproduce:

obraz

1: dotnet new console

2: paste this code

using System.Linq;

while (true)
{
	var list = new List<string> { "1", "2", "3", "4" };
	Console.WriteLine("asd");
	Thread.Sleep(500);
}

3: put this expression into watch

list.Select(x => Convert.ToInt32(x)).Where(x => x > 1).ToList()

Expected Behavior:

Returns list that contains {"2", "3", "4"}

Actual Behavior:

Returns The debugger is unable to evaluate this expression

Internally it creates this error:

(1,6): error CS1061: 'List<string>' does not contain a definition for 'Select' 

and no accessible extension method 'Select' accepting a first argument of type 'List<string>' 

could be found (are you missing a using directive or an assembly reference?)

My debugging attempt found that methodResolution fails (IsEmpty == true)

obraz

and then this error is generated

obraz

obraz

but I feel like that's because methods are empty when creating BoundMethodGroup

obraz

and that's because something is not found here

obraz

because NamespaceOrTypeSymbol has no informations of System.Linq in it??

I've got lost at this point

Swiftly1 avatar Jun 15 '22 11:06 Swiftly1

Update:

Seems like Convert.ToInt* behaves weirdly, just take a look at this example:

obraz

Swiftly1 avatar Jul 08 '22 18:07 Swiftly1

@tmat do you know what might be going on here. that Convert.ToDecimal works in the watch window, but Convert.ToInt32 does not is... interesting to say the least :)

CyrusNajmabadi avatar Jul 08 '22 19:07 CyrusNajmabadi

The original issue says there is no accessible extension method 'Select' accepting a first argument of type 'List<string>' error, which I'd attribute to some binding issue with top-level code.

that Convert.ToDecimal works in the watch window, but Convert.ToInt32 does not is... interesting to say the least :)

@chuckries This looks like possible VIL interpreter issue.

tmat avatar Jul 08 '22 20:07 tmat

this repros on 17.4 p2 32803.494.main

dibarbet avatar Aug 15 '22 18:08 dibarbet

It seems to be a lack of support on VIL for ReadOnlySpan<char> parameters, which is the case for Convert.ToInt32. This doesn't happen with Convert.ToDecimal because we hook the method with the string parameter instead. 🙂

I'll work on a fix on our side.

isadorasophia avatar Sep 20 '22 01:09 isadorasophia

@isadorasophia what does 'vil' stand for? Thanks!

CyrusNajmabadi avatar Sep 20 '22 15:09 CyrusNajmabadi

@CyrusNajmabadi it's a VS debugger component used for expression evaluation 😁

isadorasophia avatar Sep 20 '22 17:09 isadorasophia

It seems like it's been fixed and pushed to the prod

I guess I'm closing this

obraz

Swiftly1 avatar Dec 24 '22 18:12 Swiftly1