Skip to content

Fix unpickling of match type aliases #11340

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

Merged
merged 1 commit into from
Feb 10, 2021
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
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -858,10 +858,7 @@ class TreeUnpickler(reader: TastyReader,
rhs.tpe.typeParams
}
sym.info = sym.opaqueToBounds(
rhs.tpe match {
case _: TypeBounds | _: ClassInfo => checkNonCyclic(sym, rhs.tpe, reportErrors = false)
case _ => rhs.tpe.toBounds
},
checkNonCyclic(sym, rhs.tpe.toBounds, reportErrors = false),
rhs, rhs.tpe.typeParams)
if sym.isOpaqueAlias then sym.typeRef.recomputeDenot() // make sure we see the new bounds from now on
sym.resetFlag(Provisional)
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ trait TypeAssigner {
def assignType(tree: untpd.TypeBoundsTree, lo: Tree, hi: Tree, alias: Tree)(using Context): TypeBoundsTree =
tree.withType(
if !alias.isEmpty then alias.tpe
else if lo eq hi then TypeAlias(lo.tpe)
else if lo eq hi then
if lo.tpe.isMatch then MatchAlias(lo.tpe)
else TypeAlias(lo.tpe)
else TypeBounds(lo.tpe, hi.tpe))

def assignType(tree: untpd.Bind, sym: Symbol)(using Context): Bind =
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,9 @@ class Typer extends Namer
*/
val arg1 = pt match {
case AppliedType(a, typ :: Nil) if ctx.isJava && a.isRef(defn.ArrayClass) =>
tryAlternatively { typed(tree.arg, pt) } {
tryAlternatively { typed(tree.arg, pt) } {
val elemTp = untpd.TypedSplice(TypeTree(typ))
typed(untpd.JavaSeqLiteral(tree.arg :: Nil, elemTp), pt)
typed(untpd.JavaSeqLiteral(tree.arg :: Nil, elemTp), pt)
}
case _ => typed(tree.arg, pt)
}
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ i7872.scala
6687.scala
i11236.scala
i11247.scala
i11250

# Opaque type
i5720.scala
Expand Down
29 changes: 29 additions & 0 deletions tests/pos/i11250/1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package shapeless3.data

import scala.compiletime._

trait Monoidal {
type to[_] <: Tuple
type length[m] = Monoidal.length[to[m]]
}

object Monoidal {
import Tuple._

type length[m <: Tuple] = Size[m]
}

trait UnboundedMonoidal[T0[_, _], U0] extends Monoidal {
type to[t] <: Tuple = t match {
case T0[hd, tl] => hd *: to[tl]
case U0 => EmptyTuple
}
}

object pairs extends UnboundedMonoidal[Tuple2, Unit]

object MonoidalTest { // Compiles fine here
type p = (Int, (String, (Boolean, Unit)))
summon[pairs.length[p] =:= 3]
}

7 changes: 7 additions & 0 deletions tests/pos/i11250/2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package shapeless3.data

object MonoidalTest2 { // But not here
type p = (Int, (String, (Boolean, Unit)))
summon[pairs.length[p] =:= 3]
}