Groovy
  1. Groovy
  2. GROOVY-4457

generic type declarations leaking across all files in a build

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.7.5
    • Fix Version/s: 1.8.5, 2.0-beta-2, 1.7.11
    • Component/s: Compiler
    • Labels:
      None

      Description

      Simple file, A.groovy:

      class A<String> {
      }
      
      class B {
        void foo(String s) {}
      }
      

      groovyc A.groovy
      javap -private B | grep foo

      produces:

      public void foo(java.lang.Object);
      

      The 'String' is treated as a type parameter name. The reference 'String' in the foo method is mapped to this type parameter (clearly it shouldn't be) and when producing the code, String is erased to its upper bound of Object, hence foo(Object) in the bytecode.

      Change it to this:

      class A<T> {
      }
      
      class B {
        void foo(String s) {}
      }
      

      and it produces what you expect:

       public void foo(java.lang.String);
      

      The problem is the genericParameterNames collection in the ResolveVisitor is never cleared, only augmented with new entries.

      My solution that seems to work in groovy eclipse is to clear the parameter names at the end of visiting a classnode in ResolveVisitor. So at the end of

      public void visitClass(ClassNode node) {
      

      add

      genericParameterNames.clear();
      
      1. GROOVY-4457.patch
        67 kB
        Cédric Champeau

        Activity

        Andy Clement created issue -
        Graeme Rocher made changes -
        Field Original Value New Value
        Fix Version/s 1.8-beta-3 [ 16750 ]
        Fix Version/s 1.7.6 [ 16749 ]
        Fix Version/s 1.8-beta-x [ 15750 ]
        Fix Version/s 1.7.X [ 15538 ]
        Jochen Theodorou made changes -
        Link This issue is related to GRECLIPSE-845 [ GRECLIPSE-845 ]
        Guillaume Delcroix made changes -
        Assignee Guillaume Laforge [ guillaume ]
        Guillaume Delcroix made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.7.X [ 15538 ]
        Fix Version/s 1.8-beta-x [ 15750 ]
        Roshan Dawrani made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Jochen Theodorou made changes -
        Fix Version/s 1.8-beta-3 [ 16750 ]
        Fix Version/s 1.7.6 [ 16749 ]
        Cédric Champeau made changes -
        Attachment GROOVY-4457.patch [ 58038 ]
        Guillaume Delcroix made changes -
        Assignee Guillaume Laforge [ guillaume ] Cedric Champeau [ melix ]
        Cédric Champeau made changes -
        Fix Version/s 1.7.11 [ 17244 ]
        Status Reopened [ 4 ] Resolved [ 5 ]
        Fix Version/s 2.0-beta-2 [ 18072 ]
        Fix Version/s 1.8.5 [ 18071 ]
        Resolution Fixed [ 1 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733393 ] Default workflow, editable Closed status [ 12745210 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12967796 ] Default workflow, editable Closed status [ 12975503 ]

          People

          • Assignee:
            Cédric Champeau
            Reporter:
            Andy Clement
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development