biddyweb / checker-framework

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

Incorrect type inference when @Nullable param is null #319

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The nullness checker correctly infers the type T in #newFoo when the param is 
not null, as shown by #pass, however it fails when the param is null, as shown 
by #fail. Manually specifying the type shows that there is a valid type that 
could be inferred, as in #workaround.

class GenericInference {
  static class Foo<T> {
    Foo(@Nullable T t) {}
  }

  static <T> Foo<T> newFoo(@Nullable T t) {
    return new Foo<T>(t);
  }

  static void pass() {
    Foo<Boolean> f = newFoo(Boolean.FALSE);
  }

  static void fail() {
    // error: [assignment.type.incompatible] incompatible types in assignment.
    Foo<Boolean> f = newFoo(null);
    //                     ^
    // found   : @Initialized @NonNull Foo<@FBCBottom @Nullable Boolean>
    // required: @UnknownInitialization @Nullable Foo<@Initialized @NonNull Boolean>
  }

  static void workaround() {
    Foo<Boolean> f = GenericInference.<Boolean>newFoo(null);
  }
}

Original issue reported on code.google.com by hcame...@google.com on 16 Apr 2014 at 5:03

GoogleCodeExporter commented 9 years ago
Thanks for the bug report and sorry for the delay.
I fixed this: 
https://code.google.com/p/checker-framework/source/detail?r=2f5c11110ddb0ba10c03
ddda3aa641cff9d0720b
Please do let us know if you run into any other issues.

Original comment by wdi...@gmail.com on 27 May 2014 at 4:02

GoogleCodeExporter commented 9 years ago

Original comment by jtha...@cs.washington.edu on 3 Jun 2014 at 12:48

GoogleCodeExporter commented 9 years ago
Great, thanks!

Original comment by hcame...@google.com on 3 Jun 2014 at 12:23