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

Method "with()" fails to call on the object reference in Trait

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.0.0-alpha-1, 3.0.6
    • Component/s: groovy-runtime
    • Labels:
      None

      Description

      class Bar implements FooTrait {
          def whoAmI() { "It's Bar" }
      }
      
      class Foo {
          def whoAmI() { "It's Foo" }
      }
      
      trait FooTrait {
          Foo f = new Foo()
          def hiFoo() {
              f.with {
                  whoAmI() // it's Foo or Bar?!
              }
          }
      }
      
      Bar b = new Bar()
      assert b.hiFoo() == b.f.whoAmI()
      

      I would expect the assert on last line will pass, but it failed with

      Assertion failed: 
      
      assert b.hiFoo() == b.f.whoAmI()
             | |       |  | | |
             | It's Bar|  | | It's Foo
             |         |  | Foo@72967906
             |         |  Bar@5b8dfcc1
             |         false
             Bar@5b8dfcc1
      

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              twongter Terry Wong
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: