Skip to content

Commit 22aaabb

Browse files
authored
Fix error detected in review of #18699 (#18781)
2 parents 176622c + 041f9ce commit 22aaabb

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

+10-6
Original file line numberDiff line numberDiff line change
@@ -826,12 +826,16 @@ class CheckCaptures extends Recheck, SymTransformer:
826826
*/
827827
def adaptUniversal(actual: Type, expected: Type, tree: Tree)(using Context): Type =
828828
if expected.captureSet.disallowsUniversal && actual.captureSet.isUniversal then
829-
val localRoot = impliedRoot(tree)
830-
CapturingType(
831-
actual.stripCapturing,
832-
localRoot.termRef.singletonCaptureSet,
833-
actual.isBoxedCapturing)
834-
.showing(i"adapt universal $actual vs $expected = $result", capt)
829+
if actual.isInstanceOf[SingletonType] then
830+
// capture set is only exposed when widening
831+
adaptUniversal(actual.widen, expected, tree)
832+
else
833+
val localRoot = impliedRoot(tree)
834+
CapturingType(
835+
actual.stripCapturing,
836+
localRoot.termRef.singletonCaptureSet,
837+
actual.isBoxedCapturing)
838+
.showing(i"adapt universal $actual vs $expected = $result", capt)
835839
else actual
836840

837841
private inline val debugSuccesses = false

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
640640
try changePrec(GlobalPrec)(toText(arg) ~ "^" ~ toTextCaptureSet(captureSet))
641641
catch case ex: IllegalCaptureRef => toTextAnnot
642642
if annot.symbol.maybeOwner == defn.RetainsAnnot
643-
&& Feature.ccEnabled && Config.printCaptureSetsAsPrefix && !printDebug
643+
&& Feature.ccEnabled
644+
&& Config.printCaptureSetsAsPrefix && !printDebug
645+
&& Phases.checkCapturesPhase.exists // might be missing on -Ytest-pickler
644646
then toTextRetainsAnnot
645647
else toTextAnnot
646648
case EmptyTree =>

tests/pos/i18699.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import language.experimental.captureChecking
2+
trait Cap:
3+
def use: Int = 42
4+
5+
def test2(cs: List[Cap^]): Unit =
6+
val t0: Cap^{cap[test2]} = cs.head // error
7+
var t1: Cap^{cap[test2]} = cs.head // error

0 commit comments

Comments
 (0)