Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark AppliedType cachedSuper valid Nowhere when using provisional args #20527

Merged
merged 5 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
/*
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow the comment. How does it failing the conformance check lead it to not erroring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I'd overlooked updating the tense

since it has been substituted into the refinement (and cached) before its instantiation.
*/
}
Loading