Skip to content

Commit

Permalink
Add explanation doc
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneFlesselle committed Jun 6, 2024
1 parent 59b0f3a commit eaa673d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4644,7 +4644,11 @@ object Types extends TypeUtils {
case tycon: HKTypeLambda => defn.AnyType
case tycon: TypeRef if tycon.symbol.isClass => tycon
case tycon: TypeProxy =>
if validSuper != Nowhere && args.exists(_.isProvisional) then validSuper = Nowhere
if validSuper != Nowhere && args.exists(_.isProvisional) then
// applyIfParameterized may perform eta-reduction leading to different
// variance annotations depending on the instantiation of type params
// see tests/pos/typeclass-encoding3b.scala:348 for an example
validSuper = Nowhere
tycon.superType.applyIfParameterized(args)
case _ => defn.AnyType
cachedSuper
Expand Down
9 changes: 8 additions & 1 deletion tests/pos/typeclass-encoding3b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,12 @@ object functors {
}

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

0 comments on commit eaa673d

Please sign in to comment.