Skip to content

Commit 8883176

Browse files
committed
In a BiMap variable, propagate backwards before trying to add the element
This might not be enough.
1 parent eaccea3 commit 8883176

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package cc
44

55
import core.*
66
import Types.*, Symbols.*, Flags.*, Contexts.*, Decorators.*
7-
import config.Printers.capt
7+
import config.Printers.{capt, captDebug}
88
import Annotations.Annotation
99
import annotation.threadUnsafe
1010
import annotation.constructorOnly
@@ -515,7 +515,7 @@ object CaptureSet:
515515
else if !levelOK(elem) then
516516
CompareResult.LevelError(this, elem)
517517
else
518-
//assert(id != 19 || !elem.isLocalRootCapability, elem.asInstanceOf[TermRef].localRootOwner)
518+
//if id == 34 then assert(!elem.isUniversalRootCapability)
519519
elems += elem
520520
if elem.isUniversalRootCapability then
521521
rootAddedHandler()
@@ -529,6 +529,10 @@ object CaptureSet:
529529

530530
private def levelOK(elem: CaptureRef)(using Context): Boolean =
531531
if elem.isUniversalRootCapability then !noUniversal
532+
else if elem.isInstanceOf[TermParamRef] then
533+
//println(i"can't include $elem in $this")
534+
//new Error().printStackTrace()
535+
!ctx.settings.YccNew.value
532536
else !levelLimit.exists
533537
|| elem.match
534538
case elem: TermRef =>
@@ -537,7 +541,8 @@ object CaptureSet:
537541
levelLimit.isContainedIn(sym.levelOwner)
538542
case elem: ThisType =>
539543
levelLimit.isContainedIn(elem.cls.levelOwner)
540-
case _ => true
544+
case _ =>
545+
true
541546

542547
def addDependent(cs: CaptureSet)(using Context, VarState): CompareResult =
543548
if (cs eq this) || cs.isUniversal || isConst then
@@ -738,9 +743,10 @@ object CaptureSet:
738743
else if accountsFor(elem) then
739744
CompareResult.OK
740745
else
741-
addNewElem(elem).andAlso:
742-
source.tryInclude(bimap.backward(elem), this)
743-
.showing(i"propagating new elem $elem backward from $this to $source", capt)
746+
source.tryInclude(bimap.backward(elem), this)
747+
.showing(i"propagating new elem $elem backward from $this to $source = $result", capt)
748+
.andAlso:
749+
addNewElem(elem)
744750

745751
/** For a BiTypeMap, supertypes of the mapped type also constrain
746752
* the source via the inverse type mapping and vice versa. That is, if
@@ -1037,7 +1043,7 @@ object CaptureSet:
10371043
case _ =>
10381044
empty
10391045
recur(tp)
1040-
.showing(i"capture set of $tp = $result", capt)
1046+
.showing(i"capture set of $tp = $result", captDebug)
10411047

10421048
private val ShownVars: Property.Key[mutable.Set[Var]] = Property.Key()
10431049

tests/neg-custom-args/captures/levels.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
| Required: box (x$0: String) ->? String
1818
|
1919
| Note that reference (cap3 : CC^), defined in method scope
20-
| cannot be included in outer capture set ? which is associated with method test2
20+
| cannot be included in outer capture set ? of value r which is associated with method test2
2121
|
2222
| longer explanation available when compiling with `-explain`

0 commit comments

Comments
 (0)