ctolkmit / checker-framework

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

Target-typing / diamond operator doesn't work with fields #326

Closed GoogleCodeExporter closed 9 years ago

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

Run the nullness checker over the following program:

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

import java.util.Set;
import java.util.HashSet;

class Test {
  {
    Set<@Nullable String> s2 = new HashSet<>(); // OK
  }

  Set<@Nullable String> s1 = new HashSet<>(); // ERROR
}
===

$ ~/jsr308/checker-framework-1.8.0/checker/bin/javac -version -processor 
org.checkerframework.checker.nullness.NullnessChecker -cp 
~/jsr308/checker-framework-1.8.0/checker/dist/checker-qual.jar Test.java

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

I expected the compilation to succeed. Instead:

Test.java:12: error: [assignment.type.incompatible] incompatible types in 
assignment.
  Set<@Nullable String> s1 = new HashSet<>(); // ERROR
                             ^
  found   : @Initialized @NonNull HashSet<@Initialized @NonNull String>
  required: @Initialized @NonNull Set<@Initialized @Nullable String>
1 error

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

javac 1.8.0-jsr308-1.8.0

Original issue reported on code.google.com by cus...@google.com on 1 May 2014 at 9:40

GoogleCodeExporter commented 9 years ago
Thanks for the bug report!
We were not setting the right assignment context for field initializers and 
sometimes weren't promoting them correctly.
This push:
https://code.google.com/p/checker-framework/source/detail?r=6ed15697c5cdd92b20b5
6a050a3eb1ffd4c39447
fixed the test case for me.

Please do let us know whether this solves the issue for you.
cu, WMD.

Original comment by wdi...@gmail.com on 11 May 2014 at 6:22

GoogleCodeExporter commented 9 years ago

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