From 5298be08fc3dbc9aa509d48a8c75bb3cd03deadc Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Mon, 9 Jun 2025 11:37:55 +0200 Subject: [PATCH 1/2] Add regression test for type inference #22713 --- tests/pos/i22713.scala | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/pos/i22713.scala diff --git a/tests/pos/i22713.scala b/tests/pos/i22713.scala new file mode 100644 index 000000000000..ec3e12cebaec --- /dev/null +++ b/tests/pos/i22713.scala @@ -0,0 +1,13 @@ +import java.util.concurrent.ScheduledExecutorService +import java.util.concurrent.TimeUnit + +def Test = { + val worker: ScheduledExecutorService = ??? + object Worker extends Runnable { + def fails(): Either[Exception, Unit] = Right(worker.schedule(this, 5, TimeUnit.NANOSECONDS)) + def works(): Either[Exception, Unit] = Right { + worker.schedule(this, 5, TimeUnit.NANOSECONDS); () + } + def run(): Unit = ??? + } +} From 17f3bdead8ad1df1eef4a742191f4d61002058c0 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Tue, 8 Apr 2025 15:03:08 +0200 Subject: [PATCH 2/2] Revert "Make overload pruning based on result types less aggressive (#21744)" This reverts commit 93af7b8c7dde6b5a4c2993e00820733fb34fd52d, reversing changes made to 7d79c561d2f7cc0b831a072c0cd4f722a8246062. --- .../dotty/tools/dotc/typer/Applications.scala | 16 ++-------------- tests/pos/i21410.scala | 12 ------------ tests/pos/i21410b.scala | 10 ---------- tests/pos/i21410c.scala | 11 ----------- 4 files changed, 2 insertions(+), 47 deletions(-) delete mode 100644 tests/pos/i21410.scala delete mode 100644 tests/pos/i21410b.scala delete mode 100644 tests/pos/i21410c.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 78e2099511d7..99bfeef6b46c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -2169,27 +2169,16 @@ trait Applications extends Compatibility { def resolveOverloaded(alts: List[TermRef], pt: Type)(using Context): List[TermRef] = record("resolveOverloaded") - /** Is `alt` a method or polytype whose approximated result type after the first value parameter + /** Is `alt` a method or polytype whose result type after the first value parameter * section conforms to the expected type `resultType`? If `resultType` * is a `IgnoredProto`, pick the underlying type instead. - * - * Using an approximated result type is necessary to avoid false negatives - * due to incomplete type inference such as in tests/pos/i21410.scala and tests/pos/i21410b.scala. */ def resultConforms(altSym: Symbol, altType: Type, resultType: Type)(using Context): Boolean = resultType.revealIgnored match { case resultType: ValueType => altType.widen match { case tp: PolyType => resultConforms(altSym, instantiateWithTypeVars(tp), resultType) - case tp: MethodType => - val wildRes = wildApprox(tp.resultType) - - class ResultApprox extends AvoidWildcardsMap: - // Avoid false negatives by approximating to a lower bound - variance = -1 - - val approx = ResultApprox()(wildRes) - constrainResult(altSym, approx, resultType) + case tp: MethodType => constrainResult(altSym, tp.resultType, resultType) case _ => true } case _ => true @@ -2561,7 +2550,6 @@ trait Applications extends Compatibility { if t.exists && alt.symbol.exists then val (trimmed, skipped) = trimParamss(t.stripPoly, alt.symbol.rawParamss) val mappedSym = alt.symbol.asTerm.copy(info = t) - mappedSym.annotations = alt.symbol.annotations mappedSym.rawParamss = trimmed val (pre, totalSkipped) = mappedAltInfo(alt.symbol) match case Some((pre, prevSkipped)) => diff --git a/tests/pos/i21410.scala b/tests/pos/i21410.scala deleted file mode 100644 index c3ba3ea862bc..000000000000 --- a/tests/pos/i21410.scala +++ /dev/null @@ -1,12 +0,0 @@ -class A -object Test: - type F[X] <: Any = X match - case A => Int - - def foo[T](x: String): T = ??? - def foo[U](x: U): F[U] = ??? - - val x1 = foo(A()) - val y: Int = x1 - - val x2: Int = foo(A()) // error diff --git a/tests/pos/i21410b.scala b/tests/pos/i21410b.scala deleted file mode 100644 index a17ad59bc59e..000000000000 --- a/tests/pos/i21410b.scala +++ /dev/null @@ -1,10 +0,0 @@ -object Test: - def foo[T](x: Option[T]): T = ??? - def foo[T <: Tuple](x: T): Tuple.Map[T, List] = ??? - - val tup: (Int, String) = (1, "") - - val x = foo(tup) - val y: (List[Int], List[String]) = x - - val x2: (List[Int], List[String]) = foo(tup) // error diff --git a/tests/pos/i21410c.scala b/tests/pos/i21410c.scala deleted file mode 100644 index 21f69fec20fa..000000000000 --- a/tests/pos/i21410c.scala +++ /dev/null @@ -1,11 +0,0 @@ -class AppliedPIso[A, B]() -case class User(age: Int) - -object Test: - extension [From, To](from: From) - def focus(): AppliedPIso[From, From] = ??? - transparent inline def focus(inline lambda: (From => To)): Any = ??? - - - val u = User(1) - val ap: AppliedPIso[User, User] = u.focus(_.age) // error