Bug 328689

Summary: [1.4][compiler] "Incompatible conditional operand types Class and Class"
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, jarthana, Olivier_Thomann, prakash, pwebster
Version: 3.7Flags: Olivier_Thomann: review+
Target Milestone: 3.7 M4   
Hardware: PC   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed patch - no tests yet
none
Patch with test none

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.