Skip to content

Commit 6e21f42

Browse files
committed
Clarify documentation
1 parent ed51433 commit 6e21f42

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ class CheckRealizable(implicit ctx: Context) {
7070
*/
7171
private def isLateInitialized(sym: Symbol) = sym.is(LateInitialized, butNot = Module)
7272

73-
/** The realizability status of given type `tp` */
73+
/** The realizability status of given type `tp`. We can only select members from realizable types.
74+
* A type is realizable if it has non-null values. However, realizable types can
75+
* have non-realizable subtypes, so we must restrict overriding. */
7476
def realizability(tp: Type): Realizability = tp.dealias match {
7577
case tp: TermRef =>
7678
// Suppose tp is a.b.c.type, where c is declared with type T, then sym is c, tp.info is T and
@@ -85,6 +87,7 @@ class CheckRealizable(implicit ctx: Context) {
8587
def patchRealizability(r: Realizability) =
8688
r.mapError(if (tp.info.isStableRealizable) Realizable else _)
8789
val r =
90+
// Reject fields that are mutable, by-name, and similar.
8891
if (!sym.isStable)
8992
patchRealizability(NotStable)
9093
// 3. If the symbol isn't "lazy" and its prefix is realizable
@@ -93,10 +96,13 @@ class CheckRealizable(implicit ctx: Context) {
9396
// stable if it appears under a realizable prefix.
9497
// XXX: Add object DependsOnPrefix extends Realizability(""), but filter it out here.
9598
patchRealizability(realizability(tp.prefix))
96-
// 4. If the symbol can't be overridden, and
9799
else if (!sym.isEffectivelyFinal)
98100
patchRealizability(new NotFinal(sym))
99101
else
102+
// 4. If the symbol is effectively final, and a lazy or erased val
103+
// and has a realizable type. We require finality because overrides
104+
// of realizable fields might not be realizable.
105+
100106
// Since patchRealizability checks realizability(tp.info) through
101107
// isStableRealizable, using patchRealizability wouldn't make
102108
// a difference, and calling it here again might introduce

0 commit comments

Comments
 (0)