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 49388 Details for
Bug 155255
[1.5][compiler] ternary conditional operator returns wrong type
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
155255.txt (text/plain), 11.81 KB, created by
Philipe Mulet
on 2006-09-05 05:30:06 EDT
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Philipe Mulet
Created:
2006-09-05 05:30:06 EDT
Size:
11.81 KB
patch
obsolete
>### 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.57.4.1 >diff -u -r1.57.4.1 LocalDeclaration.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java 2 Jul 2006 10:11:34 -0000 1.57.4.1 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java 5 Sep 2006 09:33:27 -0000 >@@ -89,49 +89,39 @@ > return; > } > int pc = codeStream.position; >- Constant inlinedValue; > > // something to initialize? >- if (initialization != null) { >- // initialize to constant value? >- if ((inlinedValue = initialization.constant) != Constant.NotAConstant) { >- // forget initializing unused or final locals set to constant value (final ones are inlined) >- if (binding.resolvedPosition != -1) { // may need to preserve variable >- int initPC = codeStream.position; >- codeStream.generateConstant(inlinedValue, initialization.implicitConversion); >- codeStream.recordPositionsFrom(initPC, initialization.sourceStart); >- codeStream.store(binding, false); >- binding.recordInitializationStartPC(codeStream.position); >- // codeStream.lastInitStateIndexWhenRemovingInits = -2; // reinitialize remove index >- // codeStream.lastInitStateIndexWhenAddingInits = -2; // reinitialize add index >- } >- } else { // initializing to non-constant value >- initialization.generateCode(currentScope, codeStream, true); >+ generateInit: { >+ if (this.initialization == null) >+ break generateInit; >+ // forget initializing unused or final locals set to constant value (final ones are inlined) >+ if (binding.resolvedPosition < 0) { >+ if (initialization.constant != Constant.NotAConstant) >+ break generateInit; > // if binding unused generate then discard the value >- if (binding.resolvedPosition != -1) { >- // 26903, need extra cast to store null in array local var >- if (binding.type.isArrayType() >- && (initialization.resolvedType == TypeBinding.NULL // arrayLoc = null >- || ((initialization instanceof CastExpression) // arrayLoc = (type[])null >- && (((CastExpression)initialization).innermostCastedExpression().resolvedType == TypeBinding.NULL)))){ >- codeStream.checkcast(binding.type); >- } >- codeStream.store(binding, false); >- if (binding.initializationCount == 0) { >- /* Variable may have been initialized during the code initializing it >- e.g. int i = (i = 1); >- */ >- binding.recordInitializationStartPC(codeStream.position); >- // codeStream.lastInitStateIndexWhenRemovingInits = -2; // reinitialize remove index >- // codeStream.lastInitStateIndexWhenAddingInits = -2; // reinitialize add index >- } >+ // TODO why not simply discard value ? >+ initialization.generateCode(currentScope, codeStream, true); >+ if ((binding.type == TypeBinding.LONG) || (binding.type == TypeBinding.DOUBLE)) { >+ codeStream.pop2(); > } else { >- if ((binding.type == TypeBinding.LONG) || (binding.type == TypeBinding.DOUBLE)) { >- codeStream.pop2(); >- } else { >- codeStream.pop(); >- } >+ codeStream.pop(); > } >+ break generateInit; >+ } >+ initialization.generateCode(currentScope, codeStream, true); >+ // 26903, need extra cast to store null in array local var >+ if (binding.type.isArrayType() >+ && (initialization.resolvedType == TypeBinding.NULL // arrayLoc = null >+ || ((initialization instanceof CastExpression) // arrayLoc = (type[])null >+ && (((CastExpression)initialization).innermostCastedExpression().resolvedType == TypeBinding.NULL)))){ >+ codeStream.checkcast(binding.type); >+ } >+ codeStream.store(binding, false); >+ if (binding.initializationCount == 0) { >+ /* Variable may have been initialized during the code initializing it >+ e.g. int i = (i = 1); >+ */ >+ binding.recordInitializationStartPC(codeStream.position); > } > } > codeStream.recordPositionsFrom(pc, this.sourceStart); >Index: compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java,v >retrieving revision 1.102.4.1 >diff -u -r1.102.4.1 Expression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 2 Jul 2006 10:11:31 -0000 1.102.4.1 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/Expression.java 5 Sep 2006 09:33:27 -0000 >@@ -530,15 +530,16 @@ > scope.problemReporter().autoboxing(this, compileTimeType, runtimeType); > compileTimeType = unboxedType; > } >- } else { >- if (compileTimeType != TypeBinding.NULL && compileTimeType.isBaseType()) { >- TypeBinding boxedType = scope.environment().computeBoxingType(runtimeType); >- if (boxedType == runtimeType) // Object o = 12; >- boxedType = compileTimeType; >- this.implicitConversion = BOXING | (boxedType.id << 4) + compileTimeType.id; >- scope.problemReporter().autoboxing(this, compileTimeType, scope.environment().computeBoxingType(boxedType)); >- return; >- } >+ } else if (compileTimeType != TypeBinding.NULL && compileTimeType.isBaseType()) { >+ TypeBinding boxedType = scope.environment().computeBoxingType(runtimeType); >+ if (boxedType == runtimeType) // Object o = 12; >+ boxedType = compileTimeType; >+ this.implicitConversion = BOXING | (boxedType.id << 4) + compileTimeType.id; >+ scope.problemReporter().autoboxing(this, compileTimeType, scope.environment().computeBoxingType(boxedType)); >+ return; >+ } else if (this.constant != Constant.NotAConstant && this.constant.typeID() != T_JavaLangString) { >+ this.implicitConversion = BOXING; >+ return; > } > int compileTimeTypeID, runtimeTypeID; > if ((compileTimeTypeID = compileTimeType.id) == NoId) { // e.g. ? extends String ==> String (103227) >Index: compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java,v >retrieving revision 1.133.4.2 >diff -u -r1.133.4.2 CodeStream.java >--- compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java 23 Aug 2006 15:34:15 -0000 1.133.4.2 >+++ compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java 5 Sep 2006 09:33:30 -0000 >@@ -1727,37 +1727,34 @@ > } > public void generateConstant(Constant constant, int implicitConversionCode) { > int targetTypeID = (implicitConversionCode & TypeIds.IMPLICIT_CONVERSION_MASK) >> 4; >- if (targetTypeID != 0) { >- switch (targetTypeID) { >- case TypeIds.T_boolean : >- generateInlinedValue(constant.booleanValue()); >- break; >- case TypeIds.T_char : >- generateInlinedValue(constant.charValue()); >- break; >- case TypeIds.T_byte : >- generateInlinedValue(constant.byteValue()); >- break; >- case TypeIds.T_short : >- generateInlinedValue(constant.shortValue()); >- break; >- case TypeIds.T_int : >- generateInlinedValue(constant.intValue()); >- break; >- case TypeIds.T_long : >- generateInlinedValue(constant.longValue()); >- break; >- case TypeIds.T_float : >- generateInlinedValue(constant.floatValue()); >- break; >- case TypeIds.T_double : >- generateInlinedValue(constant.doubleValue()); >- break; >- case TypeIds.T_JavaLangString : >- ldc(constant.stringValue()); >- } >- } else { >- ldc(constant.stringValue()); >+ if (targetTypeID == 0) targetTypeID = constant.typeID(); // use default constant type >+ switch (targetTypeID) { >+ case TypeIds.T_boolean : >+ generateInlinedValue(constant.booleanValue()); >+ break; >+ case TypeIds.T_char : >+ generateInlinedValue(constant.charValue()); >+ break; >+ case TypeIds.T_byte : >+ generateInlinedValue(constant.byteValue()); >+ break; >+ case TypeIds.T_short : >+ generateInlinedValue(constant.shortValue()); >+ break; >+ case TypeIds.T_int : >+ generateInlinedValue(constant.intValue()); >+ break; >+ case TypeIds.T_long : >+ generateInlinedValue(constant.longValue()); >+ break; >+ case TypeIds.T_float : >+ generateInlinedValue(constant.floatValue()); >+ break; >+ case TypeIds.T_double : >+ generateInlinedValue(constant.doubleValue()); >+ break; >+ case TypeIds.T_JavaLangString : >+ ldc(constant.stringValue()); > } > if ((implicitConversionCode & TypeIds.BOXING) != 0) { > // need boxing >#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.96.4.2 >diff -u -r1.96.4.2 AutoBoxingTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/AutoBoxingTest.java 4 Sep 2006 16:26:38 -0000 1.96.4.2 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/AutoBoxingTest.java 5 Sep 2006 09:33:33 -0000 >@@ -3648,4 +3648,66 @@ > "Type mismatch: cannot convert from int to Byte\n" + > "----------\n"); > } >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155255 >+public void test123() { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String[] args) {\n" + >+ " foo1();\n" + >+ " foo2();\n" + >+ " foo3();\n" + >+ " foo4();\n" + >+ " System.out.println(\"[done]\");\n" + >+ " }\n" + >+ " static void foo1() {\n" + >+ " Object x = true ? true : \"\";\n" + >+ " System.out.print(\"[1:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + >+ " }\n" + >+ " static void foo2() {\n" + >+ " Object x = Boolean.TRUE != null ? true : \"\";\n" + >+ " System.out.print(\"[2:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + >+ " }\n" + >+ " static void foo3() {\n" + >+ " Object x = false ? \"\" : false;\n" + >+ " System.out.print(\"[3:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + >+ " }\n" + >+ " static void foo4() {\n" + >+ " Object x = Boolean.TRUE == null ? \"\" : false;\n" + >+ " System.out.print(\"[4:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + >+ " }\n" + >+ "}", // ================= >+ }, >+ "[1:true,java.lang.Boolean][2:true,java.lang.Boolean][3:false,java.lang.Boolean][4:false,java.lang.Boolean][done]"); >+} >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155255 - variation >+public void test124() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " static void foo5() {\n" + >+ " boolean x = false ? \"\" : false;\n" + >+ " System.out.print(\"[4:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + >+ " } \n" + >+ "}", // ================= >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 3)\n" + >+ " boolean x = false ? \"\" : false;\n" + >+ " ^^^^^^^^^^^^^^^^^^\n" + >+ "Type mismatch: cannot convert from Object&Serializable&Comparable<?> to boolean\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 3)\n" + >+ " boolean x = false ? \"\" : false;\n" + >+ " ^^^^^\n" + >+ "The expression of type boolean is boxed into Boolean\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 4)\n" + >+ " System.out.print(\"[4:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + >+ " ^^^^^^^^^^^^\n" + >+ "Cannot invoke getClass() on the primitive type boolean\n" + >+ "----------\n"); >+ } > }
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 155255
:
49388
|
49396