Skip to content

Commit dcd1099

Browse files
oderskytanishiking
authored andcommitted
Pick right type parameters in TreeUnpickler
Fixes scala#13190
1 parent d84dab5 commit dcd1099

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,12 @@ class TreeUnpickler(reader: TastyReader,
864864
override def completerTypeParams(sym: Symbol)(using Context) =
865865
rhs.tpe.typeParams
866866
}
867+
val tparamSyms = rhs match
868+
case LambdaTypeTree(tparams, body) => tparams.map(_.symbol.asType)
869+
case _ => Nil
867870
sym.info = sym.opaqueToBounds(
868871
checkNonCyclic(sym, rhs.tpe.toBounds, reportErrors = false),
869-
rhs, rhs.tpe.typeParams)
872+
rhs, tparamSyms)
870873
if sym.isOpaqueAlias then sym.typeRef.recomputeDenot() // make sure we see the new bounds from now on
871874
sym.resetFlag(Provisional)
872875
TypeDef(rhs)

tests/pos/i13190/A_1.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Opaque {
2+
opaque type FieldType[K, +V] <: V = V
3+
}

tests/pos/i13190/B_2.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Opaque.*
2+
3+
object Test {
4+
type FindField[R <: scala.Tuple, K] = R match {
5+
case FieldType[K, f] *: t => f
6+
case _ *: t => FindField[t, K]
7+
}
8+
9+
val f: FieldType["A", Int] = ???
10+
val f1: Int = f
11+
//val f2: Int = f
12+
13+
type R = FieldType["A", Int] *: FieldType["B", Double] *: FieldType["C", String] *: FieldType["D", Boolean] *: EmptyTuple
14+
summon[FindField[R, "B"] =:= Double]
15+
}

0 commit comments

Comments
 (0)