Skip to content

Commit f6ae62f

Browse files
authored
Tighten condition to preserve denotation in IntegrateMap (#23060)
Should fix #23056. I haven't been able to understand exactly what is going on there yet, but the problem seems to arise in a situation where the denotation should be reloaded during `integrate` and is not. This PR makes sure that we keep the previous denotation for `NamedType` _only_ if its prefix is a `ParamRef` bound to the `LambdaType` we are integrating over.
2 parents fb6cc9b + c3564df commit f6ae62f

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

+6-2
Original file line numberDiff line numberDiff line change
@@ -3858,8 +3858,12 @@ object Types extends TypeUtils {
38583858

38593859
override final def derivedSelect(tp: NamedType, pre: Type): Type =
38603860
if tp.prefix eq pre then tp
3861-
else if tp.symbol.exists then NamedType(pre, tp.name, tp.denot.asSeenFrom(pre))
3862-
else NamedType(pre, tp.name)
3861+
else
3862+
pre match
3863+
case ref: ParamRef if (ref.binder eq self) && tp.symbol.exists =>
3864+
NamedType(pre, tp.name, tp.denot.asSeenFrom(pre))
3865+
case _ =>
3866+
tp.derivedSelect(pre)
38633867

38643868
final def derivedLambdaType(paramNames: List[ThisName] = this.paramNames,
38653869
paramInfos: List[PInfo] = this.paramInfos,

tests/pos/23056.scala

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def Test = {
2+
val ops: CompileOps[Option, Option, Any] = ???
3+
ops.to(List).map(_.reverse) // error
4+
}
5+
6+
trait CompileOps[F[_], G[_], O]:
7+
def to(collector: Collector[O]): G[collector.Out]
8+
trait Collector[-A] {
9+
type Out
10+
}
11+
12+
object Collector:
13+
type Aux[A, X] = Collector[A] { type Out = X }
14+
15+
given [A, C[_]]: Conversion[
16+
scala.collection.IterableFactory[C],
17+
Collector.Aux[A, C[A]]
18+
] = ???

0 commit comments

Comments
 (0)