lovubuntu / checker-framework

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

Issue with qualified inference bug #339

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I found a possible type inference issue with the nullness checker. Should the 
explicit type parameter should be necessary for the invocation of checkNotNull? 
The checker reports an error without it.

(Also, annotating the parameter of 'checkNotNull' as @Nullable fixes the issue.)

=== Test.java ===
import org.checkerframework.checker.nullness.qual.*;

public class Test<T> {
  static <T> @NonNull T checkNotNull(T sample) {
    throw new RuntimeException();
  }

  void m(@Nullable T t) {
    @NonNull T r1 = Test.<@Nullable T>checkNotNull(t); // OK
    @NonNull T r2 = Test.checkNotNull(t);              // Error
  }
}
===

$ ~/jsr308/checker-framework-1.8.2/checker/bin/javac -processor 
org.checkerframework.checker.nullness.NullnessChecker -cp 
~/jsr308/checker-framework-1.8.2/checker/dist/checker-qual.jar Test.java
Test.java:10: error: [argument.type.incompatible] incompatible types in 
argument.
    @NonNull T r2 = Test.checkNotNull(t);              // Error
                                      ^
  found   : @Nullable T extends @Initialized @Nullable Object
  required: @NonNull T extends @Initialized @Nullable Object
1 error

Original issue reported on code.google.com by cus...@google.com on 25 Jun 2014 at 6:12

GoogleCodeExporter commented 9 years ago
Thanks, I agree that this should work without explicit type arguments.
I'm not sure whether it also shouldn't fail with "null" as argument.
I'm reworking type argument inference at the moment and added this test case.
cu, WMD.

Original comment by wdi...@gmail.com on 26 Jun 2014 at 4:30

GoogleCodeExporter commented 9 years ago
Thanks!

Original comment by cus...@google.com on 26 Jun 2014 at 6:17

GoogleCodeExporter commented 9 years ago

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

GoogleCodeExporter commented 9 years ago

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