Bug 346038 - [1.5][compiler] ecj vs. javac differ for methods using vararg parameters of different primitive types
Summary: [1.5][compiler] ecj vs. javac differ for methods using vararg parameters of d...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.8 M4   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 379871 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-05-17 03:23 EDT by Ayushman Jain CLA
Modified: 2012-06-28 08:07 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ayushman Jain CLA 2011-05-17 03:23:59 EDT
The following snippet fails to compile with HEAD. (build I20110514-0800).

package snippet;
class Test {
        public static void foo(int ...i) {}
        public static void foo(double...d) {}
    
        public static void main(String[] args) {
            foo(1, 2, 3);     // foo flagged ambiguous
        }
    }

Eclipse behaviour is consistent with javac 5,6 but with javac7 this has been fixed. See javac bug http://bugs.sun.com/view_bug.do?bug_id=6199075 for detailed explanation.

This needs to be fixed for eclipse compiler as well.
Comment 1 Olivier Thomann CLA 2011-05-17 08:42:26 EDT
I would target 3.7.1 to match the Java 7 behavior when the Java 7 support is released.
Comment 2 Srikanth Sankaran CLA 2011-08-04 00:22:55 EDT
Don't expect to get to this before 3.8. Retargetting.
Comment 3 Srikanth Sankaran CLA 2011-11-15 00:46:31 EST
While working on this I ran into this case in

org.eclipse.jdt.core.tests.compiler.regression.VarargsTest.test015()

where we have codified the wrong behavior as the expected behavior.
The test case being:

public class X {
	public static void main(String[] s) {
		Y.count(new int[0]);// for some reason this is not ambiguous
	}
}
class Y {
	public static void count(int[] array, int ... values) { System.out.print(1); }
	public static void count(int[] array, int[] ... values) { System.out.print(2); }
}

In fact both javac5 and javac6 match eclipse behavior i.e they don't
flag the call as ambiguous. Javac7 does report the call as being ambiguous.

Javac7's behavior is the right one as shown by the following slightly
modified test case:

public class X {
	public static void main(String[] s) {
		Y.count(new int[0]);// for some reason this is not ambiguous
		Y.count(new int[0], 10);  // binds only to 1st count
		Y.count(new int[0], new int[0][0]); // binds only to 2nd count
	}
}
class Y {
	public static void count(int[] array, int ... values) { System.out.print(1); }
	public static void count(int[] array, int[] ... values) { System.out.print(2); }
}

This test case proves that neither is more specific than the other and
so the call is ambiguous.
Comment 4 Srikanth Sankaran CLA 2011-11-17 07:30:47 EST
Combined fix and tests for bug 346039 and bug 346038 have been released into
3.8 stream via 85f48e0f08275e1f81e9995073d5c4f69bfd0707.

Some existing tests had to be remastered - in all instances the behavior
matches JDK 7b147 behavior.
Comment 5 Jay Arthanareeswaran CLA 2011-12-06 06:16:57 EST
Verified for 3.8M4 with build I20111204-2000.
Comment 6 Srikanth Sankaran CLA 2012-05-17 22:22:42 EDT
*** Bug 379871 has been marked as a duplicate of this bug. ***
Comment 7 Srikanth Sankaran CLA 2012-06-28 08:07:43 EDT
*** Bug 383780 has been marked as a duplicate of this bug. ***