[bug] "'if' statement can be re-written as '?:'" inspection generates wrong code

In the following code R# suggests to replace if with ?:

            int loadedComponentsCount=0;
            int failedToLoadComponentsCount=0;
            bool success = false;

            . . .

            if (success)
                Interlocked.Increment(ref loadedComponentsCount);
                Interlocked.Increment(ref failedToLoadComponentsCount);

The result of replacement  is :

            Interlocked.Increment(ref success ? loadedComponentsCount : failedToLoadComponentsCount);

such code causes compiler to report an error "A ref or out argument must be an assignable variable".

R# info

JetBrains ReSharper 5 Full Edition Pre-Release
Build 5.0.1603.35 on 2010-01-27T00:17:58

Free evaluation 7 days left
Plugins: 1
#1. “ReSharper PowerToys: ReflectorNavigation” v5.0.0.0 by “JetBrains s.r.o.”
Visual Studio 9.0.

Copyright © 2003–2010 JetBrains s.r.o.. All rights reserved.

Please sign in to leave a comment.