Skip to content

Sample input: Inheriting the same type with different arguments #68

Open

Description

@cpovirk

(split off from #67. another edge case for the "It's not just type usages" bucket)

interface NumberList<T extends @Nullable Number> extends List<T> {}

interface SerializableList<T extends @Nullable Serializable> extends List<T> {}

interface IntegerList extends NumberList<@Nullable Integer>, SerializableList<@NotNull Integer> {}

IntegerList is inheriting List twice with "different arguments," @Nullable Integer and @NotNull Integer. That is, it's both a List<@Nullable Integer> and a List<@NotNull Integer>. That's no good. This should be illegal, just as it's illegal to be both a List<Integer> and a List<Double> (8.1.5):

interface ConfusedList extends List<Integer>, List<Double> {}
error: repeated interface
interface ConfusedList extends List<Integer>, List<Double> {}
                                                  ^
error: List cannot be inherited with different arguments: <java.lang.Integer> and <java.lang.Double>
interface ConfusedList extends List<Integer>, List<Double> {}
^

Activity

  1. cpovirk commented on Aug 16, 2019

    @cpovirk
    CollaboratorAuthor

    The Checker Framework currently permits this, but they consider it a bug: typetools/checker-framework#679

  2. added
    nullness
    on Oct 25, 2019
  3. cpovirk commented on Sep 24, 2020

    @cpovirk
    CollaboratorAuthor

    Over the past year, I've come to believe that it's not our job to write rules like this. Instead, we write rules for subtyping and substitution (and maybe others that I'm forgetting), and it's up to tools how to apply those. I would expect for tools to often decide to apply subtyping checks in the same cases as the JLS requires for normal subtyping. A tool that was strict about this would issue an error in this case. But actually writing such a rule isn't our goal for this project.

    Rather than close this issue outright, I'm going to retitle it to suggest that we add a sample input, as tool owners may find it useful as a case to consider.

    (And I'm doing the same thing in #67.)

  4. changed the title [-]Rules for inheriting the same type with different arguments[/-] [+]Sample input: Inheriting the same type with different arguments[/+] on Sep 24, 2020
  5. added
    tests
    on Sep 13, 2021
  6. added this to the Release-independent milestone on Mar 16, 2022
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

    nullnesstests

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions