Bug 288586

Summary: bogus 'incompatible return type applying to constructor-call' error
Product: [Tools] AspectJ Reporter: Godmar Back <godmar>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Godmar Back CLA 2009-09-03 20:11:17 EDT
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.13) Gecko/2009073022 Firefox/3.0.13 (.NET CLR 3.5.30729)
Build Identifier: 

The following code produces a 'incompatible return type error', though - in my opinion - it should not:

package asp;

aspect Intercept {
    ConstructorIntercept around(String s)
        : call(ConstructorIntercept+.new (String)) && args(s)
    {
        return proceed(s + ", World");
    }
}

public class ConstructorIntercept {
    private String s;
    public String toString() { return this.s; }
    ConstructorIntercept(String s) { this.s = s; }

    public static void main(String []av) {
        System.out.println(new ConstructorIntercept("Hello") { });
    }
}



Reproducible: Always

Steps to Reproduce:
1. Save above code in asp/ConstructorIntercept.java
2. Run /opt/aspectj1.6/bin/ajc -classpath /opt/aspectj1.6/lib/aspectjrt.jar:. asp/ConstructorIntercept.java
3. See the error




I believe this is an error because, curiously, the following program compiles and runs:

package asp;

aspect Intercept {
    Object around(String s) 
        : call(ConstructorIntercept+.new (String)) && args(s) 
    {
        return proceed(s + ", World");
    }
}

public class ConstructorIntercept {
    private String s;
    public String toString() { return this.s; }
    ConstructorIntercept(String s) { this.s = s; }

    public static void main(String []av) {
        System.out.println(new ConstructorIntercept("Hello") { });
    }
}

The only difference is the return type of the 'around' advice - Object vs. ConstructorIntercept.  If returning Object is okay, why not ConstructorIntercept?