Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4643,7 +4643,13 @@ object Types extends TypeUtils {
cachedSuper = tycon match
case tycon: HKTypeLambda => defn.AnyType
case tycon: TypeRef if tycon.symbol.isClass => tycon
case tycon: TypeProxy => tycon.superType.applyIfParameterized(args)
case tycon: TypeProxy =>
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 Expand Up @@ -4671,8 +4677,8 @@ object Types extends TypeUtils {
*/
override def underlyingMatchType(using Context): Type =
if ctx.period != validUnderlyingMatch then
validUnderlyingMatch = if tycon.isProvisional then Nowhere else ctx.period
cachedUnderlyingMatch = superType.underlyingMatchType
validUnderlyingMatch = validSuper
cachedUnderlyingMatch

override def tryNormalize(using Context): Type = tycon.stripTypeVar match {
Expand Down
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) // error
MonadFlatten.flattened(List(List(1, 2, 3), List(4, 5)))(using ListMonad) // was an error
/*
Before the changes, when checking `ListMonad <:< functors.Monad.Impl[T]`
we eventually got to the comparison `[X] =>> T[X] <:< [+X] =>> List[X]`
because the `This` type member of `ListMonad` has a covariance annotation.
This failed the variance conformance checks despite the fact that T had been instantiated to List,
since it had been substituted into the refinement (and cached) before its instantiation.
*/
}