Bug 262257 - [plan] [generics] Compiler fails to report name clash for generics violation via ITD
Summary: [plan] [generics] Compiler fails to report name clash for generics violation ...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Build (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P2 major (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 255848 257437
  Show dependency tree
 
Reported: 2009-01-23 17:57 EST by Andrew Eisenberg CLA
Modified: 2013-06-24 11:08 EDT (History)
1 user (show)

See Also:


Attachments
Project that exhibits this behavior (23.10 KB, application/octet-stream)
2009-01-23 17:58 EST, Andrew Eisenberg CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Eisenberg CLA 2009-01-23 17:57:26 EST
The attached project shows a situation where the structure model is missing a relationship.  The class GenericMethodImpl should have the ITD declared on the interface inside its model, but does not.

The project compiles with no errors, but since the structure model is wrong, AJDT can't properly reconcile it.

To recreate:

1. import project
2. full build (should compile clean)
3. Open GenericMethodImpl
4. There is a reconcile error on the class declaration and the getStuff method because the interface method imlpementation has not been added to the class.
Comment 1 Andrew Eisenberg CLA 2009-01-23 17:58:22 EST
Created attachment 123608 [details]
Project that exhibits this behavior
Comment 2 Andrew Clement CLA 2009-01-23 21:58:09 EST
yikes... is that really the smallest testcase you have...  there are two source
folders and umpteen types... when only 4 things are involved it seems (the
interface, the implementor, the aspect and the other bound, Type1).  Here is a
much simpler file with the same behaviour:

---
import java.util.*;

interface I {
        public <T> List<T> getStuff();
}

class C<D extends Set> implements I {
        public <T extends D> List<T> getStuff(){
                return new LinkedList<T>();
        }
}

aspect X {
        public <T> List<T> I.getStuff(){
                return new ArrayList<T>();
        }
}
---

This should actually be a compile time error, there is no missing relationship
because it should not compile.  If you had looked with javap -private on the
GenericMethodImpl you'd see that the compile did not include the variant of the
method that returns an ArrayList in the woven target class - although an
erroneous weavinfo message will come out if you use -showWeaveInfo.  (I suspect
indicating a match occurred but not a weave)

You cannot have two methods in the target type with the same erasure, it is a
name clash - exactly as attempted in this pure java program:

---
import java.util.*;

interface I {
        public <T> List<T> getStuff();
}

class P implements I {
  public <T> List<T> getStuff() { return new LinkedList<T>();}
}

class C<D extends Set> extends P {
        public <T extends D> List<T> getStuff(){
                return new LinkedList<T>();
        }
}
---

Generic ITDs 1\src\Y.java:12 [error] Name clash: The method getStuff(
) of type C<D> has the same erasure as getStuff() of type P but does not
override it public <T extends D> List<T> getStuff(){
                             ^^^^^^^^
1 error

And if the ITD can manage to get onto an intermediate class in the hierarchy:

---
import java.util.*;

interface I {
        public <T> List<T> getStuff();
}

class P implements I {}

class C<D extends Set> extends P {
        public <T extends D> List<T> getStuff(){
                return new LinkedList<T>();
        }
}

aspect X {
        public <T> List<T> I.getStuff(){
                return new ArrayList<T>();
        }
}
---
this reports the same name clash.  So the bug is that if the top-most
implementor contains an name clash there should be a name clash compilation
error.
Comment 3 Andrew Clement CLA 2009-01-23 22:21:44 EST
bug is around ResolvedType.compareToExistingMembers() since that checks, when an intertype decl is added to a topmost implementor, whether the new member clashes with an existing one.
Comment 4 Andrew Clement CLA 2009-02-09 15:20:53 EST
testcode committed for this - commented out in Ajc164tests
Comment 5 Andrew Clement CLA 2013-06-24 11:08:18 EDT
unsetting the target field which is currently set for something already released