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

BUG: CC0091 (make static) changes references incorrectly when used as a method group and in conjunction with another method invocation #680

Closed
jakubsuchybio opened this issue Jan 27, 2016 · 2 comments

Comments

@jakubsuchybio
Copy link

This is producing an incorrect fix:

class Bar
{
    void ShouldBeStatic()
    {
    }
    void Caller()
    {
        Foo.M(new Baz(ShouldBeStatic));
    }
}
class Foo
{
    public static void M(Baz b) { }
}
class Baz
{
    public Baz(Action a)
    {
    }
}

This is the current fix, broken (other classes omitted):

class Bar
{
    static void ShouldBeStatic()
    {
    }
    void Caller()
    {
        M(new Baz(ShouldBeStatic));
    }
}

This is the expected fix (other classes omitted, only static added to method, nothing else changed):

class Bar
{
    static void ShouldBeStatic()
    {
    }
    void Caller()
    {
        Foo.M(new Baz(ShouldBeStatic));
    }
}

Here is the original description from @jakubsuchybio:

I found another error in CC0091 which somehow changes another method.
Dunno why it is changing things in another method not related to the changed method.

        private void ResetButton_Confirm(Gump sender, bool response)
        {
            if( response )
            {
                PerConfig.DefaultMacros();
                MacroProvider.InstanceIndex = 0;
            }

            GMacroEditorForm.Open();
        }

        private void ResetButton_OnClick(Gump g)
        {
            this.Close();
            Gumps.Desktop.Children.Add( new GMessageBoxYesNo(
                ClientLocalization.GetString( "#319#Smazat všechna\rvlastní makra?" ),
                true,
                ResetButton_Confirm ) );
        }

Translates into:

        private static void ResetButton_Confirm(Gump sender, bool response)
        {
            if( response )
            {
                PerConfig.DefaultMacros();
                MacroProvider.InstanceIndex = 0;
            }

            GMacroEditorForm.Open();
        }

        private void ResetButton_OnClick(Gump g)
        {
            this.Close();
            Add( new GMessageBoxYesNo(
                            ClientLocalization.GetString( "#319#Smazat všechna\rvlastní makra?" ),
                            true,
                            ResetButton_Confirm ) );
        }

Here is a picture of preview:
cc0091-crazy-error

Another occurence of this bug here:

        private void Export(string fileName)
        {
            var dialog = new System.Windows.Forms.SaveFileDialog
            {
                FileName = "mwmakra.mul",
                InitialDirectory = Environment.GetFolderPath( System.Environment.SpecialFolder.MyDocuments )
            };

            var result = dialog.ShowDialog();
            if( result == System.Windows.Forms.DialogResult.OK )
            {
                System.IO.File.Copy( fileName, dialog.FileName, true );
            }
            System.IO.File.Delete( fileName );
        }

        private void ExportButton_OnClick(Gump g)
        {
            var fileName = System.IO.Path.GetTempFileName();
            this.Close();
            MacroProvider.Export( fileName );
            GSystemDialogWaiter<string>.Run( Export, fileName, ExportCompleted );
        }

Translates into:

        private static void Export(string fileName)
        {
            var dialog = new System.Windows.Forms.SaveFileDialog
            {
                FileName = "mwmakra.mul",
                InitialDirectory = Environment.GetFolderPath( System.Environment.SpecialFolder.MyDocuments )
            };

            var result = dialog.ShowDialog();
            if( result == System.Windows.Forms.DialogResult.OK )
            {
                System.IO.File.Copy( fileName, dialog.FileName, true );
            }
            System.IO.File.Delete( fileName );
        }

        private void ExportButton_OnClick(Gump g)
        {
            var fileName = System.IO.Path.GetTempFileName();
            this.Close();
            MacroProvider.Export( fileName );
            Run( Export, fileName, ExportCompleted );
        }

Here is a picture of preview of second occurence:
cc0091-crazy-error2

I would post you my whole codebase to test it on it, if you couldn't find a code proof, but this project is not open and my employer wouldn't like it.

@giggio
Copy link
Member

giggio commented Jan 27, 2016

@jakubsuchybio bug confirmed, I have narrowed it down to a simpler case. Thanks for the report.

@giggio giggio changed the title CC0091 changes outside of scoped method BUG: CC0091 (make static) changes references incorrectly when used as a method group and in conjunction with another method invocation Jan 27, 2016
@giggio giggio self-assigned this Jan 28, 2016
martinzimmermann added a commit to martinzimmermann/code-cracker that referenced this issue Jan 28, 2016
@martinzimmermann
Copy link
Contributor

@giggio my pull request also fixes this issue

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

No branches or pull requests

3 participants