Bug 233838 - Inter-type declarations considered "ambiguous" despite precedence
Summary: Inter-type declarations considered "ambiguous" despite precedence
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.6.0   Edit
Hardware: PC Linux
: P3 major (vote)
Target Milestone: 1.6.1   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-25 01:20 EDT by Brian Ericson CLA
Modified: 2008-05-27 12:50 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Ericson CLA 2008-05-25 01:20:53 EDT
declare precedence for inter-type declarations appears broken in 1.6...

The following compiles correctly in version 1.5.4 (and produces the output "Y.test()" as expected) but the 1.6 and last known good developer builds result in:
Z.java:2 [error] The method test() is ambiguous for the type Z
public static void main(String[] args) throws Exception { new Z().test(); }

1 error

interface X {
   static aspect IMPL {
      public void X.test() { System.out.println("X.test()"); }
   }
}

interface Y {
   static aspect IMPL {
      declare precedence : Y.IMPL, X.IMPL;

      public void Y.test() { System.out.println("Y.test()"); }
   }
}

public class Z implements X, Y {
   public static void main(String[] args) throws Exception { new Z().test(); }
}

Note that you may "trick" ajc into compiling this by casting "new Z()" to either X or Y.  Doing so will give the same runtime result 1.5.4.
Comment 1 Andrew Clement CLA 2008-05-27 01:29:30 EDT
this is due to a rewrite in the 3.3 JDT compiler of the method:

Scope.mostSpecificMethodBinding()

and due to the use of declare precedence to determine ITD ordering being a rare case (usually), there are no tests for it (*sigh*).  The main references to declare precedence throughout the documentation are for determining advice precedence order at a join point when multiple pieces apply and there are many tests for that, it works fine.  However, there is a line in the doc:

---
Given a potential conflict between inter-type member declarations in different aspects, if one aspect has precedence over the other its declaration will take effect without any conflict notice from compiler. This is true both when the precedence is declared explicitly with declare precedence as well as when when sub-aspects implicitly have precedence over their super-aspect.
---

so I am trying to get it to work for 1.6.1.

However, given how it worked in 1.5.4, I think it worked by accident rather than by design and will try and do a better job in 1.6.1


Comment 2 Andrew Clement CLA 2008-05-27 12:50:54 EDT
I've just reworked the Scope code and fixed this problem.  Fix will be in next dev build.  Also added some tests (based on your testcase, thanks for that) - so it can't break again.