lovubuntu / checker-framework

Automatically exported from code.google.com/p/checker-framework
0 stars 0 forks source link

AnnotatedTypeVariables bounds don't make sense for class type parameters #270

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Notice that in the attached file the type param bounds are nonsensical.  
The lower bound is Nullable and the upper bound is NonNull.  If you leave out 
the uses of the WithAtv type and just check the file it will give no warning 
even though the bounds don't make sense.

2.  Put a break point in AnnotatedTypeFactory.getAnnotatedType(tree : Tree) 
right before "type" is returned.

3.  Run the NullnessChecker on the attached file.

4.  Notice that on the first call to getAnnotatedType you will be exploring the 
type: 
WithAtv<@Nullable TypeParam extends @NonNull Object>. 

5.  In you're watches list add type.getUpperBound().  Notice that the 
annotations on the bound is:
[@checkers.initialization.quals.Initialized, @checkers.nullness.quals.NonNull, 
@checkers.nullness.quals.Nullable]
Notice, the NonNull and Nullable annotations on the .

6.  If you add type.getEffectiveUpperBound() as a watch it's annotations are:  
[@checkers.initialization.quals.Initialized, @checkers.nullness.quals.Nullable]
Notice that neither of these is the declared upper bound. 

What version of the product are you using? On what operating system?
Checker Framework 1.7

Original issue reported on code.google.com by jbu...@cs.washington.edu on 6 Nov 2013 at 12:44

Attachments:

GoogleCodeExporter commented 9 years ago
Also, section 18.1.3 of the manual discusses the actual meanings of:
class MyClass<@A T extends @B Object>

http://types.cs.washington.edu/checker-framework/current/checkers-manual.html#ge
nerics

Original comment by jbu...@cs.washington.edu on 6 Nov 2013 at 12:46

GoogleCodeExporter commented 9 years ago

Original comment by Jonathan...@gmail.com on 2 Apr 2014 at 5:50

GoogleCodeExporter commented 9 years ago
This example now emits an error in the locations you would expect (see below) 
though we could probably eliminate the error messages on the actual type 
arguments since the parameter itself is nonsensical.  I will leave this open 
for now:

/Users/jburke/Downloads/AtvBoundsError.java:3: error: [bound.type.incompatible] 
incompatible bounds in type parameter
class WithAtv<@Nullable TypeParam extends @NonNull Object> {
              ^
  type: (@org.checkerframework.checker.nullness.qual.Nullable :: TypeParam)/*DECL*/ [ extends @Initialized @NonNull Object super @Initialized @Nullable Void]
  upper bound: @Initialized @NonNull Object
  lower bound: @Initialized @Nullable  null
/Users/jburke/Downloads/AtvBoundsError.java:5: error: 
[type.argument.type.incompatible] incompatible types in type argument.
        @Nullable WithAtv<@Nullable String> strWAtv = null;
                          ^
  found   : @Initialized @Nullable String
  required: @Initialized @NonNull Object
/Users/jburke/Downloads/AtvBoundsError.java:6: error: 
[type.argument.type.incompatible] incompatible types in type argument.
        @Nullable WithAtv<@NonNull Integer> intWAtv = null;
                          ^
  found   : @Initialized @NonNull Integer
  required: [extends @Initialized @NonNull Object super null

Original comment by Jonathan...@gmail.com on 8 Apr 2015 at 10:21