Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 40311 Details for
Bug 139931
[1.5][compiler] Unnecessary cast warning and varargs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
139931.txt (text/plain), 6.00 KB, created by
Philipe Mulet
on 2006-05-03 18:32:34 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2006-05-03 18:32:34 EDT
Size:
6.00 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java,v >retrieving revision 1.42 >diff -u -r1.42 VarargsTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java 31 Mar 2006 22:14:20 -0000 1.42 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java 3 May 2006 22:31:14 -0000 >@@ -1402,9 +1402,14 @@ > " }\n" + > "}\n", > }, >- // ensure no varargs warning >+ // check no varargs warning > "----------\n" + >- "1. ERROR in X.java (at line 16)\n" + >+ "1. WARNING in X.java (at line 13)\n" + >+ " varargs((Serializable[])new Object[] {1, 2}); //warns \"Varargs argument Object[] \n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Unnecessary cast from Object[] to Serializable[]\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 16)\n" + > " Zork z;\n" + > " ^^^^\n" + > "Zork cannot be resolved to a type\n" + >@@ -1547,7 +1552,12 @@ > "}\n", > }, > "----------\n" + >- "1. ERROR in X.java (at line 15)\n" + >+ "1. WARNING in X.java (at line 10)\n" + >+ " varargs((Serializable) new Object[] {1, 2});\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Unnecessary cast from Object[] to Serializable\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 15)\n" + > " Zork z;\n" + > " ^^^^\n" + > "Zork cannot be resolved to a type\n" + >@@ -1603,13 +1613,18 @@ > "}\n", > }, > "----------\n" + >- "1. WARNING in X.java (at line 10)\r\n" + >- " array((Serializable[]) new Serializable[] {3, 4}); //warns about unnecessary cast\r\n" + >+ "1. WARNING in X.java (at line 10)\n" + >+ " array((Serializable[]) new Serializable[] {3, 4}); //warns about unnecessary cast\n" + > " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + > "Unnecessary cast from Serializable[] to Serializable[]\n" + > "----------\n" + >- "2. ERROR in X.java (at line 14)\r\n" + >- " Zork z;\r\n" + >+ "2. WARNING in X.java (at line 13)\n" + >+ " array((Serializable[]) new Object[] {1, 2}); // CCE at run time\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Unnecessary cast from Object[] to Serializable[]\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 14)\n" + >+ " Zork z;\n" + > " ^^^^\n" + > "Zork cannot be resolved to a type\n" + > "----------\n"); >@@ -1640,4 +1655,31 @@ > "Zork cannot be resolved to a type\n" + > "----------\n"); > } >+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=133931 >+ public void test047() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " Y<String> [] foo() {\n" + >+ " return null;\n" + >+ " }\n" + >+ " void bar(Y... y) {\n" + >+ " }\n" + >+ " void fred() {\n" + >+ " bar(foo());\n" + >+ " bar((Y[])foo());\n" + >+ " Zork z;\n" + >+ " }\n" + >+ "}\n" + >+ "class Y<E> {\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 10)\n" + >+ " Zork z;\n" + >+ " ^^^^\n" + >+ "Zork cannot be resolved to a type\n" + >+ "----------\n"); >+ } > } >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java,v >retrieving revision 1.70 >diff -u -r1.70 ASTNode.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 28 Mar 2006 20:29:56 -0000 1.70 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 3 May 2006 22:31:19 -0000 >@@ -253,7 +253,7 @@ > if (varargsType.dimensions < dimensions) { > scope.problemReporter().varargsArgumentNeedCast(method, lastArgType, invocationSite); > } else if (varargsType.dimensions == dimensions >- && varargsType.leafComponentType != lastArgType.leafComponentType() >+ && varargsType.leafComponentType.erasure() != lastArgType.leafComponentType().erasure() > && lastArgType.isCompatibleWith(varargsType)) { > scope.problemReporter().varargsArgumentNeedCast(method, lastArgType, invocationSite); > } >Index: compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java,v >retrieving revision 1.99 >diff -u -r1.99 CastExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java 31 Mar 2006 22:13:25 -0000 1.99 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java 3 May 2006 22:31:20 -0000 >@@ -253,8 +253,18 @@ > ArrayBinding varargsType = (ArrayBinding) binding.parameters[varargsIndex]; > TypeBinding lastArgType = alternateArgumentTypes[varargsIndex]; > // originalType may be compatible already, but cast mandated to clarify between varargs/non-varargs call >- if (lastArgType.isCompatibleWith(varargsType.elementsType())) >+ int dimensions = lastArgType.dimensions(); >+ if (varargsType.dimensions < dimensions) { > return; >+ } else if (varargsType.dimensions == dimensions) { >+ if (lastArgType.isCompatibleWith(varargsType.elementsType()) >+ && lastArgType.isCompatibleWith(varargsType)) { >+ return; >+ } >+ if (varargsType.leafComponentType.erasure() == lastArgType.leafComponentType().erasure()) { >+ return; >+ } >+ } > } > } > for (int i = 0; i < argumentLength; i++) {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 139931
:
40256
|
40311
|
40688