Skip to content

Commit 9a3f20f

Browse files
committed
Document the fix and add the test
1 parent f289641 commit 9a3f20f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

compiler/src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ object Annotations {
6464
else
6565
val tp1 = tm(tree.tpe)
6666
foldOver(if tp1 frozen_=:= tree.tpe then x else tp1, tree)
67-
val diff = findDiff(NoType, args)
67+
val diff = if symbol.isRetainsLike then defn.AnyType else findDiff(NoType, args)
68+
// If this is a @retains annotation, the diff check seems to be unreliable.
69+
// We work around this issue by always mapping @retains annotations. See #20035.
70+
//
71+
// FIXME: investigate why the diff check is incorrect for @retains
6872
if tm.isRange(diff) then EmptyAnnotation
69-
else if diff.exists || symbol.isRetainsLike then derivedAnnotation(tm.mapOver(tree))
73+
else if diff.exists then derivedAnnotation(tm.mapOver(tree))
7074
else this
7175

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import language.experimental.captureChecking
2+
3+
trait Seq[+A]:
4+
def zipAll[A1 >: A, B](that: Seq[B]^, thisElem: A1, thatElem: B): Seq[(A1, B)]^{this, that}
5+
def map[B](f: A => B): Seq[B]^{this, f}
6+
7+
def zipAllOption[X](left: Seq[X], right: Seq[X]) =
8+
left.map(Option(_)).zipAll(right.map(Option(_)), None, None)
9+
10+
def fillRow[T](headRow: Seq[T], tailRow: Seq[T]) =
11+
val paddedZip = zipAllOption(headRow, tailRow)

0 commit comments

Comments
 (0)