Skip to content

Commit 9b7ba24

Browse files
committed
Add comment
1 parent eb9bf1a commit 9b7ba24

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,15 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
689689
tp
690690
}
691691

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

0 commit comments

Comments
 (0)