Groovy
  1. Groovy
  2. GROOVY-4356

Static members should not be able to access generic types

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.8-beta-1
    • Fix Version/s: None
    • Component/s: class generator
    • Labels:
      None

      Description

      The following code compiles, but it shouldn't because T is a non-static generic type, and difference instances of Outer will have different concrete representations of T. Hence it makes no sense that static inner classes should be able to use such generic type variables.

      class Outer<T> {
          T ofoo
          static class Inner {
              T ifoo
          }
      }
      

      Similarly, all the cases below should not compile as well:

      class Test1<T> {
          static T f1
      }
      
      class Test2<T> {
          static foo(T param1) {}
      }
      
      class Test3<T> {
          static foo() {
              T localVar1
          }
      }
      

        Activity

        Roshan Dawrani created issue -
        Roshan Dawrani made changes -
        Field Original Value New Value
        Description The following code compiles, but it shouldn't because T is a non-static generic type, and difference instances of Outer will have different concrete representations of T. Hence it makes no sense that static inner classes should be able to use such generic type variables.
        {code}
        class Outer<T> {
            T ofoo
            static class Inner {
                T ifoo
            }
        }
        {code}
        The following code compiles, but it shouldn't because T is a non-static generic type, and difference instances of Outer will have different concrete representations of T. Hence it makes no sense that static inner classes should be able to use such generic type variables.
        {code}
        class Outer<T> {
            T ofoo
            static class Inner {
                T ifoo
            }
        }
        {code}

        Similarly, all the cases below should not compile as well:
        {code}
        class Test1<T> {
            static T f1
        }

        class Test2<T> {
            static foo(T param1) {}
        }

        class Test3<T> {
            static foo() {
                T localVar1
            }
        }
        {code}
        Summary Static inner classes should not be able to access generic types Static members should not be able to access generic types
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733297 ] Default workflow, editable Closed status [ 12745116 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12970905 ] Default workflow, editable Closed status [ 12978684 ]
        Jochen Theodorou made changes -
        Assignee Jochen Theodorou [ blackdrag ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Roshan Dawrani
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development