From f66011b0f07e51ba1f1b7266f2cd7eb440c59d0d Mon Sep 17 00:00:00 2001 From: odersky Date: Sat, 28 Oct 2023 18:50:18 +0200 Subject: [PATCH 1/3] Fix error detected in review of #18699 --- .../src/dotty/tools/dotc/cc/CheckCaptures.scala | 16 ++++++++++------ tests/pos/i18699.scala | 7 +++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 tests/pos/i18699.scala diff --git a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala index c52e1aa6714e..fab0689b4df2 100644 --- a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala +++ b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala @@ -826,12 +826,16 @@ class CheckCaptures extends Recheck, SymTransformer: */ def adaptUniversal(actual: Type, expected: Type, tree: Tree)(using Context): Type = if expected.captureSet.disallowsUniversal && actual.captureSet.isUniversal then - val localRoot = impliedRoot(tree) - CapturingType( - actual.stripCapturing, - localRoot.termRef.singletonCaptureSet, - actual.isBoxedCapturing) - .showing(i"adapt universal $actual vs $expected = $result", capt) + if actual.isInstanceOf[SingletonType] then + // capture set is only exposed when widening + adaptUniversal(actual.widen, expected, tree) + else + val localRoot = impliedRoot(tree) + CapturingType( + actual.stripCapturing, + localRoot.termRef.singletonCaptureSet, + actual.isBoxedCapturing) + .showing(i"adapt universal $actual vs $expected = $result", capt) else actual private inline val debugSuccesses = false diff --git a/tests/pos/i18699.scala b/tests/pos/i18699.scala new file mode 100644 index 000000000000..61b21b0d3ad4 --- /dev/null +++ b/tests/pos/i18699.scala @@ -0,0 +1,7 @@ +import language.experimental.captureChecking +trait Cap: + def use: Int = 42 + +def test2(cs: List[Cap^]): Unit = + val t0: Cap^{cap[test2]} = cs.head // error + var t1: Cap^{cap[test2]} = cs.head // error \ No newline at end of file From 78c2220bc2c57655cf82751967188b8c2df7d91c Mon Sep 17 00:00:00 2001 From: odersky Date: Sun, 29 Oct 2023 16:02:57 +0100 Subject: [PATCH 2/3] Move test to avoid pickling issues --- tests/pos-custom-args/captures/i18699.scala | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/pos-custom-args/captures/i18699.scala diff --git a/tests/pos-custom-args/captures/i18699.scala b/tests/pos-custom-args/captures/i18699.scala new file mode 100644 index 000000000000..61b21b0d3ad4 --- /dev/null +++ b/tests/pos-custom-args/captures/i18699.scala @@ -0,0 +1,7 @@ +import language.experimental.captureChecking +trait Cap: + def use: Int = 42 + +def test2(cs: List[Cap^]): Unit = + val t0: Cap^{cap[test2]} = cs.head // error + var t1: Cap^{cap[test2]} = cs.head // error \ No newline at end of file From 041f9ceaf4edf02dbf197d6e636eeed2f09a6693 Mon Sep 17 00:00:00 2001 From: odersky Date: Sun, 29 Oct 2023 17:55:09 +0100 Subject: [PATCH 3/3] Make printing of capture sets work also when testing Pickler --- .../src/dotty/tools/dotc/printing/RefinedPrinter.scala | 4 +++- tests/pos-custom-args/captures/i18699.scala | 7 ------- 2 files changed, 3 insertions(+), 8 deletions(-) delete mode 100644 tests/pos-custom-args/captures/i18699.scala diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 4f63bfb38691..bc8e2e9bc88e 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -640,7 +640,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { try changePrec(GlobalPrec)(toText(arg) ~ "^" ~ toTextCaptureSet(captureSet)) catch case ex: IllegalCaptureRef => toTextAnnot if annot.symbol.maybeOwner == defn.RetainsAnnot - && Feature.ccEnabled && Config.printCaptureSetsAsPrefix && !printDebug + && Feature.ccEnabled + && Config.printCaptureSetsAsPrefix && !printDebug + && Phases.checkCapturesPhase.exists // might be missing on -Ytest-pickler then toTextRetainsAnnot else toTextAnnot case EmptyTree => diff --git a/tests/pos-custom-args/captures/i18699.scala b/tests/pos-custom-args/captures/i18699.scala deleted file mode 100644 index 61b21b0d3ad4..000000000000 --- a/tests/pos-custom-args/captures/i18699.scala +++ /dev/null @@ -1,7 +0,0 @@ -import language.experimental.captureChecking -trait Cap: - def use: Int = 42 - -def test2(cs: List[Cap^]): Unit = - val t0: Cap^{cap[test2]} = cs.head // error - var t1: Cap^{cap[test2]} = cs.head // error \ No newline at end of file