Bug 303814 - The compiler erroneously flags a method about an ambiguous method
Summary: The compiler erroneously flags a method about an ambiguous method
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-24 16:21 EST by Michael Schneider CLA
Modified: 2010-06-30 01:24 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Schneider CLA 2010-02-24 16:21:44 EST
Build Identifier: I20100129-1300

assume the example below: the compiler produces the following error:
The method min(double, double, double[]) is ambiguous for the type Foo	

this happens as soon as I add the var arg.

public class Foo {
	void foo() {
		int x1 = 1;
		int x2= 2;
		int y= min(x1, x2);
	}
	
    public static double min(double first, double second, double... others) {
    	return first;
    }
    
    public static int min(int first, int second, int... others) {
    	return first;
    }
}

Reproducible: Always
Comment 1 Olivier Thomann CLA 2010-02-24 19:17:23 EST
I think this is not an error.
The error is legitimate.

javac 1.5, 1.6 and 1.7 also reports the same error. Both min methods are valid matches for min(x1, x2).
Comment 2 Michael Schneider CLA 2010-02-25 09:27:52 EST
lowering the severity then. Do you know the reasoning behind this error marker? 
still sounds like a bug to me, even if the javac compiler does the same :)
Comment 3 Srikanth Sankaran CLA 2010-02-26 02:30:19 EST
(In reply to comment #2)
> lowering the severity then. Do you know the reasoning behind this error marker? 
> still sounds like a bug to me, even if the javac compiler does the same :)

To cite (JLS 3.0) chapter and verse,

- application of 15.12.2.1 tags both min methods as "potentially
  applicable".

- 15.12.2.2 and 15.12.2.3 do not apply for the case at hand as these
  are concerned with matching (fixed) arity potentially applicable
  methods.

- Application of 15.12.2.4 tags both the "potentially applicable" methods
  as "applicable variable arity methods" and since we now more than one
  choice, method overload resolution proceeds to 15.12.2.5, the selection
  of the "most specific method"

- By the rules of 15.12.2.5, neither method is more specific than the
  other (since on the one hand, double is not a subtype of int and on
  the other hand int[] is not a subtype of double[]). So both methods
  are "maximally specific". Since these methods are not "override 
  equivalent", the method call is ambiguous.

While that is the lower level nitty gritty leading to the error,
the seemingly counter-intuitive picture arises from the fact that
there is a defined subtyping relationship among primitive types
(4.10.1) by which int is a "subtype" of double, 4.10.3 does not
define any subtyping relationship between arrays of primitive
types so that int [] is not a subtype of double [].
Comment 4 Ayushman Jain CLA 2010-03-08 08:02:53 EST
verified for 3.6M6
Comment 5 Jay Arthanareeswaran CLA 2010-03-08 08:25:38 EST
Verified.
Comment 6 Srikanth Sankaran CLA 2010-06-30 01:24:03 EDT
*** Bug 317586 has been marked as a duplicate of this bug. ***