Skip to content

Commit f66011b

Browse files
committed
Fix error detected in review of scala#18699
1 parent 38559d7 commit f66011b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

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

Lines changed: 10 additions & 6 deletions
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

tests/pos/i18699.scala

Lines changed: 7 additions & 0 deletions
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)