From c3564dfac837b1a070ff260ac7cc7708d9f86b85 Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Mon, 28 Apr 2025 11:05:32 +0000 Subject: [PATCH] Tighten condition to preserve denotation in IntegrateMap --- compiler/src/dotty/tools/dotc/core/Types.scala | 8 ++++++-- tests/pos/23056.scala | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/pos/23056.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index ebff52b002a1..2cd66464da3c 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -3858,8 +3858,12 @@ object Types extends TypeUtils { override final def derivedSelect(tp: NamedType, pre: Type): Type = if tp.prefix eq pre then tp - else if tp.symbol.exists then NamedType(pre, tp.name, tp.denot.asSeenFrom(pre)) - else NamedType(pre, tp.name) + else + pre match + case ref: ParamRef if (ref.binder eq self) && tp.symbol.exists => + NamedType(pre, tp.name, tp.denot.asSeenFrom(pre)) + case _ => + tp.derivedSelect(pre) final def derivedLambdaType(paramNames: List[ThisName] = this.paramNames, paramInfos: List[PInfo] = this.paramInfos, diff --git a/tests/pos/23056.scala b/tests/pos/23056.scala new file mode 100644 index 000000000000..e38909e16c61 --- /dev/null +++ b/tests/pos/23056.scala @@ -0,0 +1,18 @@ +def Test = { + val ops: CompileOps[Option, Option, Any] = ??? + ops.to(List).map(_.reverse) // error +} + +trait CompileOps[F[_], G[_], O]: + def to(collector: Collector[O]): G[collector.Out] +trait Collector[-A] { + type Out +} + +object Collector: + type Aux[A, X] = Collector[A] { type Out = X } + + given [A, C[_]]: Conversion[ + scala.collection.IterableFactory[C], + Collector.Aux[A, C[A]] + ] = ???