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 take value types by reference #10

Closed
PathogenDavid opened this issue Nov 1, 2018 · 4 comments

Comments

@PathogenDavid
Copy link

Off the heels of #9, I've found another quirk around values by reference, this time with parameters:

using System;

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

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

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

        public static void Main(string[] args)
        {
            bool which = true;
            ref int x = ref Select(ref which);
            int y = Select(ref which);
            int z = Select2(ref which);
            Console.WriteLine(x);
            Console.WriteLine(y);
            Console.WriteLine(z);
        }
    }
}

(Note that the which parameter is passed by reference now.)

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

image

Unlike last time, I did not observe any weirdness involving 32 vs 64 bit or commenting out the Select2 call.

@szehetner
Copy link
Owner

This is fixed now as well, basically the same fix as for ref return values was missing for ref parameters.

FYI:
While I was checking other variants of ref methods, I found that ref readonly methods are not always highlighted as well. The reason is that the JIT Compiler emits a strange signature for these methods. I think this is a bug, so I have created an issue for that (https://github.com/dotnet/coreclr/issues/20754). Just in case you stumble upon this as well.

@PathogenDavid
Copy link
Author

Thanks again, and thanks for the warning!

@szehetner
Copy link
Owner

Version 0.7.4 with this fix has been published.

@PathogenDavid
Copy link
Author

Thanks again, and thanks for fixing the issue in CoreCLR!

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