Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 "Change signature" refactoring fails
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MichaelH
Junior Member

10 Posts

Posted - Oct 01 2018 :  06:35:36 AM  Show Profile  Reply with Quote

class Foo
{
  public:
    int doFoo(int bar, bool baz) { return (baz ? 42 : bar); };
}

class SubFoo : public Foo
{
  public:
    int doFoo(int bar) { return Foo::doFoo(bar, false); };
}


Attempting to refactor the doFoo() function via "Change signature" (switching the places of the 'int bar' and 'bool baz' parameters) the Foo class leads to unexpected results and an error:


class Foo
{
  public:
    // All good & well here
    int doFoo(bool baz, int bar) { return (baz ? 42 : bar); };
}

class SubFoo : public Foo
{
  public:
    // Error here: SubFoo::doFoo() got the 'bool baz' parameter from Foo:doFoo()
    int doFoo(bool baz, int bar) { return Foo::doFoo(false, bar); };
}


Fortunately Visual assists normally warns that something went wrong ("Visual Assist failed to modify one or more files...") - even though the error message is incorrect too (it did change the file, but incorrectly)

System Info:
Visual Studio 2015 Update 3, C++
License: [email protected] (2-user license) Support ends 2019.06.14
VA_X.dll file version 10.9.2283.2 built 2018.08.02
DevEnv.exe version 14.0.25420.1 Professional
msenv.dll version 14.0.25431.1
Comctl32.dll version 6.10.17134.285
Windows 10 10.0 Build 17134.285
8 processors (x86-64, WOW64)
Language info: 1252, 0x407

Edited by - MichaelH on Oct 01 2018 08:56:08 AM

feline
Whole Tomato Software

United Kingdom
18750 Posts

Posted - Oct 01 2018 :  08:03:29 AM  Show Profile  Reply with Quote
Have you tried compiling your sample code? I ask because in the SubFoo class, inside the doFoo function body, you only pass one parameter to the parent class function call, but two parameters are required. So if VA is going to try to update this correctly, we will have problems, since the code is not right to start with.

It raises an interesting point about error checking, and allowing the Change Signature to run when there is a function call that we won't be able to update correctly.

I have put in a feature request to check the number of parameters is correct in all calls we want to update before trying to do the updates:

case=119714

zen is the art of being at one with the two'ness
Go to Top of Page

MichaelH
Junior Member

10 Posts

Posted - Oct 01 2018 :  09:02:20 AM  Show Profile  Reply with Quote
My apologies feline, I must have accidently removed the second parameter in the SubFoo::doFoo() function while prettying-up the code (As you may have guessed, the code above is not the code that made me run across the issue initially)

I've updated my original post, and double-checked that the code compiles (and that the error issue persists) - unfortunatly it did.
As you can see, in SubFoo::doFoo() the 'return Foo::doFoo(bar, false);' is properly swapped to `return Foo::doFoo(false, bar)` - but still, the parameter list for SubFoo::doFoo() is expanded from 'SubFoo::doFoo(int bar)' to 'SubFoo::doFoo(bool baz, int bar)'

Edited by - MichaelH on Oct 01 2018 09:05:35 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18750 Posts

Posted - Oct 01 2018 :  11:19:22 AM  Show Profile  Reply with Quote
Ah, I see more clearly what is going wrong here. I have put in a bug report for this:

case=119722

Thank you for the clear explanation. Sometimes I focus on the wrong feature in the code sample, and go off in the wrong direction

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000