Skip to content

Commit a92574a

Browse files
committed
Fix #3606: Fix unpickling recursive types
Since recursive types register themselves, we should test the registry before building them again. Otherwise, a repeated read (for whatever reason) will install a new recursive type, but then any nested SHARED node of a reference to the binder will pick up the reference to the old type.
1 parent dd0e68e commit a92574a

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,17 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
208208

209209
def readMethodic[N <: Name, PInfo <: Type, LT <: LambdaType]
210210
(companion: LambdaTypeCompanion[N, PInfo, LT], nameMap: Name => N): LT = {
211-
val nameReader = fork
212-
nameReader.skipTree() // skip result
213-
val paramReader = nameReader.fork
214-
val paramNames = nameReader.readParamNames(end).map(nameMap)
215-
val result = companion(paramNames)(
211+
val result = typeAtAddr.getOrElse(start, {
212+
val nameReader = fork
213+
nameReader.skipTree() // skip result
214+
val paramReader = nameReader.fork
215+
val paramNames = nameReader.readParamNames(end).map(nameMap)
216+
companion(paramNames)(
216217
pt => registeringType(pt, paramReader.readParamTypes[PInfo](end)),
217218
pt => readType())
219+
})
218220
goto(end)
219-
result
221+
result.asInstanceOf[LT]
220222
}
221223

222224
val result =
@@ -308,7 +310,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
308310
case THIS =>
309311
ThisType.raw(readType().asInstanceOf[TypeRef])
310312
case RECtype =>
311-
RecType(rt => registeringType(rt, readType()))
313+
typeAtAddr.getOrElse(start, RecType(rt => registeringType(rt, readType())))
312314
case RECthis =>
313315
readTypeRef().asInstanceOf[RecType].recThis
314316
case TYPEALIAS =>

tests/pos-from-tasty/i3606.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object Test {
2+
def foo: Unit = {
3+
val a: GenericCompanion2[Bar] = null
4+
val b: GenericCompanion2[Baz] = null
5+
List(a, b)
6+
}
7+
}
8+
9+
class GenericCompanion2[+CC[X] <: Foo[X]]
10+
11+
class Foo[A]
12+
13+
class Bar[A] extends Foo[A]
14+
class Baz[A] extends Foo[A]

tests/pos-from-tasty/i3608.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class A {
2+
class Foo {
3+
inline def inlineMeth: Unit = new Bar
4+
}
5+
class Bar
6+
}
7+
8+
class B extends A {
9+
(new Foo).inlineMeth
10+
}

0 commit comments

Comments
 (0)