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

Wildcards aren't captured for inner classes that use type parameters from the outer class #4996

Closed
cushon opened this issue Dec 23, 2021 · 0 comments · Fixed by #5003
Closed
Assignees

Comments

@cushon
Copy link
Contributor

cushon commented Dec 23, 2021

abstract class CaptureOuter<T> {
  abstract T get();

  abstract class Inner {
    abstract T get();
  }
}

class Client {
  Object getFrom(CaptureOuter<?> o) {
    return o.get();
  }

  Object getFrom(CaptureOuter<?>.Inner o) {
    return o.get();
  }
}
$ $HOME/checker-framework-3.21.0/checker/bin/javac -processor nullness CaptureOuter.java
CaptureOuter.java:11: error: [return] incompatible types in return.
    return o.get();
                ^
  type of expression: capture#84 extends @Initialized @Nullable Object
  method return type: @Initialized @NonNull Object
CaptureOuter.java:15: error: [return] incompatible types in return.
    return o.get();
                ^
  type of expression: @Initialized ? extends @Initialized @Nullable Object
  method return type: @Initialized @NonNull Object
2 errors

The call to CaptureOuter.get() has a type of capture#84 extends @Initialized @Nullable Object, as expected.

But the call to CaptureOuter.Inner.get() has a type of @Initialized ? extends @Initialized @Nullable Object.

Contrast this to what javac does if the return types of the getFrom methods is changed to String: In both cases, it identifies the call as having a type of CAP#1.

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