Bug 328689 - [1.4][compiler] "Incompatible conditional operand types Class and Class"
Summary: [1.4][compiler] "Incompatible conditional operand types Class and Class"
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.7 M4   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-26 07:08 EDT by Markus Keller CLA
Modified: 2010-12-07 09:05 EST (History)
5 users (show)

See Also:
Olivier_Thomann: review+


Attachments
Proposed patch - no tests yet (1.12 KB, patch)
2010-10-28 10:14 EDT, Srikanth Sankaran CLA
no flags Details | Diff
Patch with test (3.16 KB, patch)
2010-10-29 04:15 EDT, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2010-10-26 07:08:27 EDT
HEAD

The snippet below produces a bad compile error when compiled against a 1.6 JRE but with compiler compliance 1.4: "Incompatible conditional operand types Class and Class".

package snippet;
import java.util.Random;
public class Snippet {
	Class c= new Random().nextBoolean() ? int.class : long.class;
}

Is OK with pure 1.4 or 1.6. Real life example is in class CocoaUtil in org.eclipse.ui.cocoa when you don't have Java 1.4 installed.
Comment 1 Olivier Thomann CLA 2010-10-26 08:55:56 EDT
Srikanth,

When we are not using generic information, should not we convert to erasure()?
This would be org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.resolveType(BlockScope) line 522.
Comment 2 Olivier Thomann CLA 2010-10-28 09:04:01 EDT
This is also a consequence of bug 324850.
Comment 3 Srikanth Sankaran CLA 2010-10-28 10:14:48 EDT
Created attachment 181953 [details]
Proposed patch - no tests yet
Comment 4 Srikanth Sankaran CLA 2010-10-29 04:15:22 EDT
Created attachment 182018 [details]
Patch with test
Comment 5 Srikanth Sankaran CLA 2010-10-29 04:16:24 EDT
Olivier, please review. TIA - Passes all JDT/Core tests.
Comment 6 Jay Arthanareeswaran CLA 2010-10-29 07:19:52 EDT
Just verified that build I20101028-1441 does not have this bug.
Comment 7 Olivier Thomann CLA 2010-10-29 13:00:10 EDT
Patch looks good.
Comment 8 Srikanth Sankaran CLA 2010-11-01 10:47:49 EDT
Released in HEAD for 3.7 M4
Comment 9 Ayushman Jain CLA 2010-12-07 09:05:46 EST
Verified for 3.7M4 using build I20101205-2000.