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

this reference in trait fails to resolve properly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.0.18, 4.0.13
    • None
    • None

    Description

      Consider the following:

      trait Foo {
        void bar() {
          print this
        }
      }
      "xxx".withTraits(Foo).bar() // prints String1_groovyProxy@328cf0e1
      
      class Foo {
        String toString() {
          "foo"
        }
      }
      trait Bar {
        String getBaz() {
          this.toString()
        }
      }
      print(new Foo().withTraits(Bar).baz) // prints Foo2_groovyProxy@14b030a0
      

      In the first example, I need to call a String method like "this.toLowerCase()" instead of "this" for it to work. I tried "this.toStirng()" but that fails as well, as illustrated in the second example.

      Attachments

        Activity

          People

            Unassigned Unassigned
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: