From ef9d7295265cfce8f56565f997b9abd83b695525 Mon Sep 17 00:00:00 2001 From: odersky Date: Thu, 9 May 2024 15:19:50 +0200 Subject: [PATCH] Re-instantiate previous behavior also for LTS --- .../dotty/tools/dotc/typer/ProtoTypes.scala | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 7bfe00aea13e..aae795277136 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -13,6 +13,7 @@ import Decorators.* import Uniques.* import Flags.{Method, Transparent} import inlines.Inlines +import config.{Feature, SourceVersion} import config.Printers.typr import Inferencing.* import ErrorReporting.* @@ -128,11 +129,22 @@ object ProtoTypes { case _ => false - if Inlines.isInlineable(meth) && meth.is(Transparent) then - constrainResult(mt, wildApprox(pt)) - true - else - constFoldException(pt) || constrainResult(mt, pt) + constFoldException(pt) || { + if Inlines.isInlineable(meth) then + // Stricter behaviour in 3.4+: do not apply `wildApprox` to non-transparent inlines + if Feature.sourceVersion.isAtLeast(SourceVersion.`3.4`) then + if meth.is(Transparent) then + constrainResult(mt, wildApprox(pt)) + // do not constrain the result type of transparent inline methods + true + else + constrainResult(mt, pt) + else + // Best-effort to fix https://github.com/scala/scala3/issues/9685 in the 3.3.x series + // while preserving source compatibility as much as possible + constrainResult(mt, wildApprox(pt)) || meth.is(Transparent) + else constrainResult(mt, pt) + } end constrainResult end Compatibility