Bug 103849 - [jdk][compiler] Incorrect ambiguity error for generic types + inheritance
Summary: [jdk][compiler] Incorrect ambiguity error for generic types + inheritance
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-14 12:35 EDT by Osvaldo Pinali Doederlein CLA
Modified: 2005-09-26 11:09 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 Osvaldo Pinali Doederlein CLA 2005-07-14 12:35:42 EDT
I found a new problem in support for generic types.  See this code:

interface Jukebox {
  <M extends Music, A extends Artist<M>> A getArtist (M music);
}
class JukeboxImpl implements Jukebox {
public <M extends Music,A extends Artist<M>> A getArtist (M music){return null;}
  void test () { Elvis king = getArtist(new Rock()); }
}
interface Music {}
class Rock implements Music {}
class Classic implements Music {}
interface Artist<M extends Music> {}
class Elvis implements Artist<Rock> {}
class Mozart implements Artist<Classic> {}

JDT compiler produces errors like: "The method getArtist(Rock) is ambiguous
for the type JukeboxImpl".  But JDK 1.5.0_04's javac compiles this code
normally; not only the method invocation is okay (no ambiguity), but javac
makes the assignments to 'king' and 'amadeus' without even a warning
(even if I use -Xlint:unchecked or -Xlint:all).

This behavior of javac doesn't sound very correct either, because the inferred
type of getArtist()'s return value should be "Artist<Rock>", that is not yet
assignment-compatible to Elvis, this should produce a compiler error (not just
a type-safety warning, because the incompatibility is in the erased type).

The bug in JDT is also related to inheritance.  If you remove the interface
Jukebox, this erro disappears.  There is no difference if I use interfaces,
abstract classes, or a simple base class with a concrete definition of the
method getArtist(); bug always happens if the method overrides something.
Comment 1 Osvaldo Pinali Doederlein CLA 2005-07-14 12:41:59 EDT
Only after posting I found bug 100869, that is apparently the same problem.
Sorry.  But I hope this adds some additional info, in particular I'd like
to confirm that Sun's javac compiler is also wrong so I can report to Sun...
(very likely the JCK has a hole here, otherwise neither JDT nor javac could
be certified as compliant)
Comment 2 Kent Johnson CLA 2005-09-19 13:24:17 EDT
fixed & released in 3.1.1 stream
Comment 3 Kent Johnson CLA 2005-09-19 13:32:11 EDT
Added MethodVerify test066
Comment 4 Kent Johnson CLA 2005-09-19 14:54:01 EDT
released in 3.2 HEAD stream
Comment 5 Maxime Daniel CLA 2005-09-21 10:13:30 EDT
Verified for 3.2 M2 with build I20050920-0010.
Comment 6 Olivier Thomann CLA 2005-09-26 11:09:01 EDT
Verified for 3.1.1 using M20050923-1430.