Bug 247307

Summary: [1.5][compiler] Array clone return type should be governed by source level instead of compliance
Product: [Eclipse Project] JDT Reporter: Philipe Mulet <philippe_mulet>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.5   
Target Milestone: 3.5 M3   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Test patch
none
Better regression tests none

Description Philipe Mulet CLA 2008-09-15 11:57:03 EDT
3.5M1

In compliance 1.5 but source level 1.4, the following code should be rejected, but Eclipse does accept it incorrectly.

public class X {
	void foo(long[] longs) throws Exception {
		long[] other = longs.clone();
	}
}

should report type mismatch:
----------
1. ERROR in X.java (at line 3)
        long[] other = longs.clone();
                       ^^^^^^^^^^^^^
Type mismatch: cannot convert from Object to long[]
----------
Comment 1 Philipe Mulet CLA 2008-09-15 12:41:10 EDT
Created attachment 112557 [details]
Test patch
Comment 2 Philipe Mulet CLA 2008-09-15 13:22:12 EDT
Created attachment 112567 [details]
Better regression tests

Added ArrayTest#test014-017
Comment 3 Philipe Mulet CLA 2008-09-15 13:24:16 EDT
Change being combined with bug 247292.
Specific fix takes place in 2 places:

MessageSend#computeConversion(...)

following portion should refer to sourceLevel instead of complianceLevel:

		} 	else if (this.actualReceiverType.isArrayType()
						&& runtimeTimeType.id != TypeIds.T_JavaLangObject
						&& this.binding.parameters == Binding.NO_PARAMETERS
						&& scope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_5
						&& CharOperation.equals(this.binding.selector, TypeConstants.CLONE)) {
					// from 1.5 compliant mode on, array#clone() resolves to array type, but codegen to #clone()Object - thus require extra inserted cast
			this.valueCast = runtimeTimeType;
Comment 4 Philipe Mulet CLA 2008-09-15 13:25:12 EDT
also MessageSend#resolveType(...) should refer to sourceLevel instead of complianceLevel in following code:

	// from 1.5 compliance on, array#clone() returns the array type (but binding still shows Object)
	if (this.actualReceiverType.isArrayType()
			&& this.binding.parameters == Binding.NO_PARAMETERS
			&& compilerOptions.complianceLevel >= ClassFileConstants.JDK1_5
			&& CharOperation.equals(this.binding.selector, TypeConstants.CLONE)) {
		this.resolvedType = this.actualReceiverType;
Comment 5 Philipe Mulet CLA 2008-09-17 05:10:31 EDT
Released for 3.5M3.
Fixed
Comment 6 Kent Johnson CLA 2008-10-28 13:07:27 EDT
Verified for 3.5M3 using I20081026-2000 build.