Bug 53012 - declare precedence on a class should be a compile-time error
Summary: declare precedence on a class should be a compile-time error
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.1.1   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 1.2   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-24 19:43 EST by Wes Isberg CLA
Modified: 2021-09-02 00:54 EDT (History)
1 user (show)

See Also:


Attachments
Patch for: weaver/src/org/aspectj/weaver/patterns/DeclarePrecedence.java (967 bytes, patch)
2004-02-27 11:13 EST, Andrew Clement CLA
aclement: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Wes Isberg CLA 2004-02-24 19:43:32 EST
The compiler silently accepts

----
public class DeclarePrecedence {
public static void main(String[] args) {
    System.out.println("hello");
}
}
aspect DP {
    declare precedence: DeclarePrecedence, DP;
    before() : staticinitialization(DeclarePrecedence) {
        System.out.println("ok"); 
    }
}
----

Since this is likely to be a mistake, an error would be nice.  However, that
would mean saying (!TargetClass && TargetClass+) to pick out the aspect subtypes
of TargetClass.
Comment 1 Andrew Clement CLA 2004-02-27 11:13:45 EST
Created attachment 8210 [details]
Patch for: weaver/src/org/aspectj/weaver/patterns/DeclarePrecedence.java

This will produce a compile time error message if a declare precedence
statement includes a non-aspect type.
Comment 2 Jim Hugunin CLA 2004-03-18 13:50:07 EST
I'm a little worried that this change would prevent the use of marker 
interfaces for precendence, something like this:

public aspect Priority {
    public interface Highest {}
    public interface Lowest {}
    declare precedence: Highest+, *, Lowest+;
}

aspect Security implements Priority.Highest {}

I'd suggest modifying Andy's patch to check if pi.isIncludeSubtypes() and if 
so not to produce an error since it is possible for an aspect to match any 
such pattern.

Otherwise, I'm assigning this to Andy to implement his patch and add both 
Wes's original positive test case and my negative test case to the test suite.
Comment 3 Andrew Clement CLA 2004-03-19 04:45:30 EST
Fix checked in.  I modified my patch to allow for non-aspect types where the 
subtypes are included.  Both test cases are now in ajcTests.xml.  Here is the 
error message that now comes out whilst compiling Wes' test.  Wording is ok I 
hope?

"Non-aspect types can only be specified in a declare precedence statement when 
subtypes are included.  Non-aspect type is : DeclarePrecedenceTestClass"

Comment 4 Adrian Colyer CLA 2004-03-19 09:45:12 EST
updating target flag to indicate inclusion in 1.2 release.