Bug 108902 - Type mismatch: cannot convert from Collection to Collection
Summary: Type mismatch: cannot convert from Collection to Collection
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: Macintosh All
: P3 major (vote)
Target Milestone: 1.5.0 M4   Edit
Assignee: Adrian Colyer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-07 02:53 EDT by Adrian Colyer CLA
Modified: 2005-09-08 09:41 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.