Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong type signature in method chaining #16779

Open
cagritepebasili opened this issue Jan 28, 2023 · 4 comments
Open

Wrong type signature in method chaining #16779

cagritepebasili opened this issue Jan 28, 2023 · 4 comments
Assignees
Labels
itype:bug stat:needs minimization Needs a self contained minimization

Comments

@cagritepebasili
Copy link

Compiler version

Scala Version: 3.2.1

Minimized code

dependencies:

Maven dependencies:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.projectreactor</groupId>
                <artifactId>reactor-bom</artifactId>
                <version>2020.0.6</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
</dependencyManagement>

<dependency>
            <groupId>io.projectreactor.netty</groupId>
            <artifactId>reactor-netty-core</artifactId>
        </dependency>
        <dependency>
            <groupId>io.projectreactor.netty</groupId>
            <artifactId>reactor-netty-http</artifactId>
</dependency>
HttpClient.create().get().uri("").responseContent().aggregate().asString()

Output

value responseContent is not a member of reactor.netty.http.client.HttpClient#ResponseReceiver'

Expectation

This code doesn't compile due to 'value responseContent is not a member of reactor.netty.http.client.HttpClient#ResponseReceiver'. Same code compiles in Java. What am I missing ?

Interesting note that, I got error highlights for this piece of code in Intellij IDEA but it was worked in Scala 2.13.x anyway. I upgraded Scala version to 3 and this code no longer compiles.

Also i get same errors in some Spring Framework methods. Somehow in method chaining interface types get lost. This issue #16724 might be related with this.

scala-netty-reactor.zip

@cagritepebasili cagritepebasili added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 28, 2023
@anatoliykmetyuk anatoliykmetyuk added stat:needs minimization Needs a self contained minimization and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 30, 2023
@anatoliykmetyuk
Copy link
Contributor

It would be good to have a minimized version without external dependencies.

@cagritepebasili
Copy link
Author

I would love to give you a minimized version of this but I don't know what causes this bug. So I cannot produce a minimized version of this problem.

As I mentioned:

HttpClient.create().get().uri("").responseContent().aggregate().asString()

Above line is perfectly valid code. I can compile it with Scala 2.13.x. But it doesn't compile with Scala version 3.2.1.

@wjoel
Copy link
Contributor

wjoel commented Sep 1, 2024

Here's an attempt at a minimized example, fails to compile with the error message

Compiling project (Scala 3.5.0, JVM (22))
[error] ./Main.scala:3:3
[error] value responseContent is not a member of HttpClient#ResponseReceiver[?]#A
[error]   HttpClient.create().get().uri("").responseContent()
[error]   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error compiling project (Scala 3.5.0, JVM (22))
public abstract class HttpClient {
  public interface UriConfiguration<A extends UriConfiguration<?>> {
    A uri(String uri);
  }

  public interface ResponseReceiver<B extends ResponseReceiver<?>> extends UriConfiguration<B> {
    String responseContent();
  }

  public final ResponseReceiver<?> get() {
    return null;
  }

  public static HttpClient create() {
    return new HttpClient() { };
  }
}
object Main {
  HttpClient.create().get().uri("").responseContent() // error on Scala 3, works on Scala 2
}

The closest I could get with only Scala code is this, giving the same kind of error message on Scala 3 (value responseContent is not a member of HttpClientS.ResponseReceiver[?]#A), but does not compile on Scala 2.13 either (value responseContent is not a member of ?$3):

object HttpClientS {
  trait UriConfiguration[A <: UriConfiguration[?]] {
    def uri(uri: String): A
  }

  trait ResponseReceiver[B <: ResponseReceiver[?]]
    extends UriConfiguration[B] {
    def responseContent(): String
  }

  abstract class HttpClientS {
    def get(): ResponseReceiver[?] = ???
  }

  def create() = {
    new HttpClientS() { }
  }
}

@wjoel
Copy link
Contributor

wjoel commented Sep 1, 2024

Huh. Using some self-types, HttpClientS.create().get().uri("").responseContent() works with this:

object HttpClientS {
  trait UriConfiguration[A <: UriConfiguration[?]] { base: A =>
    def uri(uri: String): base.type
  }

  trait ResponseReceiver[B <: ResponseReceiver[?]]
    extends UriConfiguration[B] { base: B =>
    def responseContent(): String
  }

  abstract class HttpClientS {
    def get(): ResponseReceiver[?] = ???
  }

  def create() = {
    new HttpClientS() { }
  }
}

@SethTisue SethTisue changed the title Wrong type signatature in method chaining Wrong type signature in method chaining Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug stat:needs minimization Needs a self contained minimization
Projects
None yet
Development

No branches or pull requests

3 participants