Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 367534 - [inline] Inline Local Variable does not qualify accesses to shadowed fields
Summary: [inline] Inline Local Variable does not qualify accesses to shadowed fields
Status: CLOSED DUPLICATE of bug 367536
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.8   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-24 05:12 EST by Max Schaefer CLA
Modified: 2012-01-03 11:12 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Max Schaefer CLA 2011-12-24 05:12:37 EST
Build Identifier: M20110909-1335

Consider the following program:

  public class A {
    int f = 42;
    int foo() {
      int r = f;
      int f = 23;
      return r;
    }
	
    public static void main(String[] args) {
      System.out.println(new A().foo());
    }
  }

This program prints "42". Note that the reference to field "f" in the initialiser of local variable "r" is shadowed later on by the local variable "f". Inlining local variable "r" yields the following program:


  public class A {
    int f = 42;
    int foo() {
      int f = 23;
      return f;  // should be "return this.f;"
    }
	
    public static void main(String[] args) {
      System.out.println(new A().foo());
    }
  }

This is wrong: the program now prints "23", since the reference "f" now refers to the local variable.

Reproducible: Always

Steps to Reproduce:
See above description.
Comment 1 Dani Megert CLA 2012-01-03 11:12:12 EST

*** This bug has been marked as a duplicate of bug 367536 ***