Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultTypeHierarchy.visitTypevarSubtype can ignore type arguments #3443

Closed
cpovirk opened this issue Jul 7, 2020 · 0 comments · Fixed by #3456
Closed

DefaultTypeHierarchy.visitTypevarSubtype can ignore type arguments #3443

cpovirk opened this issue Jul 7, 2020 · 0 comments · Fixed by #3456
Assignees

Comments

@cpovirk
Copy link
Contributor

cpovirk commented Jul 7, 2020

$ cat OnlyTopLevelForTypeVariable.java
import org.checkerframework.checker.nullness.qual.Nullable;

class OnlyTopLevelForTypeVariable {
  static <T extends Supplier<@Nullable String>> Supplier<String> passThrough(T t) {
    return t;
  }

  public static void main(String[] args) {
    Supplier<@Nullable String> s1 = () -> null;
    Supplier<String> s2 = passThrough(s1);
    s2.get().toString();
  }
}

interface Supplier<T> {
  T get();
}

$ $HOME/checker-framework-3.4.1/checker/bin/javac -processor org.checkerframework.checker.nullness.NullnessChecker OnlyTopLevelForTypeVariable.java && java OnlyTopLevelForTypeVariable
Exception in thread "main" java.lang.NullPointerException
        at OnlyTopLevelForTypeVariable.main(OnlyTopLevelForTypeVariable.java:11)

I would have expected an error in the implementation of passThrough, since a Supplier<@Nullable String> isn't a Supplier<String> (as the Checker Framework knows if I use Supplier<@Nullable String> directly instead of T).

I think this is a result of the code somewhere around here:

As I understand it, we end up checking isPrimarySubtype but not the arguments.

I didn't encounter this in "real" code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants