Bug 78104 - [1.5][compiler] java.lang.Object.clone() implicitely needs an implicit cast to receiver type
Summary: [1.5][compiler] java.lang.Object.clone() implicitely needs an implicit cast t...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-08 15:37 EST by Olivier Thomann CLA
Modified: 2004-12-14 15:52 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2004-11-08 15:37:03 EST
Using 1.5, the following code should compile fine.

public class X {

  public static void main(String argv[]) {
     int[] tabInt = new int[] {};
     int[] tabInt2 = tabInt.clone();
     System.out.print("SUCCESS");
  }

}

We report:
----------
1. ERROR in C:\tests_sources\X.java (at line 5)
	int[] tabInt2 = tabInt.clone();
	      ^^^^^^^
Type mismatch: cannot convert from Object to int[]
----------
1 problem (1 error)

The return type of clone() is int[], but inside its signature it is still
java.lang.Object.
It adds a cast after the clone call.
Comment 1 Philipe Mulet CLA 2004-11-11 10:23:59 EST
Array#clone() is answering the array type from compliant mode 1.5 on.
Added regression tests: Compliance_1_x#test56
Fixed
Comment 2 Philipe Mulet CLA 2004-11-11 10:24:46 EST
fixed
Comment 3 Philipe Mulet CLA 2004-11-11 11:07:19 EST
The method descriptor in classfile still returns Object, only the MessageSend
resolved type is reflecting the array type.
Comment 4 Philipe Mulet CLA 2004-11-11 11:07:55 EST
Regression tests are actually rather: Compliance_1_x#test090 & test091.
Comment 5 Philipe Mulet CLA 2004-11-11 17:07:29 EST
There is an issue with following code:
public class X {	
	public static void main(String[] arguments) { 
		String[] s = new String[]{"SUCCESS" };	
		System.out.print(s.length);	
		System.out.print(((String[])s.clone())[0]);	
	} 
} 

When changing the resolved type of message send, it optimizes out the need for
runtime checkcast, which is still mandated as the runtime #clone() method is
only of type Object.
Comment 6 Philipe Mulet CLA 2004-11-11 17:24:08 EST
Reused #genericCast slot (renamed into #valueCast) to handle the extra needed cast.
Fixed
Comment 7 Olivier Thomann CLA 2004-12-14 15:52:53 EST
Verified in 200412140800