Skip to content

Commit c0a7fc1

Browse files
committed
Handle capture checking language imports correctly for -Ytest-pickler
The pickler test did not track whether capture checking was on. This meant that files with import language.experimental.captureChecking has to be compiled additionally with the capture checking setting -language.experimental.captureChecking to pass pickler tests. This made it impossible to test mixed code bases where some files require capture checking and others don't. We now use the previous setting of `CompilationUnit#needsCaptureChecking` when unpickling.
1 parent 8b14802 commit c0a7fc1

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Pickler extends Phase {
4848

4949
// Maps that keep a record if -Ytest-pickler is set.
5050
private val beforePickling = new mutable.HashMap[ClassSymbol, String]
51-
private val pickledBytes = new mutable.HashMap[ClassSymbol, Array[Byte]]
51+
private val pickledBytes = new mutable.HashMap[ClassSymbol, (CompilationUnit, Array[Byte])]
5252

5353
/** Drop any elements of this list that are linked module classes of other elements in the list */
5454
private def dropCompanionModuleClasses(clss: List[ClassSymbol])(using Context): List[ClassSymbol] = {
@@ -137,7 +137,7 @@ class Pickler extends Phase {
137137
else
138138
val pickled = computePickled()
139139
reportPositionWarnings()
140-
if ctx.settings.YtestPickler.value then pickledBytes(cls) = pickled
140+
if ctx.settings.YtestPickler.value then pickledBytes(cls) = (unit, pickled)
141141
() => pickled
142142

143143
unit.pickled += (cls -> demandPickled)
@@ -163,21 +163,21 @@ class Pickler extends Phase {
163163
result
164164
}
165165

166-
private def testUnpickler(using Context): Unit = {
166+
private def testUnpickler(using Context): Unit =
167167
pickling.println(i"testing unpickler at run ${ctx.runId}")
168168
ctx.initialize()
169169
val unpicklers =
170-
for ((cls, bytes) <- pickledBytes) yield {
170+
for ((cls, (unit, bytes)) <- pickledBytes) yield {
171171
val unpickler = new DottyUnpickler(bytes)
172172
unpickler.enter(roots = Set.empty)
173-
cls -> unpickler
173+
cls -> (unit, unpickler)
174174
}
175175
pickling.println("************* entered toplevel ***********")
176-
for ((cls, unpickler) <- unpicklers) {
176+
val rootCtx = ctx
177+
for ((cls, (unit, unpickler)) <- unpicklers) do
178+
ctx.compilationUnit.needsCaptureChecking = unit.needsCaptureChecking
177179
val unpickled = unpickler.rootTrees
178180
testSame(i"$unpickled%\n%", beforePickling(cls), cls)
179-
}
180-
}
181181

182182
private def testSame(unpickled: String, previous: String, cls: ClassSymbol)(using Context) =
183183
import java.nio.charset.StandardCharsets.UTF_8

tests/pos/cc-backwards-compat/A.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package p
2+
class A:
3+
def map(other: Iter): Iter = other
4+
def pair[T](x: T): (T, T) = (x, x)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package p
2+
import language.experimental.captureChecking
3+
4+
class Iter:
5+
self: Iter^ =>
6+
7+
def test(it: Iter^) =
8+
val a = A()
9+
//val b = a.map(it) // does not work yet
10+
val c = a.pair(it)

0 commit comments

Comments
 (0)