History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEADEV-24166
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Normal Normal
Assignee: Alexey Kudravtsev
Reporter: Christopher Manning
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
IDEA: Development

Good code marked as red: use of generics in heterogeneous typesafe map

Created: 04 Jan 08 07:40   Updated: 07 Jan 08 15:16
Component/s: Code Analysis. Inspection, Editor. Error Highlighting
Fix Version/s: Selena 7.0.3

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown
File Attachments: 1. Zip Archive BungGenerics.zip (105 kb)

Environment: any OS

Build: 7,590
Fixed in build: 8,088
Severity: High


 Description  « Hide
In the code, incorrect or incomplete type resolution causes correct code to be given a red underline and red analysis mark in the IntelliJ IDEA editor. The errors can be seen in the CoreMaps class, including its main method, even though it compiles and runs without error (under either JDK1.5 or JDK1.6). They are caused by the setup of the typesafe heterogeneous map in CoreAnnotation/TypesafeMap.

The code implements a version of the heterogeneous typesafe map idiom which Joshua Bloch has spoken about at many recent conferences. This version differs from an EnumMap by assuming a situation where there is a large (open) set of keys for which particular items will only have values for a sparse subset. Keys valid for an object are hence stored in an array.

On any get operation from the map, IDEA incorrectly reports an error of this type:

Inferred type 'CoreMaps.IntegerA' for type parameter 'KEY' is not within its bound; should implement TypeSafeMap.Key<CoreMap,java
.lang.Object>

but this error is wrong and reflects a failure to do type resolution.

The compiler/IDE needs to correctly bind the relevant type variables introduced in get's signature (VALUE, KEY) for each call to the method. The correct bindings are Integer and TypesafeMap.Key<CoreMap,Integer>). If those bindings are done correctly, then the method call compiles okay because the return type is an Integer and the KEY says it will return a Integer. In particular, if those bindings are right then "Object" - which shows up as part of the binding in IntelliJ's error message - should just never show up anywhere.



 All   Comments   Work Log   Change History      Sort Order:
Eugene Vigdorchik - 07 Jan 08 12:46
Type inference corner case with inferring from other type parameter's extends type list should be looked into.