Bug 334377 - [1.5][compiler] Invalid 'type mismatch' error in conditional expression (if-else construct behaves correct)
Summary: [1.5][compiler] Invalid 'type mismatch' error in conditional expression (if-e...
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7 M6   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-14 08:38 EST by Fabian CLA
Modified: 2011-03-08 01:08 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fabian CLA 2011-01-14 08:38:56 EST
Build Identifier: M20100909-0800

If the the following three classes are placed in different files conditional expression will throw a syntax error while the equivalent if-else construct is compiled without any errors. Javac compiles this classes without any problems. 
I guess this is the minimal class configuration to produce this behavior. The problem occurred in code generated from ANTLR.

package pkg;
public abstract class Upper<T>  {
	   public static enum Mode {IN,OUT;}
}

package pkg;
public class Lower extends Upper<Lower> {}

package pkg;

public class Bug {

	Upper.Mode m1;
	
	void usage(){
		
		//no syntax error
		Lower.Mode m3;
		if (m1 == null){
			m3 = Lower.Mode.IN;
		} else {
			m3 = m1;
		}

		//syntax error
		Lower.Mode m2 = (m1 == null ?  Lower.Mode.IN : m1);
		
	}
}


Reproducible: Always

Steps to Reproduce:
1.Create classes
2.Save all files!
3.
Comment 1 Olivier Thomann CLA 2011-01-14 08:41:53 EST
Could you please provide your compiler settings ?
Comment 2 Olivier Thomann CLA 2011-01-14 08:44:53 EST
Please provide the jdt.core id.
So far I cannot reproduce. The code compiles fine for me.
Comment 3 Fabian CLA 2011-01-14 08:55:12 EST
Oh, the classes are not complete yet:
public abstract class Upper<T>  

must be

public abstract class Upper<T extends Upper>

But moving from the second version to the first does NOT remove the bug!

My compiler level is 1.6 with default settings.
Comment 4 Olivier Thomann CLA 2011-01-14 09:06:17 EST
This seems to be fixed in HEAD (3.7).
It is only a problem with the incremental builder. If you do a full build of your project, the error goes away.

Srikanth, could you please investigate what change fixed this for 3.7 ?
If not too risky, we might investigate backporting it for 3.6.2.

The latest M-build still contains the bug.
Comment 5 Srikanth Sankaran CLA 2011-01-17 04:12:27 EST
The change to org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.isEquivalentTo(TypeBinding) made on behalf of the fix for bug 186565 seems to have taken care of
this.
Comment 6 Srikanth Sankaran CLA 2011-02-07 00:20:44 EST
(In reply to comment #5)
> The change to
> org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.isEquivalentTo(TypeBinding)
> made on behalf of the fix for bug 186565 seems to have taken care of
> this.

While the change to the method mentioned above ostensibly fixes the problem
reported, the fix for bug 186565 was part of a large set of bug fixes 
(~25 or so) that were made to properly support mixed mode operations of
1.4 and 1.5 source/class files. It is unclear what is the effect of
back porting just one fix to 3.6.2. As such, it is too late to include
this for 3.6.2.

I'll add a regression test for this on HEAD to capture the current case
and close this as a duplicate of bug 186565.
Comment 7 Srikanth Sankaran CLA 2011-02-07 04:56:51 EST
Released org.eclipse.jdt.core.tests.builder.IncrementalTests.testBug334377()
in HEAD for 3.7 M6.

Resolving as WORKSFORME as this is not exactly a duplicate of bug 186565.
Comment 8 Jay Arthanareeswaran CLA 2011-03-08 01:08:45 EST
Verified for 3.7M6 using build I20110301-1537.