Skip to content

Commit

Permalink
Fix error detected in review of #18699 (#18781)
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyxus authored Oct 30, 2023
2 parents 176622c + 041f9ce commit 22aaabb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
16 changes: 10 additions & 6 deletions compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
7 changes: 7 additions & 0 deletions tests/pos/i18699.scala
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 22aaabb

Please sign in to comment.