Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error detected in review of #18699 #18781

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading