ctolkmit / checker-framework

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

Problem with ternary operator + generics #337

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The nullness checker incorrectly reports an error for the following program. 
The non-generic case works as expected (replacing uses of 'R' with Object 
allows the test to pass).

I tested with v1.8.2.

=== Test.java ===
import javax.annotation.Nullable;

abstract class Test<R> {
  abstract R getThing(String key);
  @Nullable R m(String key) {
    return (key == null) ? null : getThing(key);
  }
}
===

$ ~/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:6: error: [conditional.type.incompatible] incompatible types in 
conditional expression.
    return (key == null) ? null : getThing(key);
                           ^
  found   : null
  required: R extends @Initialized @Nullable Object

Original issue reported on code.google.com by cus...@google.com on 16 Jun 2014 at 10:35

GoogleCodeExporter commented 9 years ago
Thanks! I can reproduce the issue.

Original comment by wdi...@gmail.com on 16 Jun 2014 at 10:57

GoogleCodeExporter commented 9 years ago
This seems to have been fixed for a while and never updated.

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

GoogleCodeExporter commented 9 years ago

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