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

Fix #10867: Normalize after applyIfParameterized in superType #13253

Merged
merged 3 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4110,7 +4110,7 @@ object Types {
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 => tycon.superType.applyIfParameterized(args).normalized
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure whether the caching is permissible here. If we normalize, are we certain that the next time around when we demand the super type of an applied type, we get the same normalization result? It does not look obvious to me.
Maybe we should do this instead.

    override def superType(using Context): Type =
      if ctx.period != validSuper then
        validSuper = if (tycon.isProvisional) Nowhere else ctx.period
        def reappliedSuper = tycon.superType.applyIfParameterized(args).normalized
        cachedSuper = tycon match
          case tycon: HKTypeLambda => defn.AnyType
          case tycon: TypeRef =>
            if tycon.symbol.isClass then tycon
            else
              if tycon.info.isInstanceof[MatchAlias] then validSuper = Nowhere
              reappliedSuper
          case tycon: TypeProxy => reappliedSuper
          case _ => defn.AnyType
      cachedSuper

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the PR to change validity of the cache for normalizing match types.

case _ => defn.AnyType
}
validSuper = if (tycon.isProvisional) Nowhere else ctx.period
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type *:[A, B] = A match
type *:[A, B] = A match // error: Recursion limit exceeded.
case (B *: x) => A
case (x *: y) => x *: (B *: y)
case _ => A *: B
49 changes: 49 additions & 0 deletions tests/pos/10867.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
object Test {
type inserts[a, as <: Tuple] <: Tuple =
as match
case EmptyTuple => (a *: EmptyTuple) *: EmptyTuple
case y *: ys => (a *: y *: ys) *: Tuple.Map[inserts[a, ys], [t <: Tuple] =>> y *: t]

type inserts2[a] =
[as <: Tuple] =>> inserts[a, as]

type A = inserts [1, EmptyTuple]
type B = inserts2[1][EmptyTuple]

summon[A =:= ((1 *: EmptyTuple) *: EmptyTuple)]
summon[B =:= ((1 *: EmptyTuple) *: EmptyTuple)]
summon[A =:= B]

type H[t <: Tuple] = Tuple.Concat[t, EmptyTuple]

summon[H[A] =:= H[B]]

summon[Tuple.Concat[A, EmptyTuple] =:= Tuple.Concat[B, EmptyTuple]]
}

object Minimized {
type Concombre[X <: Tuple, +Y <: Tuple] <: Tuple = X match {
case EmptyTuple => Y
case x1 *: xs1 => X
}

type inserts[a, as <: Tuple] <: Tuple =
as match
case EmptyTuple => a *: EmptyTuple

type inserts2[a] =
[as <: Tuple] =>> inserts[a, as]

type A = inserts [1, EmptyTuple]
type B = inserts2[1][EmptyTuple]
type C = 1 *: EmptyTuple

summon[A =:= B]
summon[A =:= C]
summon[B =:= C]

type H[t <: Tuple] = Concombre[t, EmptyTuple]

summon[H[C] =:= H[A]]
summon[H[C] =:= H[B]]
}