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

STC fails to compile AssertJ fluent API expression

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.3
    • 4.0.4, 3.0.20
    • None
    • None

    Description

      Groovy 4.0.3 fails to compile this class:
       

      @Grab('org.assertj:assertj-core:3.22.0')
      @Grab('org.junit.jupiter:junit-jupiter-api:5.8.2')
      import groovy.transform.CompileStatic
      import org.junit.jupiter.api.Test
      
      import static org.assertj.core.api.Assertions.assertThat
      
      @CompileStatic
      class AssertJSelfTypesWithCollection {
      
        @Test
        void chainWithAs() {
          def texts = someStrings()
          assertThat(texts)
            .as('a test')
            .containsExactlyInAnyOrderElementsOf(['a', 'b'])
        }
      
        private static Collection<String> someStrings() {
          return ['a', 'b']
        }
      }
      

      It produces a message like

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /home/jh/Code/groovy-bugs/src/test/groovy/de/jhunovis/fluentapi/AssertJSelfTypesWithCollection.groovy: 14: [Static type checking] - Cannot find matching method SELF#containsExactlyInAnyOrderElementsOf(java.util.List<java.lang.String>). Please check if the declared type is correct and if the method exists.
       @ line 14, column 5.
             assertThat(texts)
             ^
      
      1 error
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              jhunovis Jan Hackel
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: