Priority
Normal
Type
Bug 
State
Fixed 
Assignee
Alexey Kudravtsev 
Subsystem
Code Analysis. Inspection 
Affected versions
Fixed in
Fixed in build
Next build 
Build
7590
Fixed in build
8088
Subsystems
0, 0
Severity
0
  • Submitted by   Christopher Manning
    2 years ago (04 Jan 2008 07:40)
  • Updated by   root
    3 weeks ago (17 Jan 2010 19:57)
  • Jira: IDEA-42470
    (history, comments)

IDEA-42470

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

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.



Environment: any OS

Issue was resolved
Comments (1)
 
History (1)
 
Links
 
Eugene Vigdorchik
  Eugene Vigdorchik
07 Jan 2008 12:46
(2 years ago)
#permalink
Type inference corner case with inferring from other type parameter's extends type list should be looked into.