Bug 232558

Summary: [compiler] += is not allowed between Object and String
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.4   
Target Milestone: 3.5 M4   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix
none
Proposed fix (2)
none
updated patch based on HEAD none

Description Olivier Thomann CLA 2008-05-16 14:27:35 EDT
Using jdk7b25, this code now compiles fine:

public class X {
	public static void main(String[] args) {
			Object o = new X();
			String s = "World";
			o += s;
			System.out.println(o);
	}
	public String toString() {
		return "Hello";
	}
}

We reject it with:
[compiled 10 lines in 422 ms: 23.6 lines/s]
----------
1. ERROR in D:\tests_sources\X.java (at line 5)
	o += s;
	^^^^^^
The operator += is undefined for the argument type(s) Object, String
----------
1 problem (1 error)

JDK6 still fails to compile it. So this should be done only if the compliance is 1.7.

See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4741726 for further details.
Comment 1 Olivier Thomann CLA 2008-05-16 16:28:50 EDT
This is related bug 39248.
It looks like javac changed its mind again.
Comment 2 Olivier Thomann CLA 2008-05-16 16:34:11 EDT
It depends if we want to fix it regardless of the compliance or only for compliance above 1.7.
Comment 3 Olivier Thomann CLA 2008-05-16 16:35:32 EDT
Created attachment 100733 [details]
Proposed fix

Proposed fix if we don't want to check the compliance being >= 1.7.
Comment 4 Olivier Thomann CLA 2008-05-16 16:36:31 EDT
Created attachment 100734 [details]
Proposed fix (2)

Proposed fix if we want to fix this only for compliance >= 1.7.
Comment 5 Olivier Thomann CLA 2008-05-16 16:38:14 EDT
Since the fix is pretty simple, I think this is a good candidate for RC2.
Just need to decide what patch to release.
All tests should be run as this will very likely fail the regression tests for bug 39248.
Comment 6 Philipe Mulet CLA 2008-11-10 07:10:59 EST
Pls release the flavor of the fix which allows it from 1.7 on.
We may want to relax the rule later on, but for now this should be a good emulation.
Comment 7 Olivier Thomann CLA 2008-11-11 18:38:15 EST
Created attachment 117602 [details]
updated patch based on HEAD

Adds new regression tests triggered only when a JDK7 VM is used.
Comment 8 Olivier Thomann CLA 2008-11-12 12:54:42 EST
Released for 3.5M4.
New regression test added in org.eclipse.jdt.core.tests.compiler.regression.AssignmentTest_1_7
Comment 9 Frederic Fusier CLA 2008-12-09 07:18:09 EST
Verified for 3.5M4 using I20081209-0100