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 195879 Details for
Bug 345559
[1.7][compiler] Type inference for generic allocation can be avoided for invalid constructor
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
released patch
patch345559.txt (text/plain), 16.28 KB, created by
Ayushman Jain
on 2011-05-17 11:35:11 EDT
(
hide
)
Description:
released patch
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2011-05-17 11:35:11 EDT
Size:
16.28 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java,v >retrieving revision 1.84.2.9 >diff -u -r1.84.2.9 AllocationExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java 11 May 2011 08:25:19 -0000 1.84.2.9 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java 17 May 2011 15:14:42 -0000 >@@ -17,7 +17,6 @@ > *******************************************************************************/ > package org.eclipse.jdt.internal.compiler.ast; > >-import org.eclipse.jdt.core.compiler.CharOperation; > import org.eclipse.jdt.internal.compiler.ASTVisitor; > import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; > import org.eclipse.jdt.internal.compiler.codegen.*; >@@ -375,6 +374,10 @@ > } > if (isDiamond) { > TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) this.resolvedType).genericType(), argumentTypes, scope); >+ if (inferredTypes == null) { >+ scope.problemReporter().cannotInferElidedTypes(this); >+ return this.resolvedType = null; >+ } > this.resolvedType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) this.resolvedType).genericType(), inferredTypes, ((ParameterizedTypeBinding) this.resolvedType).enclosingType()); > } > ReferenceBinding allocationType = (ReferenceBinding) this.resolvedType; >@@ -412,13 +415,7 @@ > if (factory instanceof ParameterizedGenericMethodBinding && factory.isValidBinding()) { > return ((ParameterizedTypeBinding)factory.returnType).arguments; > } >- scope.problemReporter().cannotInferElidedTypes(this); >- int arity = allocationType.typeVariables().length; >- TypeBinding [] inferredTypes = new TypeBinding[arity]; >- for (int i = 0; i < arity; i++) { >- inferredTypes[i] = new ProblemReferenceBinding(CharOperation.NO_CHAR_CHAR, null, ProblemReasons.InferenceFailed); >- } >- return inferredTypes; >+ return null; > } > > public void setActualReceiverType(ReferenceBinding receiverType) { >Index: compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java,v >retrieving revision 1.101.2.9 >diff -u -r1.101.2.9 QualifiedAllocationExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java 12 May 2011 06:32:46 -0000 1.101.2.9 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java 17 May 2011 15:14:43 -0000 >@@ -400,6 +400,10 @@ > } > if (isDiamond) { > TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) receiverType).genericType(), argumentTypes, scope); >+ if (inferredTypes == null) { >+ scope.problemReporter().cannotInferElidedTypes(this); >+ return this.resolvedType = null; >+ } > receiverType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) receiverType).genericType(), inferredTypes, ((ParameterizedTypeBinding) receiverType).enclosingType()); > } > ReferenceBinding allocationType = (ReferenceBinding) receiverType; >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemReasons.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemReasons.java,v >retrieving revision 1.14.28.2 >diff -u -r1.14.28.2 ProblemReasons.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemReasons.java 24 Apr 2011 11:01:15 -0000 1.14.28.2 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemReasons.java 17 May 2011 15:14:43 -0000 >@@ -31,5 +31,4 @@ > final int TypeArgumentsForRawGenericMethod = 13; // for generic method > final int InvalidTypeForStaticImport = 14; > final int InvalidTypeForAutoManagedResource = 15; >- final int InferenceFailed = 16; > } >Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v >retrieving revision 1.380.2.5 >diff -u -r1.380.2.5 Scope.java >--- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 10 May 2011 10:22:36 -0000 1.380.2.5 >+++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 17 May 2011 15:14:52 -0000 >@@ -4036,7 +4036,11 @@ > int sfi = 0; > for (int i = 0, length = methods.length; i < length; i++) { > MethodBinding method = methods[i]; >- >+ int paramLength = method.parameters.length; >+ boolean isVarArgs = method.isVarargs(); >+ if (argumentTypes.length != paramLength) >+ if (!isVarArgs || argumentTypes.length < paramLength - 1) >+ continue; // incompatible > TypeVariableBinding[] methodTypeVariables = method.typeVariables(); > int methodTypeVariablesArity = methodTypeVariables.length; > >@@ -4114,6 +4118,8 @@ > staticFactories[sfi++] = new ParameterizedMethodBinding((ParameterizedTypeBinding) environment.convertToParameterizedType(staticFactory.declaringClass), > staticFactory); > } >+ if (sfi == 0) >+ return null; > if (sfi != methods.length) { > System.arraycopy(staticFactories, 0, staticFactories = new MethodBinding[sfi], 0, sfi); > } >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Attic/GenericsRegressionTest_1_7.java,v >retrieving revision 1.1.2.13 >diff -u -r1.1.2.13 GenericsRegressionTest_1_7.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java 17 May 2011 05:13:05 -0000 1.1.2.13 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java 17 May 2011 15:14:59 -0000 >@@ -991,16 +991,6 @@ > " Map<String, Integer> m1 = new StringKeyHashMap<>(10);\n" + > " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + > "Cannot infer elided type(s)\n" + >- "----------\n" + >- "4. ERROR in X.java (at line 11)\n" + >- " Map<String, Integer> m1 = new StringKeyHashMap<>(10);\n" + >- " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >- "The constructor StringKeyHashMap<>(int) is undefined\n" + >- "----------\n" + >- "5. ERROR in X.java (at line 11)\n" + >- " Map<String, Integer> m1 = new StringKeyHashMap<>(10);\n" + >- " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >- "Type mismatch: cannot convert from StringKeyHashMap<> to Map<String,Integer>\n" + > "----------\n"); > } > // check inference at return expression. >@@ -1198,6 +1188,260 @@ > "Y cannot be resolved to a type\n" + > "----------\n"); > } >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 >+// TODO(ayush) enable and update the error message after bug 345968 is fixed >+public void _test0031() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<T> {\n" + >+ " X(T t) {}\n" + >+ " X() {}\n" + >+ " void foo(T a) {\n" + >+ " System.out.println(a);\n" + >+ " }\n" + >+ " class Y<K>{\n" + >+ " Y(T t,K k) {}\n" + >+ " }\n" + >+ " public static void main(String[] args) {\n" + >+ " X<Integer> x1 = new X<>(1,1);\n" + >+ " X<Integer> x2 = new X<>(1);\n" + >+ " X<Integer> x3 = new X<>();\n" + >+ " X<Integer>.Y<String> y1 = new X<>(1,1).new Y<>();\n" + >+ " X<Integer>.Y<String> y2 = new X<>(1,1).new Y<>(1);\n" + >+ " X<Integer>.Y<String> y3 = new X<>(1).new Y<>(1);\n" + >+ " X<Integer>.Y<String> y4 = new X<>(1).new Y<>(\"\",\"\");\n" + >+ " X<Integer>.Y<String> y5 = new X<>(1).new Y<>(1,\"\");\n" + >+ " X<Integer>.Y<String> y6 = new X<>().new Y<>(1,\"\");\n" + >+ " X<Integer>.Y<String> y7 = new X<>().new Y<>(1,1);\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 3)\n" + >+ " X<String> f2 = new X<>(new Y()); \n" + >+ " ^\n" + >+ "Y cannot be resolved to a type\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 >+// TODO(ayush) enable and update the error message after bug 345968 is fixed >+public void _test0032() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<T> {\n" + >+ " X(T t) {}\n" + >+ " X() {}\n" + >+ " X(String abc, String abc2, T... t) {}\n" + >+ " void foo(T a) {\n" + >+ " System.out.println(a);\n" + >+ " }\n" + >+ " class Y<K>{\n" + >+ " Y(T t,String abc, K... k) {}\n" + >+ " }\n" + >+ " public static void main(String[] args) {\n" + >+ " X<Integer> x1 = new X<>(1,1);\n" + >+ " X<Integer> x2 = new X<>(1);\n" + >+ " X<Integer> x3 = new X<>();\n" + >+ " X<Integer> x4 = new X<>(\"\",\"\");\n" + >+ " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + >+ " X<Integer> x6 = new X<>(\"\",\"\",1);\n" + >+ " X<Integer>.Y<String> y1 = new X<>(1,1).new Y<>();\n" + >+ " X<Integer>.Y<String> y2 = new X<>(\"\",1).new Y<>(\"\");\n" + >+ " X<Integer>.Y<String> y3 = new X<>(1).new Y<>(1);\n" + >+ " X<Integer>.Y<String> y4 = new X<>(1).new Y<>(1,\"\");\n" + >+ " X<Integer>.Y<String> y5 = new X<>(1).new Y<>(1,\"\",\"\");\n" + >+ " X<Integer>.Y<String> y6 = new X<>().new Y<>(1,\"\",1);\n" + >+ " X<Integer>.Y<String> y7 = new X<>().new Y<>(\"\",\"\",1);\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 3)\n" + >+ " X<String> f2 = new X<>(new Y()); \n" + >+ " ^\n" + >+ "Y cannot be resolved to a type\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 >+// TODO(ayush) enable and update the error message after bug 345968 is fixed >+public void _test0033() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<T> {\n" + >+ " X(T t) {}\n" + >+ " X() {}\n" + >+ " X(String abc, String abc2, T... t) {}\n" + >+ " void foo(T a) {\n" + >+ " System.out.println(a);\n" + >+ " }\n" + >+ " class Y<K>{\n" + >+ " Y(T t,String abc, K... k) {}\n" + >+ " }\n" + >+ " X<Integer> x1 = new X<>(1,1);\n" + >+ " X<Integer> x2 = new X<>(1);\n" + >+ " X<Integer> x3 = new X<>();\n" + >+ " X<Integer> x4 = new X<>(\"\",\"\");\n" + >+ " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + >+ " X<Integer> x6 = new X<>(\"\",\"\",1);\n" + >+ " X<Integer>.Y<String> y1 = new X<>(1,1).new Y<>();\n" + >+ " X<Integer>.Y<String> y2 = new X<>(\"\",1).new Y<>(\"\");\n" + >+ " X<Integer>.Y<String> y3 = new X<>(1).new Y<>(1);\n" + >+ " X<Integer>.Y<String> y4 = new X<>(1).new Y<>(1,\"\");\n" + >+ " X<Integer>.Y<String> y5 = new X<>(1).new Y<>(1,\"\",\"\");\n" + >+ " X<Integer>.Y<String> y6 = new X<>().new Y<>(1,\"\",1);\n" + >+ " X<Integer>.Y<String> y7 = new X<>().new Y<>(\"\",\"\",1);\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 3)\n" + >+ " X<String> f2 = new X<>(new Y()); \n" + >+ " ^\n" + >+ "Y cannot be resolved to a type\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 >+public void test0034() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<T> {\n" + >+ " X(T t) {}\n" + >+ " X() {}\n" + >+ " void foo(T a) {\n" + >+ " System.out.println(a);\n" + >+ " }\n" + >+ " public static void main(String[] args) {\n" + >+ " X<Integer> x1 = new X<>(1,1);\n" + >+ " X<Integer> x2 = new X<>(1);\n" + >+ " X<Integer> x3 = new X<>();\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 8)\n" + >+ " X<Integer> x1 = new X<>(1,1);\n" + >+ " ^^^^^^^^^^^^\n" + >+ "Cannot infer elided type(s)\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 >+public void test0035() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<T> {\n" + >+ " X(T t) {}\n" + >+ " X() {}\n" + >+ " @SafeVarargs\n" + >+ " X(String abc, String abc2, T... t) {}\n" + >+ " void foo(T a) {\n" + >+ " System.out.println(a);\n" + >+ " }\n" + >+ " public static void main(String[] args) {\n" + >+ " X<Integer> x1 = new X<>(1,1);\n" + >+ " X<Integer> x2 = new X<>(1);\n" + >+ " X<Integer> x3 = new X<>();\n" + >+ " X<Integer> x4 = new X<>(\"\",\"\");\n" + >+ " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + >+ " X<Integer> x6 = new X<>(\"\",\"\",1);\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 10)\n" + >+ " X<Integer> x1 = new X<>(1,1);\n" + >+ " ^^^^^^^^^^^^\n" + >+ "Cannot infer elided type(s)\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 14)\n" + >+ " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + >+ " ^^^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from X<String> to X<Integer>\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 >+public void test0036() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<T> {\n" + >+ " X(T t) {}\n" + >+ " X() {}\n" + >+ " @SafeVarargs\n" + >+ " X(String abc, String abc2, T... t) {}\n" + >+ " void foo(T a) {\n" + >+ " System.out.println(a);\n" + >+ " }\n" + >+ " X<Integer> x1 = new X<>(1,1);\n" + >+ " X<Integer> x2 = new X<>(1);\n" + >+ " X<Integer> x3 = new X<>();\n" + >+ " X<Integer> x4 = new X<>(\"\",\"\");\n" + >+ " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + >+ " X<Integer> x6 = new X<>(\"\",\"\",1);\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 9)\n" + >+ " X<Integer> x1 = new X<>(1,1);\n" + >+ " ^^^^^^^^^^^^\n" + >+ "Cannot infer elided type(s)\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 13)\n" + >+ " X<Integer> x5 = new X<>(\"\",\"\",\"\");\n" + >+ " ^^^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from X<String> to X<Integer>\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 >+public void test0037() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X<T> {\n" + >+ " X(T t) {}\n" + >+ " X() {}\n" + >+ " @SafeVarargs\n" + >+ " X(String abc, String abc2, T... t) {}\n" + >+ " void foo(T a) {\n" + >+ " System.out.println(a);\n" + >+ " }\n" + >+ " class Y<K>{\n" + >+ " @SafeVarargs\n" + >+ " Y(T t,String abc, K... k) {}\n" + >+ " }\n" + >+ " public static void main(String[] args) {\n" + >+ " X<Integer>.Y<String> y1 = new X<>().new Y<>(1);\n" + >+ " X<Integer>.Y<String> y2 = new X<>(1).new Y<>(1);\n" + >+ " X<Integer>.Y<String> y3 = new X<>(\"\",\"\",1).new Y<>(1);\n" + >+ " X<Integer>.Y<String> y4 = new X<>(1,\"\").new Y<>(1,\"\");\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 14)\n" + >+ " X<Integer>.Y<String> y1 = new X<>().new Y<>(1);\n" + >+ " ^^^^^^^^^^^^^^^^^^^^\n" + >+ "Cannot infer elided type(s)\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 15)\n" + >+ " X<Integer>.Y<String> y2 = new X<>(1).new Y<>(1);\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Cannot infer elided type(s)\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 16)\n" + >+ " X<Integer>.Y<String> y3 = new X<>(\"\",\"\",1).new Y<>(1);\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Cannot infer elided type(s)\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 17)\n" + >+ " X<Integer>.Y<String> y4 = new X<>(1,\"\").new Y<>(1,\"\");\n" + >+ " ^^^^^^^^^^^^^\n" + >+ "Cannot infer elided type(s)\n" + >+ "----------\n"); >+} > public static Class testClass() { > return GenericsRegressionTest_1_7.class; > }
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 345559
:
195479
|
195691
|
195699
| 195879