Skip to content

Commit fef6576

Browse files
authored
Fix conversion of this.fld capture refs under separate compilation (#20238)
2 parents 0bf4911 + 736c6f4 commit fef6576

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,14 @@ class TypeUtils {
135135
case _ =>
136136
val cls = self.underlyingClassRef(refinementOK = false).typeSymbol
137137
cls.isTransparentClass && (!traitOnly || cls.is(Trait))
138+
139+
/** Is this type the ThisType of class `cls?`. Note we can't use `self eq cls.thisType` for this,
140+
* since ThisTypes take TermRef parameters and semantically equal TermRefs could have different
141+
* forms (for instance one could use as a prefix the ThisType of an enclosing static module or package,
142+
* and the other could select it from something further out)
143+
*/
144+
def isThisTypeOf(cls: Symbol)(using Context) = self match
145+
case self: Types.ThisType => self.cls == cls
146+
case _ => false
138147
}
139148
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2991,7 +2991,7 @@ object Types extends TypeUtils {
29912991
*/
29922992
override def isTrackableRef(using Context) =
29932993
((prefix eq NoPrefix)
2994-
|| symbol.is(ParamAccessor) && (prefix eq symbol.owner.thisType)
2994+
|| symbol.is(ParamAccessor) && prefix.isThisTypeOf(symbol.owner)
29952995
|| isRootCapability
29962996
) && !symbol.isOneOf(UnstableValueFlags)
29972997

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Future[T]
2+
object Future:
3+
class Collector[T](fs: (Future[T]^)*)
4+
class MutableCollector[T](val futures: (Future[T]^)*) extends Collector[T](futures*):
5+
def add(future: Future[T]^{futures*}) = ???
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def test =
2+
val collector: Future.MutableCollector[Int] = Future.MutableCollector()
3+
collector.add(???)
4+
5+

0 commit comments

Comments
 (0)