biddyweb / checker-framework

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

Unexpected 'incompatible types in type argument' with the nullness checker #376

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

$ cat Test.java
class Test {
  interface I<T> {}
  <Q extends Enum<Q> & I<?>> void m(Class<Q> clazz, String name) {
    I<?> i = Enum.valueOf(clazz, name);
  }
}

$ javac -version -processor 
org.checkerframework.checker.nullness.NullnessChecker Test.java
javac 1.8.0-jsr308-1.8.7
Test.java:4: error: [type.argument.type.incompatible] incompatible types in 
type argument.
    I<?> i = Enum.valueOf(clazz, name);
                         ^
  found   : Q extends Enum<Q> & I<?>
  required: @Initialized @NonNull Enum<Q extends Enum<Q> & I<?>>
1 error

What is the expected output? What do you see instead?

javac correctly infers the type, and I expected the checker-framework to do the 
same. Instead, the inference fails.

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

v1.8.7

Original issue reported on code.google.com by cus...@google.com on 11 Nov 2014 at 5:52

GoogleCodeExporter commented 9 years ago
I have reproduced this issue and have committed the test case 
checker/tests/nullness/Issue376.java.

The type parameter Q extends Enum<Q> & I<?> is inferred by method type variable 
inference for the Enum.valueOf method call.  The annotations @Initialized 
@NonNull are added to the upper bound of the type parameter. However, since the 
upper bound is an intersection type, these annotations are later ignored by 
TypeHierarchy.isSubtype.

Original comment by mcarthur...@gmail.com on 19 Nov 2014 at 9:41

GoogleCodeExporter commented 9 years ago

Original comment by mcart...@cs.washington.edu on 19 Nov 2014 at 11:13

GoogleCodeExporter commented 9 years ago
The current mainline repository typechecks this correctly and it will be 
included in the next release.  It will be marked as fixed when this happens.

Original comment by Jonathan...@gmail.com on 8 Apr 2015 at 9:15

GoogleCodeExporter commented 9 years ago

Original comment by jtha...@cs.washington.edu on 18 Apr 2015 at 6:42