8000
Skip to content

Inscrutable error messages from inference failures #1721

Description

@msridhar

(From ben-manes/caffeine#2004 (comment))

16 errors read "inference failure: type variable V constrained to be both @nonnull and @nullable",
concentrated in generic inference and wildcards. These were Caffeine's fault, not NullAway's.
CompletableFuture<T extends @Nullable Object> and BiFunction<T, U, R> with all three bounded by
@Nullable Object; Caffeine's helpers declared plain type variables, which bind to non-null
Object in null-marked code, so they could not accept those types at all. Widening the bounds
cleared all 16.

The diagnostic could point at this more directly. Adding an explicit type witness produces the
message that actually explains it:

Type argument cannot be @Nullable, as method <T,U,R>identity(...)'s type variable U is not @Nullable

whereas the inferred call says only that a type variable is "constrained to be both @nonnull and
@nullable", which reads like an inference defect rather than a missing bound on the user's own
declaration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    highpriorityjspecifyRelated to support for jspecify standard (see jspecify.dev)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0