You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/06/29 17:45:00 UTC
[jira] [Comment Edited] (GROOVY-10671) STC fails to compile AssertJ fluent API expression
[ https://issues.apache.org/jira/browse/GROOVY-10671?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17560598#comment-17560598 ]
Eric Milles edited comment on GROOVY-10671 at 6/29/22 5:44 PM:
---------------------------------------------------------------
It looks like ".as('a test')" is where the type is lost. This might be the same issue as: https://github.com/assertj/assertj-core/issues/2439
"assertThat(texts)" has a return type of:
{code}
org.assertj.core.api.AbstractCollectionAssert<?, java.util.Collection<? extends E>, E, org.assertj.core.api.ObjectAssert<E>>
->
org.assertj.core.api.AbstractCollectionAssert<SELF extends org.assertj.core.api.AbstractCollectionAssert<SELF, ACTUAL, ELEMENT, ELEMENT_ASSERT>, ACTUAL extends java.util.Collection<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends org.assertj.core.api.AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
{code}
You may be able to see that the type argument for "SELF" is just "?" (line 1). That asks a lot of the compiler to work out what "SELF" is, which is the return type of ".as('a test')"
was (Author: emilles):
It looks like ".as('a test')" is where the type is lost. This might be the same issue as: https://github.com/assertj/assertj-core/issues/2439
"assertThat(texts)" has a return type of:
{code}
org.assertj.core.api.AbstractCollectionAssert<?, java.util.Collection<? extends E>, E, org.assertj.core.api.ObjectAssert<E>>
->
org.assertj.core.api.AbstractCollectionAssert<SELF extends org.assertj.core.api.AbstractCollectionAssert<SELF, ACTUAL, ELEMENT, ELEMENT_ASSERT>, ACTUAL extends java.util.Collection<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends org.assertj.core.api.AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
{code}
You may be able to see that the type argument for "SELF" is just "?". That asks a lot of the compiler to work out what "SELF" is, which is the return type of ".as('a test')"
> STC fails to compile AssertJ fluent API expression
> --------------------------------------------------
>
> Key: GROOVY-10671
> URL: https://issues.apache.org/jira/browse/GROOVY-10671
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 4.0.3
> Reporter: Jan Hackel
> Assignee: Eric Milles
> Priority: Major
>
> Groovy 4.0.3 fails to compile this class:
>
> {code:groovy}
> @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']
> }
> }
> {code}
> It produces a message like
> {noformat}
> 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
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)