From 22f9265008b0b530e052aebf19ec324169984348 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 21 Nov 2023 16:16:53 +0100 Subject: [PATCH] Revert part of 171773d9d8067dc54028c54c0cc8257c9c06a1a8 Fixes #19006 --- .../dotty/tools/dotc/typer/Applications.scala | 5 +++- tests/pos/i19006a.scala | 11 ++++++++ tests/pos/i19006b.scala | 27 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i19006a.scala create mode 100644 tests/pos/i19006b.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 49c8910712c7..62cef94330c1 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -2003,7 +2003,10 @@ trait Applications extends Compatibility { // the arity of that function, otherise -1. def paramCount(ref: TermRef) = val formals = ref.widen.firstParamTypes - if formals.length > idx then defn.functionArity(formals(idx)) + if formals.length > idx then + formals(idx).dealias match + case defn.FunctionNOf(args, _, _) => args.length + case _ => -1 else -1 val numArgs = args.length diff --git a/tests/pos/i19006a.scala b/tests/pos/i19006a.scala new file mode 100644 index 000000000000..d38100997987 --- /dev/null +++ b/tests/pos/i19006a.scala @@ -0,0 +1,11 @@ +import java.util.Map.Entry; +import java.util.function.BiConsumer; +import java.lang.Iterable + +trait HttpHeaders extends Iterable[Entry[String, String]] { + def forEach(action: BiConsumer[String, String]): Unit = ??? +} + +@main def Test = + val headers: HttpHeaders = ??? + headers.forEach((a, b) => ???) diff --git a/tests/pos/i19006b.scala b/tests/pos/i19006b.scala new file mode 100644 index 000000000000..fbec70423ae9 --- /dev/null +++ b/tests/pos/i19006b.scala @@ -0,0 +1,27 @@ +import java.util.function.Function + +trait HttpClient +trait HttpRequest +trait HttpResponse +trait ClientRequestContext + +trait DecoratingHttpClientFunction { + def execute(delegate: HttpClient, ctx: ClientRequestContext, req: HttpRequest): HttpResponse +} + +class AbstractClientOptionsBuilder: + def decorator(fn: Function[? <: HttpClient, ? <: HttpClient]): AbstractClientOptionsBuilder = ??? + def decorator(fn: DecoratingHttpClientFunction): AbstractClientOptionsBuilder = ??? + +class WebClientBuilder extends AbstractClientOptionsBuilder: + override def decorator(fn: Function[? <: HttpClient, ? <: HttpClient]): WebClientBuilder = ??? + override def decorator(fn: DecoratingHttpClientFunction): WebClientBuilder = ??? + +class ArmeriaClientBuilder[F[_]]: + type DecoratingFunction = (HttpClient, ClientRequestContext, HttpRequest) => HttpResponse + def clientBuilder: WebClientBuilder = ??? + + def withDecorator(decorator: DecoratingFunction): ArmeriaClientBuilder[F] = { + clientBuilder.decorator(decorator(_, _, _)) + this + }