Bug 61768 - scope for intertype methods
Summary: scope for intertype methods
Status: RESOLVED FIXED
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-11 13:35 EDT by Oege de Moor CLA
Modified: 2004-10-21 04:32 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-11 13:35:42 EDT
/* According to the documentation, the scope rules for
   intertype method declarations are interpreted
   from the originating aspect. The only exceptions
   (I thought) are the use of "this" and "super" which refer to
   the target type.

   According to that interpretation, the program below is type correct, but
   ajc generates two error messages, shown in comments
   at the relevant lines. Note that it's ok to access private static
   fields of the aspect, but not to use private classes of the aspect.

   If this is a feature and not a bug, what are the
   precise scope rules for intertype method declarations?
*/

aspect Aspect { 

    private static int y = 5;

    private class A { int x = 3; }

    private static void B.happy() {
	System.out.println(y);          // happy accessing private field y
    }

    private static void B.foo(A z) { 
	System.out.println(z.x); 	// ERROR: The type Aspect.A is not visible
    }

    public void B.bar() {
	B.foo(new A());                 // ERROR: The type A is not visible
    }

}

class B {
}

public class IT { 


    public static void main(String[] args) { 
	new B().bar();
    } 
 
}
Comment 1 Adrian Colyer CLA 2004-08-09 15:30:48 EDT
marked as target 1.2.1
Comment 2 Adrian Colyer CLA 2004-08-11 11:16:26 EDT
Good bug report, thanks. I added a slightly extended version of your test 
program to the test suite:

aspect Aspect { 

 private static int y = 5;

 private class A { int x = 3; }
 
 private static class A2 {}

 private static void B.happy() {
    System.out.println(y);          // happy accessing private field y
 }

 private static void B.foo(A z) { 
    System.out.println(z.x); 
 }
 
 private static void B.foo2(A2 z) {
     System.out.println(z);
 }

 public void B.bar() {
     B.foo(new A());        // CE L37 : no enclosing instance
 }
 
 public void B.bar2() {
     B.foo2(new A2());
 }

}

class B {
}

class IT { 


 public static void main(String[] args) { 
    new B().bar();
 } 

}

This now compiles and correctly finds the types A and A2. Note that line 37 *is 
still an error* (but not the one previously reported) as a non-static inner 
class needs to be within an enclosing instance of the aspect, and the body of an 
ITDM is not such a place.

Will close this bug report once the fix is available for download.
Comment 3 Adrian Colyer CLA 2004-08-11 16:37:01 EDT
Fix now available in latest jar from AspectJ download page.
Comment 4 Adrian Colyer CLA 2004-10-21 04:32:36 EDT
Fix released as part of AspectJ 1.2.1