Skip to content

Commit

Permalink
Do not check for trackable refs in BiTypeMap
Browse files Browse the repository at this point in the history
Fixes scala#22437

The check crashes the compiler when mapping over a capture variable
in an upper bound of the form `CapSet^{C^}` as well as
path captures in function signatures. See the test
`capture-vars-subtyping2.scala` for examples.
  • Loading branch information
bracevac committed Jan 24, 2025
1 parent f7e5df5 commit 81e05a2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6072,15 +6072,16 @@ object Types extends TypeUtils {
/** A restriction of this map to a function on tracked CaptureRefs */
def forward(ref: CaptureRef): CaptureRef =
val result = this(ref)
def ensureTrackable(tp: Type): CaptureRef = tp match
/*def ensureTrackable(tp: Type): CaptureRef = tp match
case tp: CaptureRef =>
if tp.isTrackableRef then tp
else ensureTrackable(tp.underlying)
case tp: TypeAlias =>
ensureTrackable(tp.alias)
case _ =>
assert(false, i"not a trackable captureRef ref: $result, ${result.underlyingIterator.toList}")
ensureTrackable(result)
ensureTrackable(result)*/
result.asInstanceOf[CaptureRef]

/** A restriction of the inverse to a function on tracked CaptureRefs */
def backward(ref: CaptureRef): CaptureRef = inverse(ref) match
Expand Down
44 changes: 44 additions & 0 deletions tests/neg-custom-args/captures/capture-vars-subtyping2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import language.experimental.captureChecking
import caps.*

trait BoundsTest:

trait Bar { val f: () => Unit }
def bar(x: Bar^, y: () ->{x.f} Unit): Unit = ???

val b: Bar^ = ???

def testTransMixed[A^,
B >: CapSet <: A,
C >: CapSet <: CapSet^{B^},
D >: CapSet <: C,
E >: CapSet <: CapSet^{D^},
F >: CapSet <: CapSet^{A^,b},
X >: CapSet <: CapSet^{F^,D^},
Y >: CapSet^{F^} <: CapSet^{F^,A^,b},
Z >: CapSet^{b} <: CapSet^{b,Y^}] =
val e: E = ???
val e2: CapSet^{E^} = e
val ed: D = e
val ed2: CapSet^{D^} = e
val ec: C = e
val ec2: CapSet^{C^} = e
val eb: B = e
val eb2: CapSet^{B^} = e
val ea: A = e
val ea2: CapSet^{A^} = e
val ex: X = e // error
val ex2: CapSet^{X^} = e // error
val f: F = ???
val f2: CapSet^{F^} = f
val y: Y = f
val y2: CapSet^{Y^} = f
val cb: CapSet^{b} = ???
val z: Z = cb
val z2: CapSet^{Z^} = cb

def callTransMixed =
val x, y, z: Bar^ = ???
testTransMixed[CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{x,y,z}, CapSet^{b,x,y,z}]
testTransMixed[CapSet^{x,y,z}, CapSet^{x,y}, CapSet^{x,y}, CapSet^{x}, CapSet^{}, CapSet^{b,x}, CapSet^{b}, CapSet^{b,x}, CapSet^{b}]
testTransMixed[CapSet^{x,y,z}, CapSet^{x,y}, CapSet^{x,y}, CapSet^{x}, CapSet^{}, CapSet^{b,x}, CapSet^{b}, CapSet^{b,x}, CapSet^{b,x,y,z}] // error

0 comments on commit 81e05a2

Please sign in to comment.