File tree 3 files changed +17
-5
lines changed
compiler/src/dotty/tools/dotc
tests/pos-custom-args/captures
3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -49,7 +49,14 @@ sealed abstract class CaptureSet extends Showable:
49
49
/** Is this capture set definitely non-empty? */
50
50
final def isNotEmpty : Boolean = ! elems.isEmpty
51
51
52
- /** Cast to variable. @pre: @isConst */
52
+ /** Cast to Const. @pre: isConst */
53
+ def asConst : Const = this match
54
+ case c : Const => c
55
+ case v : Var =>
56
+ assert(v.isConst)
57
+ Const (v.elems)
58
+
59
+ /** Cast to variable. @pre: !isConst */
53
60
def asVar : Var =
54
61
assert(! isConst)
55
62
asInstanceOf [Var ]
Original file line number Diff line number Diff line change @@ -325,10 +325,14 @@ class CheckCaptures extends Recheck:
325
325
override def recheckRHS (tree : Tree , pt : Type , sym : Symbol )(using Context ): Type =
326
326
val pt1 = pt match
327
327
case CapturingType (core, refs, _)
328
- if sym.owner.isClass
329
- && refs.elems.contains(sym.owner.thisType)
330
- && sym.paramSymss.forall(_.forall(p => p.isType || p.info.captureSet.isAlwaysEmpty)) =>
331
- pt.derivedCapturingType(core, refs ++ sym.owner.asClass.givenSelfType.captureSet)
328
+ if sym.owner.isClass && refs.elems.contains(sym.owner.thisType) =>
329
+ val paramCaptures =
330
+ sym.paramSymss.flatten.foldLeft(CaptureSet .empty) { (cs, p) =>
331
+ val pcs = p.info.captureSet
332
+ (cs ++ (if pcs.isConst then pcs else CaptureSet .universal)).asConst
333
+ }
334
+ val declaredCaptures = sym.owner.asClass.givenSelfType.captureSet
335
+ pt.derivedCapturingType(core, refs ++ (declaredCaptures -- paramCaptures))
332
336
case _ =>
333
337
pt
334
338
recheck(tree, pt1)
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ extension [A](xs: {*} LazyList[A])
21
21
def isEmpty = false
22
22
def head : B = f(xs.head)
23
23
def tail : {this } LazyList [B ] = xs.tail.map(f) // OK
24
+ def concat (other : {f} LazyList [A ]): {this , f} LazyList [A ] = ??? : ({xs, f} LazyList [A ]) // OK
24
25
new Mapped
25
26
26
27
def test (cap1 : Cap , cap2 : Cap ) =
You can’t perform that action at this time.
0 commit comments