Bug 247307 - [1.5][compiler] Array clone return type should be governed by source level instead of compliance
Summary: [1.5][compiler] Array clone return type should be governed by source level in...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-15 11:57 EDT by Philipe Mulet CLA
Modified: 2009-05-07 03:32 EDT (History)
0 users

See Also:


Attachments
Test patch (7.31 KB, patch)
2008-09-15 12:41 EDT, Philipe Mulet CLA
no flags Details | Diff
Better regression tests (6.29 KB, patch)
2008-09-15 13:22 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.