Skip to content

Generic mismatch message omits the wildcard-bound note when the bound is a subclass of an inner-class type #2224

Backlog

Description

@vlsi

When a wildcard's implicit bound is a top-level class that extends an inner-class type, and the mismatch lies in the enclosing type of that inner class, the message names the mismatch but gives no note: line explaining where the nullable type argument comes from.

static class Enclosing<X extends @Nullable Object> {
  class Nested<Y> {}
}
static class TopNested extends Enclosing<@Nullable String>.Nested<String> {
  TopNested(Enclosing<@Nullable String> e) { e.super(); }
}
static class Holder<T extends Enclosing<@Nullable String>.Nested<String>> {}
static class TopSub<U extends TopNested> extends Holder<U> {}

void f(TopSub<?> s) {
  Holder<? extends Enclosing<String>.Nested<String>> h = s;
}

With #1828 applied, NullAway reports:

incompatible nullability in type argument for T of Holder -> upper bound of wildcard -> enclosing type -> type argument for X of Enclosing: source has @Nullable String where target requires String
    source: TopSub<?>
                   ^
    target: Holder<? extends Enclosing<String>.Nested<String>>
                                       ^^^^^^

Expected: a note: line like the one printed when the bound is a subclass and the mismatch is in a type argument (NoteTests.aHolderNoteIsPrintedOnlyWhereItsBoundHasTheNullnessTheCheckCompared, key BOUND_IS_A_SUBCLASS_OF_THE_COMPARED_CLASS), naming the bound TopNested of U in TopSub. Viewed as Nested, that bound holds @Nullable String at X, which is the nullness the first line reports.

The test key NO_NOTE_BELOW_AN_ENCLOSING_TYPE_OF_A_SUBCLASS_BOUND in the same test pins the current output.

Analysis, from reading the source (the report stands without it): NullabilityMismatchMessage.hasNullnessAt views a node as the step's class only for a type-argument step (typeArgumentAt calls asSuper). For an enclosing-type step it takes the enclosing type of TopNested itself, which is noType, so the note's agreement check fails. A TypePath.Step for an enclosing type carries no class to view the node as.

Found in the final review of the round-4 fixes for #1828.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions