[ https://issues.apache.org/jira/browse/GROOVY-10055?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17534307#comment-17534307 ]
Jan Hackel commented on GROOVY-10055: ------------------------------------- This is still not fixed up to Groovy 4.0.2! {code:groovy} package de.jhunovis.fluentapi @Grab('org.springframework.boot:spring-boot-starter-webflux:2.6.7') import groovy.transform.CompileStatic import org.junit.jupiter.api.Test import org.springframework.core.ParameterizedTypeReference import org.springframework.http.MediaType import org.springframework.web.reactive.function.client.WebClient import java.time.Duration @CompileStatic class WebFluxFluentApiBugTest { private static final ParameterizedTypeReference<List<BigDecimal>> TYPE_TAG = new ParameterizedTypeReference<List<BigDecimal>>() {} private static final Duration MAX_DURATION = Duration.ofSeconds(8) private final WebClient webClient List<BigDecimal> flux() { def response = webClient.get() .uri('/something?id={id}', 'id') .accept(MediaType.APPLICATION_JSON) .retrieve() .toEntity(TYPE_TAG) .block(MAX_DURATION) return response.getBody() ?: [] } @Test void webflux() { flux() } } {code} It produces: {noformat} > groovy src/test/groovy/de/jhunovis/fluentapi/WebFluxFluentApiBugTest.groovy org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: /home/jh/Code/groovy-bugs/src/test/groovy/de/jhunovis/fluentapi/WebFluxFluentApiBugTest.groovy: 27: [Static type checking] - Cannot find matching method S#retrieve(). Please check if the declared type is correct and if the method exists. @ line 27, column 16. .retrieve() {noformat} Please re-open and fix this. > STC does not support self bounded types > --------------------------------------- > > Key: GROOVY-10055 > URL: https://issues.apache.org/jira/browse/GROOVY-10055 > Project: Groovy > Issue Type: Bug > Components: Static compilation, Static Type Checker > Affects Versions: 3.0.8 > Reporter: Damir Murat > Assignee: Eric Milles > Priority: Major > Fix For: 4.0.0-beta-2 > > > Some popular libraries use self bounded types for creating builder > hierarchies. For example, > PostgreSQLContainer (from Tescontainers library) is declared as > {code:java} > public class PostgreSQLContainer<SELF extends PostgreSQLContainer<SELF>> > extends JdbcDatabaseContainer<SELF> > {code} > where JdbcDatabaseContainer is declared as > {code:java} > public abstract class JdbcDatabaseContainer<SELF extends > JdbcDatabaseContainer<SELF>> extends GenericContainer<SELF> implements > LinkableContainer > {code} > and so on. > In the following example (tested with Groovy Console), I'm trying to create > and modify such an object with its corresponding fluent API: > {code:java} > import org.testcontainers.containers.PostgreSQLContainer > import groovy.transform.CompileStatic > @Grab("org.testcontainers:testcontainers:1.15.3") > @Grab("org.testcontainers:postgresql:1.15.3") > @CompileStatic > class TestcontainersTester { > static void testSome() { > PostgreSQLContainer postgresqlServer = new PostgreSQLContainer<>() > .withExposedPorts(5432) > .withEnv(["TZ": "Europe/Paris"]) > .withDatabaseName("my_database") > .withUsername("user") > .withPassword("pass") > // Working alternative 1 > // PostgreSQLContainer postgresqlServer = new > PostgreSQLContainer<PostgreSQLContainer<PostgreSQLContainer<PostgreSQLContainer<PostgreSQLContainer>>>>() > // .withExposedPorts(5432) > // .withEnv(["TZ": "Europe/Paris"]) > // .withDatabaseName("my_database") > // .withUsername("user") > // .withPassword("pass") > // Working alternative 2 > // PostgreSQLContainer postgresqlServer = new PostgreSQLContainer<>() > // postgresqlServer.withExposedPorts(5432) > // postgresqlServer.withEnv(["TZ": "Europe/Paris"]) > // postgresqlServer.withDatabaseName("my_database") > // postgresqlServer.withUsername("user") > // postgresqlServer.withPassword("pass") > println postgresqlServer > } > } > TestcontainersTester.testSome(); > {code} > Unfortunately, STC complains with several errors: > {code:java} > 4 compilation errors: > [Static type checking] - Cannot call SELF#withEnv(java.util.Map > <java.lang.String, java.lang.String>) with arguments [java.util.LinkedHashMap > <java.lang.String, java.lang.String>] > at line: 11, column: 17 > [Static type checking] - Cannot find matching method > java.lang.Object#withDatabaseName(java.lang.String). Please check if the > declared type is correct and if the method exists. > at line: 12, column: 26 > [Static type checking] - Cannot find matching method > java.lang.Object#withUsername(java.lang.String). Please check if the declared > type is correct and if the method exists. > at line: 13, column: 22 > [Static type checking] - Cannot find matching method > java.lang.Object#withPassword(java.lang.String). Please check if the declared > type is correct and if the method exists. > at line: 9, column: 44 > {code} > There are two working alternatives in the example. "Alternative 1" is not > really practical, but maybe it can help with solving the issue. "Alternative > 2" is an actual practical workaround that can be further improved by using > the "with" method. > Tnx -- This message was sent by Atlassian Jira (v8.20.7#820007)