Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7719

Type incompatibility of generic placeholders not detected for method called on field

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.4.5
    • None
    • Static Type Checker
    • None

    Description

      While reading the test case for GROOVY-5839, I noticed it did not actually match the reported problem, which is about a method-level generic type shadowing a class-level generic type. However, the real problem is that the code compiles even without the shadowing of the generic type of the class by the method:

      class GoodCodeRed<T> {
          Collection<GoodCodeRed<T>> attached = []
          public <U> void attach(GoodCodeRed<U> toAttach) {
              attached.add(toAttach)
          }
      }
      def g1 = new GoodCodeRed<Integer>()
      def g2 = new GoodCodeRed<Integer>()
      g1.attach(g2)
      

      T and U are unrelated, the attached.add(toAttach) call should not compile.

      Once that is fixed, we can see if the shadowing of the type is also an issue, simply by renaming U to T.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              fpavageau Frank Pavageau
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: