Bug 108902

Summary: Type mismatch: cannot convert from Collection to Collection
Product: [Tools] AspectJ Reporter: Adrian Colyer <adrian.colyer>
Component: CompilerAssignee: Adrian Colyer <adrian.colyer>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3    
Version: DEVELOPMENT   
Target Milestone: 1.5.0 M4   
Hardware: Macintosh   
OS: All   
Whiteboard:

Description Adrian Colyer CLA 2005-09-07 02:53:36 EDT
(From aspectj-users)

The program below produces the erroneous message:

    [iajc] D:\workdir\DPsample\main\src\com\designpattern\observer\ObserverProt
ocol.aj:39 [error] Type mismatch: cannot convert from Collection to Collection
    [iajc] return observers;
    [iajc]        ^^^^^

//Subject.java
interface Subject {
 public void addObserver(Observer observer);
 public void removeObserver(Observer observer);
 public Collection getObservers();
}
//Observer.java
interface Observer
{
 public void update();
}

//ObserverProtocol
public abstract aspect ObserverProtocol{
 abstract pointcut stateChange(Subject subject);
 after(Subject subject):stateChange(subject){
   Iterator it=subject.getObservers().iterator();
   while(it.hasNext()){
        Observer observer=(Observer)it.next();
        observer.update();
   }
 }
 private Collection Subject.observers=new ArrayList();
 public void Subject.addObserver(Observer observer){
        observers.add(observer);
 }
 public void Subject.removeObserver(Observer observer){
       observers.remove(observer);
 }
 public Collection Subject.getObservers()
 {
  return observers;
 }
}
Comment 1 Adrian Colyer CLA 2005-09-07 02:54:53 EDT
I'm out of the office most of today, will take another look at this tonight... Regards, Adrian.
Comment 2 Adrian Colyer CLA 2005-09-07 15:06:36 EDT
ok, I made some progress on this on the train. The first piece of good news is
that I can reliably reproduce it, and have a failing test case in the suite. I
also know what the cause of the bug is :- the inter-type field has been given
the (correct) type of Collection#RAW, but the return type of the inter-type
method has the type Collection (the generic base type). The compiler compares
the two types by identity and says that they are not the same, resulting in the
confusing error message. 

Now all I need to do is find out why the itd method does not also present its
return type as raw....
Comment 3 Adrian Colyer CLA 2005-09-08 09:41:14 EDT
fix now committed in tree.