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

Field initialized in a trait using tap doesn't work correctly

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.5.9, 3.0.0-rc-3
    • Fix Version/s: 4.0.0-alpha-1, 3.0.6
    • Component/s: None
    • Labels:
      None

      Description

      The following code

      class Foo {
          int bar
      }
      
      trait TestTrait {
          def foo = new Foo().tap{
              bar = 1
          }
      }
      
      class SomeClass implements TestTrait {
      
      }
      
      new SomeClass()
      

      fails with the following error:

      Caught: groovy.lang.MissingPropertyException: No such property: bar for class: SomeClass
      Possible solutions: foo
      groovy.lang.MissingPropertyException: No such property: bar for class: SomeClass
      Possible solutions: foo
      	at TestTrait$Trait$Helper$__init__closure1.doCall(scratch.groovy:8)
      	at TestTrait$Trait$Helper.$init$(scratch.groovy:7)
      	at SomeClass.<init>(scratch.groovy)
      	at scratch.run(scratch.groovy:16)
      

      if using the following code in the tap makes it work correctly:

      
      trait TestTrait {
          def foo = new Foo().tap{
              it.bar = 1
          }
      }
      

      Also when used in a class directly, it works also correctly:

      
      class SomeClass {
          def foo = new Foo().tap{
              bar = 1
          }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              kiefermat Matthias Kiefer
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 20m
                20m