Summary: | [1.5][compiler] Internal compiler error while processing Currency | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Philipe Mulet <philippe_mulet> |
Component: | Core | Assignee: | Kent Johnson <kent_johnson> |
Status: | VERIFIED FIXED | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | ||
Version: | 3.1.1 | ||
Target Milestone: | 3.1.1 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Philipe Mulet
2005-09-26 17:54:56 EDT
It seems the following check is missing; but still javac 1.6 accepts the code and we reject it complaining about an ambiguous method; though it should be fine due to presence of varargs method, only one allowing a 4 args invocation. Index: Scope.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v retrieving revision 1.231.2.12 diff -u -r1.231.2.12 Scope.java --- Scope.java 26 Sep 2005 14:13:48 -0000 1.231.2.12 +++ Scope.java 26 Sep 2005 21:55:40 -0000 @@ -3488,8 +3488,10 @@ } level = VARARGS_COMPATIBLE; // varargs support needed } - // now compare standard arguments from 0 to lastIndex + } else if (paramLength != argLength) { + return NOT_COMPATIBLE; } + // now compare standard arguments from 0 to lastIndex for (int i = 0; i < lastIndex; i++) { TypeBinding param = parameters[i]; TypeBinding arg = arguments[i]; Simpler testcase: public class X { void bar() { this.foo("", this, null, ""); } Object foo(String s, X x, Object... obs) { return s; } Object foo(String s, X x, String r, Object o, Object... obs) { return s; } } Released patch to 3.1 maintenance stream, still we shouldn't reject the code. It seems precedence is given to varargs methods with <= parameters than arguments, for instance the following produces ambiguity due to first 2 methods: public class X { void bar() { System.out.println(this.foo(null, "")); } Object foo(Object... obs) { return "1"; } Object foo(String r, Object... obs) { return "2"; } Object foo(String r, Object o, Object... obs) { return "3"; } } Proposed patch: Index: Scope.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v retrieving revision 1.231.2.13 diff -u -r1.231.2.13 Scope.java --- Scope.java 26 Sep 2005 22:18:15 -0000 1.231.2.13 +++ Scope.java 26 Sep 2005 22:35:13 -0000 @@ -40,7 +40,7 @@ public final static int COMPATIBLE = 0; public final static int AUTOBOX_COMPATIBLE = 1; public final static int VARARGS_COMPATIBLE = 2; - + public int kind; public Scope parent; @@ -2798,9 +2798,9 @@ return true; } - if (one.isVarargs() && two.isVarargs() && oneParamsLength - 1 == twoParamsLength) { + if (one.isVarargs() && two.isVarargs() && oneParamsLength > twoParamsLength) { // special case when autoboxing makes (int, int...) better than (Object...) but not (int...) or (Integer, int...) - if (((ArrayBinding) twoParams[twoParamsLength - 1]).elementsType().id != TypeIds.T_JavaLangObject) + if (oneParamsLength - 1 == twoParamsLength && ((ArrayBinding) twoParams[twoParamsLength - 1]).elementsType().id != TypeIds.T_JavaLangObject) return false; // check that each parameter before the vararg parameters are compatible (no autoboxing allowed here) for (int i = twoParamsLength - 2; i >= 0; i--) Add Varargs test37 Released into 3.1.1 stream AND HEAD. Verified in M20050923-1430 + JDT/Core 3.1.1RC3 candidate |