Skip to content

Commit 8f86525

Browse files
oderskyKordyjan
authored andcommitted
Add comment
1 parent ae6c7b8 commit 8f86525

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,15 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
686686
tp
687687
}
688688

689+
/** Widen term ref, skipping any `()` parameter of an eventual getter. Used to erase a TermRef.
690+
* Since getters are introduced after erasure, one would think that erasing a TermRef
691+
* could just use `widen`. However, it's possible that the TermRef got read from a class
692+
* file after Getters (i.e. in the backend). In that case, the reference will not get
693+
* an earlier denotation even when time travelling forward to erasure. Hence, we
694+
* need to take the extra precaution of going from nullary method types to their resuls.
695+
* A test case where this is needed is pos/i15649.scala, which fails non-deterministically
696+
* if `underlyingOfTermRef` is replaced by `widen`.
697+
*/
689698
private def underlyingOfTermRef(tp: TermRef)(using Context) = tp.widen match
690699
case tpw @ MethodType(Nil) if tp.symbol.isGetter => tpw.resultType
691700
case tpw => tpw

0 commit comments

Comments
 (0)