Bug 123553 - Can't use named pointcut in advice decl. in generic aspect
Summary: Can't use named pointcut in advice decl. in generic aspect
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.5.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 1.5.1   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-12 00:56 EST by Jan Hannemann CLA
Modified: 2006-02-17 14:42 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Hannemann CLA 2006-01-12 00:56:24 EST
When defining a generic aspect with a paramterized PC, using that PC in an advice declaration causes an 'incompatible type' error. Example:

public abstract aspect GenericAspect<Par1> {
   abstract pointcut checkpoint(Par1 par1);

   // advice declaration causes error
   after(Par1 par1): checkpoint(par1) {// do something}
}

Using 1.3.0.20051220093604 and AspectJ 1.5.0, the compiler complains:

"incompatible type, expected java.lang.Object found BindingTypePattern(TPar1;, 0).  Check the type specified in your pointcut"  

Since it is possible to paramterize a named PC in subaspects:

public abstract aspect GenericAspect<Par1> {    
   abstract pointcut checkpoint(Par1 par1);
}

public aspect SubAspect1 extends GenericAspect<Main>{
   pointcut checkpoint(Main main): call(void Main.test()) && target(main);
   after (Main main): checkpoint(main) {
       System.out.println("Caught by 1.");
   }
}

public aspect SubAspect2 extends GenericAspect<Main2>{    pointcut checkpoint(Main2 main): call(void Main2.test()) && target(main);
   after (Main2 main): checkpoint(main) {
       System.out.println("Caught by 2.");
   }
} 

... and since it is possible to use generic PC utilizing unnamed PCs in a generic aspect: 

public abstract aspect GenericAspect<Par1> {    
   // works
   after(Par1 par1): call(void Par1.test()) && target(par1) {// something }
} 

... it seems that this is a bug.
Comment 1 Matt Chapman CLA 2006-01-12 04:44:51 EST
Passing over to compiler
Comment 2 Wes Isberg CLA 2006-02-17 14:42:52 EST
This was broken in 1.5.0 but is fixed in HEAD (I assume by Adrian or Andy.)  I'm going to close it as such, at the risk of missing an issue they've found but which is not covered by the test case below, which fails in 1.5.0, passes now, and is checked in as tests/bugs151/pr123553:
---------------------------------------------------
public class A {
    static Object s;
    public static void main(String[] args) {
        String t = "Hello, World!";
        t.toString();
        if (s != t) throw new Error();
    }
    static abstract aspect GenericAspect<T> {
        abstract pointcut checkpoint(T t);

        // advice declaration causes error
        after(T t): checkpoint(t) { s = t;}
    }
    static aspect AAA extends GenericAspect<String>{
        pointcut checkpoint(String s) : target(s) && 
            call(String String.toString());
    }  
}