Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer does not consistently process methods that return value types by reference #9

Closed
PathogenDavid opened this issue Oct 26, 2018 · 4 comments

Comments

@PathogenDavid
Copy link

The analyzer seems to have some issues with methods that return value types by reference.

Consider this code below:

using System;

namespace InliningAnalyzerIgnoresRefReturnMethods
{
    public class Program
    {
        private static int a;
        private static int b;

        private static ref int Select(bool which)
            => ref (which ? ref a : ref b);

        private static int Select2(bool which)
            => Select(which);

        public static void Main(string[] args)
        {
            ref int x = ref Select(true);
            int y = Select(true);
            int z = Select2(true); // <-- Commenting out this line causes the call to Select by Select2 to be highlighted.
            Console.WriteLine(x);
            Console.WriteLine(y);
        }
    }
}

If you run the analyzer, none of the calls to Select are highlighted:

image

Oddly enough, if you comment out the call to Select2, its call to Select in it is highlighted:

image

Even more strange, turning off "Prefer 32-bit" or explicitly choosing x64 will also fix Select2's call to Select.

@szehetner
Copy link
Owner

There was a bug with matching the signature of ref return methods. This is fixed now, the 2 Select calls in Main are now also highlighted correctly.

The reason why it didn't work for x86 was that the Jit Compiler seems to emit the ETW event for the Select2->Select call twice, whereas it is only emitted once for x64. No idea why that is the case, but the doubled method call led to the overload resolution logic to kick in, which didn't work because of the missing ref return support. In the x64 case there is only one call, so the signature isn't needed to match the method call.

@PathogenDavid
Copy link
Author

Thanks for the prompt fix!

@szehetner
Copy link
Owner

FYI, I just published a new version (0.7.3) that contains this fix.

@PathogenDavid
Copy link
Author

PathogenDavid commented Nov 1, 2018

Thanks! The fix works, but I unfortunately found a similar issue, which I've described in #10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants