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

Performance of extended checks for wildcards #1077

Open
wmdietl opened this issue Jan 29, 2025 · 0 comments
Open

Performance of extended checks for wildcards #1077

wmdietl opened this issue Jan 29, 2025 · 0 comments

Comments

@wmdietl
Copy link
Member

wmdietl commented Jan 29, 2025

Take this code:

import java.util.List;

class Code<T extends List<Number>> {
  void foo(Code<? extends List<String>> p) {}
}

we get an error from normal javac:

Code.java:4: error: type argument ? extends List<String> is not within bounds of type-variable T
  void foo(Code<? extends List<String>> p) {}
                ^
  where T is a type-variable:
    T extends List<Number> declared in class Code
1 error

However, this code is okay for javac:

import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;

class Code<T extends List<@Nullable Number>> {
  void foo(Code<? extends List<Number>> p) {}
}

But the Nullness Checker complains with:

Code.java:5: error: [type.argument.type.incompatible] incompatible type argument for type parameter T of Code.
  void foo(Code<? extends List<Number>> p) {}
                ^
  found   : @NonNull List<@NonNull Number>
  required: @NonNull List<@Nullable Number>
1 error

This is a valuable error, but it might be costly to implement.
Allowing this parameter type should not affect soundness, as no call of the method can provide an argument that has that type.

First, evaluate whether these checks have a significant impact on compilation times.
If so, add a new option to enable these extended checks if desired.

This issue only arises for wildcards and type parameters with generic types. For non-generic types, the capture of the wildcard will always be within the expected bound, as there always is a GLB.

// Check that the extends bound of the captured type variable is a subtype of the

// For most captured type variables, this will trivially hold, as capturing

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

No branches or pull requests

1 participant