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 125920 Details for
Bug 264843
[1.5][compiler] Eclipse compiler fails to reject invalid code with primitives autoboxed to generics
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch and testcase
patch.txt (text/plain), 13.49 KB, created by
Kent Johnson
on 2009-02-17 12:43:11 EST
(
hide
)
Description:
Proposed patch and testcase
Filename:
MIME Type:
Creator:
Kent Johnson
Created:
2009-02-17 12:43:11 EST
Size:
13.49 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#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.121 >diff -u -r1.121 AutoBoxingTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/AutoBoxingTest.java 13 Feb 2009 21:39:27 -0000 1.121 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/AutoBoxingTest.java 17 Feb 2009 17:45:42 -0000 >@@ -5102,4 +5102,70 @@ > "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<T extends Integer> {\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<T extends Integer> {\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"); >+} > } >#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.68 >diff -u -r1.68 LocalDeclaration.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java 11 Sep 2008 10:04:25 -0000 1.68 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java 17 Feb 2009 17:45:43 -0000 >@@ -197,11 +197,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() >- && this.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.43 >diff -u -r1.43 Statement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java 24 Nov 2008 13:13:43 -0000 1.43 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/Statement.java 17 Feb 2009 17:45:43 -0000 >@@ -114,6 +114,17 @@ > > 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.94 >diff -u -r1.94 FieldDeclaration.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java 13 Feb 2009 21:40:39 -0000 1.94 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java 17 Feb 2009 17:45:43 -0000 >@@ -227,11 +227,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() >- && this.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.31 >diff -u -r1.31 CaseStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java 27 Jun 2008 16:03:56 -0000 1.31 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java 17 Feb 2009 17:45:43 -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.65 >diff -u -r1.65 ReturnStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java 13 Feb 2009 21:39:25 -0000 1.65 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java 17 Feb 2009 17:45:43 -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; >@@ -241,12 +240,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() >- && !methodType.isTypeVariable() >- && 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.86 >diff -u -r1.86 Assignment.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java 11 Sep 2008 10:04:25 -0000 1.86 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java 17 Feb 2009 17:45:43 -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; >@@ -179,11 +178,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.53 >diff -u -r1.53 ArrayInitializer.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java 11 Sep 2008 10:04:25 -0000 1.53 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ArrayInitializer.java 17 Feb 2009 17:45:43 -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; >@@ -168,11 +167,7 @@ > if (expression.isConstantValueOfTypeAssignableToType(expressionType, elementType) > || 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);
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 264843
:
125658
| 125920 |
125935