### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java,v retrieving revision 1.64 diff -u -r1.64 LocalDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java 27 May 2008 22:21:13 -0000 1.64 +++ compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java 17 Feb 2009 19:32:06 -0000 @@ -198,11 +198,7 @@ && (this.initialization.bits & ASTNode.UnnecessaryCast) == 0) { CastExpression.checkNeedForAssignedCast(scope, variableType, (CastExpression) this.initialization); } - } else if (scope.isBoxingCompatibleWith(initializationType, variableType) - || (initializationType.isBaseType() // narrowing then boxing ? - && scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5 // autoboxing - && !variableType.isBaseType() - && initialization.isConstantValueOfTypeAssignableToType(initializationType, scope.environment().computeBoxingType(variableType)))) { + } else if (isBoxingCompatible(initializationType, variableType, this.initialization, scope)) { this.initialization.computeConversion(scope, variableType, initializationType); if (this.initialization instanceof CastExpression && (this.initialization.bits & ASTNode.UnnecessaryCast) == 0) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java,v retrieving revision 1.41 diff -u -r1.41 Statement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java 28 Mar 2006 20:29:57 -0000 1.41 +++ compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java 17 Feb 2009 19:32:06 -0000 @@ -104,7 +104,18 @@ } public abstract void generateCode(BlockScope currentScope, CodeStream codeStream); - + + protected boolean isBoxingCompatible(TypeBinding expressionType, TypeBinding targetType, Expression expression, Scope scope) { + if (scope.isBoxingCompatibleWith(expressionType, targetType)) + return true; + + return expressionType.isBaseType() // narrowing then boxing ? + && !targetType.isBaseType() + && !targetType.isTypeVariable() + && scope.compilerOptions().sourceLevel >= org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_5 // autoboxing + && expression.isConstantValueOfTypeAssignableToType(expressionType, scope.environment().computeBoxingType( targetType)); + } + public boolean isEmptyBlock() { return false; } Index: compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java,v retrieving revision 1.88 diff -u -r1.88 FieldDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java 27 May 2008 22:21:13 -0000 1.88 +++ compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java 17 Feb 2009 19:32:06 -0000 @@ -230,11 +230,7 @@ && (this.initialization.bits & ASTNode.UnnecessaryCast) == 0) { CastExpression.checkNeedForAssignedCast(initializationScope, fieldType, (CastExpression) this.initialization); } - } else if (initializationScope.isBoxingCompatibleWith(initializationType, fieldType) - || (initializationType.isBaseType() // narrowing then boxing ? - && initializationScope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5 // autoboxing - && !fieldType.isBaseType() - && initialization.isConstantValueOfTypeAssignableToType(initializationType, initializationScope.environment().computeBoxingType(fieldType)))) { + } else if (isBoxingCompatible(initializationType, fieldType, this.initialization, initializationScope)) { this.initialization.computeConversion(initializationScope, fieldType, initializationType); if (this.initialization instanceof CastExpression && (this.initialization.bits & ASTNode.UnnecessaryCast) == 0) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java,v retrieving revision 1.30 diff -u -r1.30 CaseStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java 27 May 2008 22:21:13 -0000 1.30 +++ compiler/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java 17 Feb 2009 19:32:06 -0000 @@ -127,11 +127,7 @@ } else { return this.constantExpression.constant; } - } else if (scope.isBoxingCompatibleWith(caseType, switchExpressionType) - || (caseType.isBaseType() // narrowing then boxing ? - && scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5 // autoboxing - && !switchExpressionType.isBaseType() - && this.constantExpression.isConstantValueOfTypeAssignableToType(caseType, scope.environment().computeBoxingType(switchExpressionType)))) { + } else if (isBoxingCompatible(caseType, switchExpressionType, this.constantExpression, scope)) { // constantExpression.computeConversion(scope, caseType, switchExpressionType); - do not report boxing/unboxing conversion return this.constantExpression.constant; } Index: compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java,v retrieving revision 1.62 diff -u -r1.62 ReturnStatement.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java 27 May 2008 22:21:13 -0000 1.62 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java 17 Feb 2009 19:32:06 -0000 @@ -11,7 +11,6 @@ package org.eclipse.jdt.internal.compiler.ast; import org.eclipse.jdt.internal.compiler.ASTVisitor; -import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.*; import org.eclipse.jdt.internal.compiler.flow.*; import org.eclipse.jdt.internal.compiler.impl.Constant; @@ -239,11 +238,7 @@ CastExpression.checkNeedForAssignedCast(scope, methodType, (CastExpression) this.expression); } return; - } else if (scope.isBoxingCompatibleWith(expressionType, methodType) - || (expressionType.isBaseType() // narrowing then boxing ? - && scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5 // autoboxing - && !methodType.isBaseType() - && this.expression.isConstantValueOfTypeAssignableToType(expressionType, scope.environment().computeBoxingType(methodType)))) { + } else if (isBoxingCompatible(expressionType, methodType, this.expression, scope)) { this.expression.computeConversion(scope, methodType, expressionType); if (this.expression instanceof CastExpression && (this.expression.bits & (ASTNode.UnnecessaryCast|ASTNode.DisableUnnecessaryCastCheck)) == 0) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java,v retrieving revision 1.82 diff -u -r1.82 Assignment.java --- compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java 27 May 2008 22:21:13 -0000 1.82 +++ compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java 17 Feb 2009 19:32:06 -0000 @@ -12,7 +12,6 @@ package org.eclipse.jdt.internal.compiler.ast; import org.eclipse.jdt.internal.compiler.ASTVisitor; -import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.*; import org.eclipse.jdt.internal.compiler.flow.*; import org.eclipse.jdt.internal.compiler.impl.Constant; @@ -214,11 +213,7 @@ CastExpression.checkNeedForAssignedCast(scope, lhsType, (CastExpression) this.expression); } return this.resolvedType; - } else if (scope.isBoxingCompatibleWith(rhsType, lhsType) - || (rhsType.isBaseType() // narrowing then boxing ? - && scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5 // autoboxing - && !lhsType.isBaseType() - && this.expression.isConstantValueOfTypeAssignableToType(rhsType, scope.environment().computeBoxingType(lhsType)))) { + } else if (isBoxingCompatible(rhsType, lhsType, this.expression, scope)) { this.expression.computeConversion(scope, lhsType, rhsType); if (this.expression instanceof CastExpression && (this.expression.bits & ASTNode.UnnecessaryCast) == 0) { Index: compiler/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java,v retrieving revision 1.50 diff -u -r1.50 ArrayInitializer.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java 27 May 2008 22:21:13 -0000 1.50 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java 17 Feb 2009 19:32:06 -0000 @@ -11,7 +11,6 @@ package org.eclipse.jdt.internal.compiler.ast; import org.eclipse.jdt.internal.compiler.ASTVisitor; -import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.*; import org.eclipse.jdt.internal.compiler.flow.*; import org.eclipse.jdt.internal.compiler.impl.Constant; @@ -169,11 +168,7 @@ || (elementType.isBaseType() && BaseTypeBinding.isWidening(elementType.id, expressionType.id))) || expressionType.isCompatibleWith(elementType)) { expression.computeConversion(scope, elementType, expressionType); - } else if (scope.isBoxingCompatibleWith(expressionType, elementType) - || (expressionType.isBaseType() // narrowing then boxing ? - && scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5 // autoboxing - && !elementType.isBaseType() - && expression.isConstantValueOfTypeAssignableToType(expressionType, scope.environment().computeBoxingType(elementType)))) { + } else if (isBoxingCompatible(expressionType, elementType, expression, scope)) { expression.computeConversion(scope, elementType, expressionType); } else { scope.problemReporter().typeMismatchError(expressionType, elementType, expression, null); #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/AutoBoxingTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AutoBoxingTest.java,v retrieving revision 1.114.2.1 diff -u -r1.114.2.1 AutoBoxingTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AutoBoxingTest.java 30 Jun 2008 19:36:02 -0000 1.114.2.1 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AutoBoxingTest.java 17 Feb 2009 19:32:12 -0000 @@ -4847,4 +4847,129 @@ }, "IJdone"); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=264843 +public void test168() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T a() { return 35; }\n" + + " T[] b() { return new int[]{35}; }\n" + + " T c() { return new Integer(35); }\n" + + " T[] d() { return new Integer[]{35}; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " T a() { return 35; }\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " T a() { return 35; }\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to T\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " T[] b() { return new int[]{35}; }\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " T[] b() { return new int[]{35}; }\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from int[] to T[]\n" + + "----------\n" + + "5. WARNING in X.java (at line 4)\n" + + " T c() { return new Integer(35); }\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " T c() { return new Integer(35); }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Integer to T\n" + + "----------\n" + + "7. WARNING in X.java (at line 5)\n" + + " T[] d() { return new Integer[]{35}; }\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "8. ERROR in X.java (at line 5)\n" + + " T[] d() { return new Integer[]{35}; }\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Integer[] to T[]\n" + + "----------\n" + + "9. WARNING in X.java (at line 5)\n" + + " T[] d() { return new Integer[]{35}; }\n" + + " ^^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=264843 +public void test169() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T x = 12;\n" + + " Byte y = 12;\n" + + " void x(T t) {\n" + + " t = 5;\n" + + " switch (t) {\n" + + " case 1:\n" + + " break;\n" + + " }\n" + + " }\n" + + " void y(Byte t) {\n" + + " t = 5;\n" + + " switch (t) {\n" + + " case 1:\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " T x = 12;\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to T\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " Byte y = 12;\n" + + " ^^\n" + + "The expression of type int is boxed into Byte\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " t = 5;\n" + + " ^\n" + + "Type mismatch: cannot convert from int to T\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " switch (t) {\n" + + " ^\n" + + "The expression of type T is unboxed into int\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " case 1:\n" + + " ^\n" + + "Type mismatch: cannot convert from int to T\n" + + "----------\n" + + "7. WARNING in X.java (at line 12)\n" + + " t = 5;\n" + + " ^\n" + + "The expression of type int is boxed into Byte\n" + + "----------\n" + + "8. WARNING in X.java (at line 13)\n" + + " switch (t) {\n" + + " ^\n" + + "The expression of type Byte is unboxed into int\n" + + "----------\n"); +} }