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

SC: Lambda within lambda that references "this" produces cast exceptions

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.0-rc-2
    • Fix Version/s: 3.0.0-rc-3
    • Component/s: None
    • Labels:
      None

      Description

      Follow up to GROOVY-9332 and GROOVY-9333. Consider the following:

      @groovy.transform.CompileStatic
      class ThisTest {
        private final ThisTest that = this
      
        void m() {
          java.util.function.Predicate<ThisTest> p1 = (ThisTest t1) -> {
            java.util.function.Predicate<ThisTest> p2 = (ThisTest t2) -> {
              assert this === t1 && this === t2
            }
            p2.test(t1)
          }
          p1.test(that)
          p1.test(this)
        }
      }
      new ThisTest().m()
      
      java.lang.ClassCastException: ThisTest$_m_lambda1 cannot be cast to ThisTest
              at ThisTest$_m_lambda1$_lambda2.doCall(TestScript4.groovy:9)
              at ThisTest$_m_lambda1.doCall(TestScript4.groovy:11)
              at ThisTest.m(TestScript4.groovy:13)
              at ThisTest$m.call(Unknown Source)
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                emilles Eric Milles
                Reporter:
                emilles Eric Milles
              • 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 - 10m
                  10m