Bug 62475 - resolution of IT field inits
Summary: resolution of IT field inits
Status: RESOLVED INVALID
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 1.2.1   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-17 09:54 EDT by Oege de Moor CLA
Modified: 2004-10-21 04:30 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oege de Moor CLA 2004-05-17 09:54:32 EDT
/* 
   Intertype field initialisers should be resolved in the aspect
   (lexical scope), for consistency with intertype method and 
   constructor bodies.

   The program below compiles without warning, however, binding z
   to the z field of the target class.
*/



aspect Aspect {

    public int A.x = z; // error: z not visible.

}

class A {
    int z = 0;
}

public class ITA3 {

    public static void main(String[] args) {
	System.out.println(new A().x);
    }

}
Comment 1 Adrian Colyer CLA 2004-08-09 15:31:04 EDT
marked as target 1.2.1
Comment 2 Adrian Colyer CLA 2004-08-11 06:11:27 EDT
This program is compiling as expected (ie. I believe it is correct to bind
A.x to z in this case). 

A field initializer in Java for an instance variable is evaluated, and the 
assignment performed, each time an instance of the class is created (JLS 2.9.2). 
The initialization occurs in the context of the instance being created, so the 
type of 'this' is the targetType of the ITD.

To put it another way, the program below is equivalent to writing:

aspect Aspect {
  public int A.x;
}

class A {
  int z = 0;
  A() { x = z; }
}
Comment 3 Oege de Moor CLA 2004-08-11 06:22:28 EDT
Agreed.
Comment 4 Adrian Colyer CLA 2004-10-21 04:30:51 EDT
Fix released as part of AspectJ 1.2.1