This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 223937 - [rename-refactoring] NB silently renames a variable in a module to a name of an existent one in another module
Summary: [rename-refactoring] NB silently renames a variable in a module to a name of ...
Status: REOPENED
Alias: None
Product: cnd
Classification: Unclassified
Component: Code Model (show other bugs)
Version: 7.2.1
Hardware: All All
: P3 normal (vote)
Assignee: Vladimir Voskresensky
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-17 14:48 UTC by gugawag
Modified: 2014-11-19 13:47 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
image 1: eclipse informs that this refactoring can leads to a conflict. (70.59 KB, image/png)
2012-12-17 20:22 UTC, gugawag
Details
image 2: the user may continue with the refactoring if he wants. (96.04 KB, image/png)
2012-12-17 20:23 UTC, gugawag
Details

Note You need to log in before you can comment on or make changes to this bug.
Description gugawag 2012-12-17 14:48:05 UTC
Build: 201210100934 (Same result in NB 7.3 Beta 2 Build 201211062253)

NB refactoring support renames a variable inside a module to a name of an existent one in another module, leading to a compilation error: "error: redefinition of 'x'"

Reproducible: Always

Steps to Reproduce:

1. Create a C file with the following code:

#include "h1.h"
#include "h2.h"

extern int x;

int main(){
    printf("%d", x);
}

2. Create a header file named h1.h with the following code:

int x = 10;

3. Create a header file named h2.h with the following code:

int y = 20;

2. Apply the rename to the "y" variable inside the h2.h header, typing in the New Name "x" (NB silently do that):

int x = 20;//refactored from y to x

3. The program does not compile anymore:

h2.h:1: error: redefinition of 'x'
h1.h:1: error: previous definition of 'x' was here
Comment 1 Leonid Lenyashin 2012-12-17 15:38:56 UTC
I'm not sure I understand what is the correct behavior of IDE in this case? Could you please elaborate.
In my view it is incorrect user's action and the best IDE can do is only warn user that the redefinition can occur. This sounds more like enhancement request. But even if it is what you want I'm not sure if we are going to proceed with this. In big projects it would take a lot of time to analyze all possible cases.

BTW, you can get into similar trouble w/o using rename. Assume you have h1.h and h2.h both defining int x. There is nothing wrong with it until there is no c/c++ file including both of them. Once you try to include both - you are in exactly same trouble.
Comment 2 gugawag 2012-12-17 16:07:38 UTC
Hello Leonid.

For any refactoring, the ide shouldn't change the behavior of the program (by definition of refactoring). So, NB shouldn't permit changing the variable y to x, because the behavior of the program will change. For example, Eclipse CDT (C/C++) does not permit this refactoring because it will lead to an inconsistent behavior.

About your example, the IDE must prevent to do this kindle of changing. Again, CDT do that.

Can I reopen the issue?
Comment 3 gugawag 2012-12-17 20:22:28 UTC
Created attachment 129478 [details]
image 1: eclipse informs that this refactoring can leads to a conflict.
Comment 4 gugawag 2012-12-17 20:23:54 UTC
Created attachment 129479 [details]
image 2: the user may continue with the refactoring if he wants.