Skip to content

Commit 4649fd9

Browse files
committed
Explain both level avoidance schemes in the TypeVar doc comment
1 parent d44cbab commit 4649fd9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4501,9 +4501,21 @@ object Types {
45014501
* @param creatorState The typer state in which the variable was created.
45024502
* @param nestingLevel Symbols with a nestingLevel strictly greater than this
45034503
* will not appear in the instantiation of this type variable.
4504-
* This is enforced in `ConstraintHandling#fixLevels`.
4505-
* The `nestingLevel` of a type variable can be made smaller when
4506-
* fixing the levels for some other type variable instance.
4504+
* This is enforced in `ConstraintHandling`, dependig on the
4505+
* Config flags setting `checkLevelsOnConstraints` and
4506+
* `checkLevelsOnInstantiation`.
4507+
*
4508+
* Under `checkLevelsOnConstraints` we maintain the invariant that
4509+
* the `nonParamBounds` of a type variable never refer to a type with a
4510+
* greater `nestingLevel` (see `legalBound` for the reason why this
4511+
* cannot be delayed until instantiation). Then, on instantiation,
4512+
* we replace any param in the param bound with a level greater than
4513+
* nestingLevel (see `fullLowerBound`).
4514+
*
4515+
* Under `checkLevelsOnInstantiation`, we avoid incorrect levels only
4516+
* when a type variable is instantiated, see `ConstraintHandling$fixLevels`.
4517+
* Under this mode, the `nestingLevel` of a type variable can be made
4518+
* smaller when fixing the levels for some other type variable instance.
45074519
*/
45084520
final class TypeVar private(initOrigin: TypeParamRef, creatorState: TyperState | Null, var nestingLevel: Int) extends CachedProxyType with ValueType {
45094521
private var currentOrigin = initOrigin

0 commit comments

Comments
 (0)