-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Wrong type signature in method chaining #16779
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
Comments
It would be good to have a minimized version without external dependencies. |
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:
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. |
Here's an attempt at a minimized example, fails to compile with the error message
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 ( 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() { }
}
} |
Huh. Using some self-types, 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() { }
}
} |
Compiler version
Scala Version: 3.2.1
Minimized code
dependencies:
Maven dependencies:
Output
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
The text was updated successfully, but these errors were encountered: