Skip to content

Commit eaa673d

Browse files
Add explanation doc
1 parent 59b0f3a commit eaa673d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -4644,7 +4644,11 @@ object Types extends TypeUtils {
46444644
case tycon: HKTypeLambda => defn.AnyType
46454645
case tycon: TypeRef if tycon.symbol.isClass => tycon
46464646
case tycon: TypeProxy =>
4647-
if validSuper != Nowhere && args.exists(_.isProvisional) then validSuper = Nowhere
4647+
if validSuper != Nowhere && args.exists(_.isProvisional) then
4648+
// applyIfParameterized may perform eta-reduction leading to different
4649+
// variance annotations depending on the instantiation of type params
4650+
// see tests/pos/typeclass-encoding3b.scala:348 for an example
4651+
validSuper = Nowhere
46484652
tycon.superType.applyIfParameterized(args)
46494653
case _ => defn.AnyType
46504654
cachedSuper

tests/pos/typeclass-encoding3b.scala

+8-1
Original file line numberDiff line numberDiff line change
@@ -345,5 +345,12 @@ object functors {
345345
}
346346

347347
MonadFlatten.flattened(List(List(1, 2, 3), List(4, 5))) // ok, synthesizes (using ListMonad)
348-
MonadFlatten.flattened(List(List(1, 2, 3), List(4, 5)))(using ListMonad)
348+
MonadFlatten.flattened(List(List(1, 2, 3), List(4, 5)))(using ListMonad) // was an error
349+
/*
350+
When checking `ListMonad <:< functors.Monad.Impl[T]`
351+
we eventually get to the comparison `[X] =>> T[X] <:< [+X] =>> List[X]`
352+
because the `This` type member of `ListMonad` has a covariance annotation.
353+
This fails the variance conformance checks despite the fact that T has been instantiated to List,
354+
since it has been substituted into the refinement (and cached) before its instantiation.
355+
*/
349356
}

0 commit comments

Comments
 (0)