Skip to content

Commit

Permalink
Document the fix and add the test
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyxus committed Mar 27, 2024
1 parent f289641 commit 9a3f20f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 10 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ object Annotations {
else
val tp1 = tm(tree.tpe)
foldOver(if tp1 frozen_=:= tree.tpe then x else tp1, tree)
val diff = findDiff(NoType, args)
val diff = if symbol.isRetainsLike then defn.AnyType else findDiff(NoType, args)
// If this is a @retains annotation, the diff check seems to be unreliable.
// We work around this issue by always mapping @retains annotations. See #20035.
//
// FIXME: investigate why the diff check is incorrect for @retains
if tm.isRange(diff) then EmptyAnnotation
else if diff.exists || symbol.isRetainsLike then derivedAnnotation(tm.mapOver(tree))
else if diff.exists then derivedAnnotation(tm.mapOver(tree))
else this

/** Does this annotation refer to a parameter of `tl`? */
Expand All @@ -79,7 +83,10 @@ object Annotations {
case _ => false
case ref: This => ref.tpe match
case TermParamRef(tl1, _) => tl eq tl1
case AnnotatedType(tp1, annot1) => annot1.refersToParamOf(tl)
case AnnotatedType(tp1, annot1) =>
// The type of captured elements in @retains annotation could themself
// refer to term parameters. See #20035.
annot1.refersToParamOf(tl)
case _ => false
case _ => false

Expand Down
11 changes: 11 additions & 0 deletions tests/pos-custom-args/captures/tablediff.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import language.experimental.captureChecking

trait Seq[+A]:
def zipAll[A1 >: A, B](that: Seq[B]^, thisElem: A1, thatElem: B): Seq[(A1, B)]^{this, that}
def map[B](f: A => B): Seq[B]^{this, f}

def zipAllOption[X](left: Seq[X], right: Seq[X]) =
left.map(Option(_)).zipAll(right.map(Option(_)), None, None)

def fillRow[T](headRow: Seq[T], tailRow: Seq[T]) =
val paddedZip = zipAllOption(headRow, tailRow)

0 comments on commit 9a3f20f

Please sign in to comment.