-
Notifications
You must be signed in to change notification settings - Fork 331
JSpecify: inference for calls to generic methods not working for lambda arguments #1294
Copy link
Copy link
Closed
Labels
jspecifyRelated to support for jspecify standard (see jspecify.dev)Related to support for jspecify standard (see jspecify.dev)
Description
Follow-up to #1075
@NullMarked
class Foo {
public interface Callback<T extends @Nullable Object> {
void onResult(T thing);
}
public static <T extends @Nullable Object> Callback<T> wrap(Callback<T> thing) {
return thing;
}
public static void test() {
Callback<@Nullable String> ret1 = wrap((@Nullable String s) -> {});
Callback<@Nullable String> ret2 = wrap(s -> {});
}
}Yields:
Foo.java:18: warning: [NullAway] incompatible types: Callback<String> cannot be converted to Callback<@Nullable String>
Callback<@Nullable String> ret1 = wrap((@Nullable String s) -> {});
^
(see http://t.uber.com/nullaway )
Foo.java:20: warning: [NullAway] incompatible types: Callback<String> cannot be converted to Callback<@Nullable String>
Callback<@Nullable String> ret2 = wrap(s -> {});
^
(see http://t.uber.com/nullaway )
Guessing ret2 is harder to make work than ret1, but it'd be great if ret1 could be made to work.
As a work-around, assigning to a local variable works:
Callback<@Nullable String> tmp = s -> {};
Callback<@Nullable String> ret1 = wrap(tmp);Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
jspecifyRelated to support for jspecify standard (see jspecify.dev)Related to support for jspecify standard (see jspecify.dev)